Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Subclassing again ...

Here is a multiple choice question. If you are subclassing a form or control,
when is the best time to stop subclassing it:

1) form_unload
2) form_terminate/usercontrol_terminate
3) WM_NCDESTROY
4) WM_DESTROY
5) Other

Place you questionaire at the front on your way out and thank you for attending
:) Although the examiner may have troubles marking as he doesn't know the
answer

Mike
[443 byte] By [Mike] at [2007-11-10 0:20:44]
# 1 Re: Subclassing again ...
Mike wrote in message <38da0f11$1@news.dev-archive.com>...
>
>Here is a multiple choice question. If you are subclassing a form or
control,
>when is the best time to stop subclassing it:
>
>1) form_unload
>2) form_terminate/usercontrol_terminate
>3) WM_NCDESTROY
>4) WM_DESTROY
>5) Other
>
>Place you questionaire at the front on your way out and thank you for
attending
>:) Although the examiner may have troubles marking as he doesn't know the
>answer
>
>Mike

If you're writing a subclassing component, I'd suggest that you have that
component stop subclassing that handle if it ever receives a WM_DESTROY or
WM_NCDESTROY message; it saves a lot of heartache down the road.

If you're not using a component, but just threw the subclassing code
directly into your program, you could do it on Form_Terminate or
UserControl_Terminate, which would be more efficient (by some most likely
negligible amount) than checking for the WM_[NC]DESTROY messages (you won't
have to check for them everytime you get a message in your winproc)...but
it's a tradeoff. In my opinion, it's better to be safer and check for those
messages.

--
Colin McGuigan
Colin McGuigan at 2007-11-11 20:02:55 >
# 2 Re: Subclassing again ...
Mike wrote in message <38da0f11$1@news.dev-archive.com>...
>
>Here is a multiple choice question. If you are subclassing a form or
control,
>when is the best time to stop subclassing it:
>
>1) form_unload
>2) form_terminate/usercontrol_terminate
>3) WM_NCDESTROY
>4) WM_DESTROY
>5) Other
>
>Place you questionaire at the front on your way out and thank you for
attending
>:) Although the examiner may have troubles marking as he doesn't know the
>answer
>
>Mike

If you're writing a subclassing component, I'd suggest that you have that
component stop subclassing that handle if it ever receives a WM_DESTROY or
WM_NCDESTROY message; it saves a lot of heartache down the road.

If you're not using a component, but just threw the subclassing code
directly into your program, you could do it on Form_Terminate or
UserControl_Terminate, which would be more efficient (by some most likely
negligible amount) than checking for the WM_[NC]DESTROY messages (you won't
have to check for them everytime you get a message in your winproc)...but
it's a tradeoff. In my opinion, it's better to be safer and check for those
messages.

--
Colin McGuigan
Colin McGuigan at 2007-11-11 20:04:01 >
# 3 Re: Subclassing again ...
WM_NCDESTROY is the last message sent to a window. Therefore, subclassing
components and C++ window classes usually clean up with this message. (See
the subclass control on our site for an example of this.)

However, if your subclassing code is part of a custom application, you might
consider if your particular application could stop subclassing earlier as
doing so will stop the overhead involved.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Mike" <m_culley@one.net.au> wrote in message
news:38da0f11$1@news.dev-archive.com...
>
> Here is a multiple choice question. If you are subclassing a form or
control,
> when is the best time to stop subclassing it:
>
> 1) form_unload
> 2) form_terminate/usercontrol_terminate
> 3) WM_NCDESTROY
> 4) WM_DESTROY
> 5) Other
>
> Place you questionaire at the front on your way out and thank you for
attending
> :) Although the examiner may have troubles marking as he doesn't know the
> answer
>
> Mike
Jonathan Wood at 2007-11-11 20:04:59 >
# 4 Re: Subclassing again ...
WM_NCDESTROY is the last message sent to a window. Therefore, subclassing
components and C++ window classes usually clean up with this message. (See
the subclass control on our site for an example of this.)

However, if your subclassing code is part of a custom application, you might
consider if your particular application could stop subclassing earlier as
doing so will stop the overhead involved.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Mike" <m_culley@one.net.au> wrote in message
news:38da0f11$1@news.dev-archive.com...
>
> Here is a multiple choice question. If you are subclassing a form or
control,
> when is the best time to stop subclassing it:
>
> 1) form_unload
> 2) form_terminate/usercontrol_terminate
> 3) WM_NCDESTROY
> 4) WM_DESTROY
> 5) Other
>
> Place you questionaire at the front on your way out and thank you for
attending
> :) Although the examiner may have troubles marking as he doesn't know the
> answer
>
> Mike
Jonathan Wood at 2007-11-11 20:06:04 >
# 5 Re: Subclassing again ...
Mike,

Both Colin and Jonathan answered this question well. I just wanted to
expand upon the logic behind choosing like they did.

>Here is a multiple choice question. If you are subclassing a form or control,
>when is the best time to stop subclassing it:
>
>1) form_unload

Hmm. But what would happen if the programmer used Load control(Index)
and Unload control(Index) or Controls.Add and Controls.Remove to
create and destroy the windows? Your subclassing code would fail. So
that's out.

>2a) form_terminate

That's way too late to release your code. The form and all its
children have already been destroyed. In fact, you can't even
correspond every unload event to a terminate, since you can load and
unload forms without terminating your references.

>2b)usercontrol_terminate

That would only be useful for cleaning up code related only to the
subclasser, and not to the window being subclassed.

>3) WM_NCDESTROY

Good choice. It's the last message going to the window.

>4) WM_DESTROY

Also a good choice. I generally use this, because I use Set/GetProp on
the windows to subclass them. I want to RemoveProp in this message.

Ciao, Craig
Craig Clearman at 2007-11-11 20:07:08 >
# 6 Re: Subclassing again ...
Mike,

Both Colin and Jonathan answered this question well. I just wanted to
expand upon the logic behind choosing like they did.

>Here is a multiple choice question. If you are subclassing a form or control,
>when is the best time to stop subclassing it:
>
>1) form_unload

Hmm. But what would happen if the programmer used Load control(Index)
and Unload control(Index) or Controls.Add and Controls.Remove to
create and destroy the windows? Your subclassing code would fail. So
that's out.

>2a) form_terminate

That's way too late to release your code. The form and all its
children have already been destroyed. In fact, you can't even
correspond every unload event to a terminate, since you can load and
unload forms without terminating your references.

>2b)usercontrol_terminate

That would only be useful for cleaning up code related only to the
subclasser, and not to the window being subclassed.

>3) WM_NCDESTROY

Good choice. It's the last message going to the window.

>4) WM_DESTROY

Also a good choice. I generally use this, because I use Set/GetProp on
the windows to subclass them. I want to RemoveProp in this message.

Ciao, Craig
Craig Clearman at 2007-11-11 20:08:01 >
# 7 Re: Subclassing again ...
Thanks all. It seams to be a big thumbs up for WM_DESTROY or WM_NCDESTROY.

Mike
Mike at 2007-11-11 20:09:05 >
# 8 Re: Subclassing again ...
Thanks all. It seams to be a big thumbs up for WM_DESTROY or WM_NCDESTROY.

Mike
Mike at 2007-11-11 20:10:03 >
# 9 Re: Subclassing again ...
Craig, Colin, Jonathon

If you have the time, I have another question. This is how I stop the subclassing:

Function SubWndProc(hWnd etc...)
Call my object if it wants the message
If msg=WM_DESTROY then StopSubclassing
CallWindowProc
end Function

What do you think regarding the order of events here. ie should I StopSubclassing
before or after CallWindowProc.

Thanks again

Mike

Craig Clearman <chclear@nospam.please> wrote:
>Mike,
>
>Both Colin and Jonathan answered this question well. I just wanted to
>expand upon the logic behind choosing like they did.
>
>>Here is a multiple choice question. If you are subclassing a form or control,
>>when is the best time to stop subclassing it:
>>
>>1) form_unload
>
>Hmm. But what would happen if the programmer used Load control(Index)
>and Unload control(Index) or Controls.Add and Controls.Remove to
>create and destroy the windows? Your subclassing code would fail. So
>that's out.
>
>>2a) form_terminate
>
>That's way too late to release your code. The form and all its
>children have already been destroyed. In fact, you can't even
>correspond every unload event to a terminate, since you can load and
>unload forms without terminating your references.
>
>>2b)usercontrol_terminate
>
>That would only be useful for cleaning up code related only to the
>subclasser, and not to the window being subclassed.
>
>>3) WM_NCDESTROY
>
>Good choice. It's the last message going to the window.
>
>>4) WM_DESTROY
>
>Also a good choice. I generally use this, because I use Set/GetProp on
>the windows to subclass them. I want to RemoveProp in this message.
>
>Ciao, Craig
>
Mike at 2007-11-11 20:11:05 >
# 10 Re: Subclassing again ...
Craig, Colin, Jonathon

If you have the time, I have another question. This is how I stop the subclassing:

Function SubWndProc(hWnd etc...)
Call my object if it wants the message
If msg=WM_DESTROY then StopSubclassing
CallWindowProc
end Function

What do you think regarding the order of events here. ie should I StopSubclassing
before or after CallWindowProc.

Thanks again

Mike

Craig Clearman <chclear@nospam.please> wrote:
>Mike,
>
>Both Colin and Jonathan answered this question well. I just wanted to
>expand upon the logic behind choosing like they did.
>
>>Here is a multiple choice question. If you are subclassing a form or control,
>>when is the best time to stop subclassing it:
>>
>>1) form_unload
>
>Hmm. But what would happen if the programmer used Load control(Index)
>and Unload control(Index) or Controls.Add and Controls.Remove to
>create and destroy the windows? Your subclassing code would fail. So
>that's out.
>
>>2a) form_terminate
>
>That's way too late to release your code. The form and all its
>children have already been destroyed. In fact, you can't even
>correspond every unload event to a terminate, since you can load and
>unload forms without terminating your references.
>
>>2b)usercontrol_terminate
>
>That would only be useful for cleaning up code related only to the
>subclasser, and not to the window being subclassed.
>
>>3) WM_NCDESTROY
>
>Good choice. It's the last message going to the window.
>
>>4) WM_DESTROY
>
>Also a good choice. I generally use this, because I use Set/GetProp on
>the windows to subclass them. I want to RemoveProp in this message.
>
>Ciao, Craig
>
Mike at 2007-11-11 20:12:12 >