Re: Venting on .NET

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You have to move the event handlers because, obviously, the events from the control now
have to be interpreted in the context of the new application. This is not a major
complication. Any event handler unique to the control should be embedded in the control.
A classic example is OnCtlColor for a child control being any place other than in the
child control.

Otherwise, you are arguing that it is hard to reuse a CEdit because an OnChanged handler
has to be added to each app. Handlers are unique to the application. Similarly, there
are only two kinds of initialization: the initialization of the control which are
intrinsic to the control, which of course belong in the control subclass and are
automatically invoked, typically, a place to do this is in PreSubclassWindow, so the
initialization is carried with the subclass. The other form of initialization is the
intiialization of the application-senstitive aspects of the control, for example, the
range of a spin control, the contents of a CEdit, etc. and there is no way this
initialization could be carried across with the control, because it is entirely dependent
on the needs of the application. So initializing a listbox would make no sense for
application-specific initialization.

If you wanted to initialize a listbox to a set of baud rates, then the control should be
subclassed and the initialization done as part of the control. Bad programming style
would always interfere with proper reuse.

The real problem is moving stringtable resources. This would be greatly simplified if it
were possible to organize .rc files but #includes do not work right. The resource
compiler is one of the major problems, but it has remained unchanged for well over a
decade.

So we could argue that features like the ability to include multiple .res files, use
#includes properly in the resource editor, and so on, are what should be supported.
Microsoft's excuse is that we should use ActiveX, but it is so gratuitously complex that
the cost of hand-editing a .rc file is vastly lower than the cost of learning or using
ActiveX.
joe

On Mon, 09 Jan 2006 15:28:48 GMT, "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
>news:auq4s15u5hcgkld9ipufj7r10e28fr1t4l@xxxxxxxxxx
>> Why would there be custom initialization code in OnInitDialog? Could it
>> be that the
>> control was badly designed?
>>
>> A control is defined by its interface. Therefore, the only semantics on
>> OnClicked would
>> be for the container of the control. Anything unique to the control would
>> be built into
>> the control. Perhaps you are used to seeing badly-designed controls.
>>
>
>No, reusing a control involves more than just putting the control into a new
>project. You also have to move the initialization and event handlers also,
>if you want to reuse those. MFC makes it easy to move the control itself
>(although not any resources it depends on). It doesn't make it easy to move
>the initialization and event handlers.
>
>
>> As far as I could tell from my work with C#, and in talking to others that
>> use it, there
>> *is* no .rc file, so discussing it is pointless.
>
>If there is no .rc file involved, then that is a major advantage in the code
>reuse of C#.
>
>-- David
>
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: CSplitterWnd paint problems
    ... the pane contents. ... Now the control draws its child elements, ... the mainframe for the pane's initialization. ... the parent window that just houses them. ...
    (microsoft.public.vc.mfc)
  • Re: When is an added TSP initialized?
    ... > my TSP via TAPI32 browser lineAddProviderthe whole initialization chain ... > control panel only attaches my dll to the telephony process but does not add ... How can I add my provider when my TSP is added via the control ... These TSPI_ functions are required by control, ...
    (microsoft.public.win32.programmer.tapi)
  • Re: WM_CREATE not received in dialogs controls
    ... Use PreSubclassWindow for initialization of controls. ... The WM_PAINT must *always* be robust enough to not crash! ... At first I done it programatically creating the control and placing the ... But I want to create the control from a resource ID, not programatically, to ...
    (microsoft.public.vc.mfc)
  • Re: Dynamically Created Gridview - Paging events are not fired
    ... I'm having a similar problem but in my case the grid does not disappear (as I do all the initialization on Page_Init()) but it just reloads the page and nothing changes. ... The GridView is being initialized during the Init event of the UserControl and the PageIndexChanged event is being hooked to a function in that control's code. ... Then I create the control on my aspx page by using the Page.LoadControlmethod and assign the result to the Controls collection of a placeholder that I placed on that page. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: DDX problem: Is DDX even worth the trouble?
    ... If the data weren't valid I'd set the focus to the control ... NOT call the base class OnInitDialog first: ... // perhaps other initialization here ... I often insert processing that needs to happen before the DDX calls ...
    (microsoft.public.vc.mfc)