News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Subclassing: just the one window, right?

Started by NoCforMe, February 20, 2017, 11:58:02 AM

Previous topic - Next topic

NoCforMe

Just a simple question*: when one subclasses a window (say, a control), the subclassing is only for that one instance, not for the entire class of controls, right? That's my understanding, but after reading the MSDN docs on the subject, some doubt crept into my mind. What I mean is, it doesn't mean that every window of that class will be subclassed afterwards, right?

Another related question is this: it's OK to use the same window procedure for several subclassed controls, isn't it? Even if they're not the same type? Oops, I might have answered my own question right here: I subclassed several different types of control to the same window proc. Probably not a good thing, right? Back to the workshop ...

Reason I ask is I had a program that ran fine until I tried subclassing some controls (several controls, edit, button, etc.), all children of another window; not only did my program then crash, but it also crashed Dr. Watson! Never saw that happen before ...

* probably no such thing as a simple question here, eh?

Thanks in advance for any helpful answers!
Assembly language programming should be fun. That's why I do it.

NoCforMe

nevermind ... that was the problem. You can't subclass a bunch of different type of controls to the same window proc and expect Windows not to get confused.
Assembly language programming should be fun. That's why I do it.

hutch--

You will find that the code for a subclass is so small that multiple subclass procedures don't add up to much. It is viable to use the same subclass procedure for multiple controls if they are indentical but mixed control type are hard to handle and near impossible to edit afterwards.

NoCforMe

Quote from: hutch-- on February 20, 2017, 12:35:12 PM
You will find that the code for a subclass is so small that multiple subclass procedures don't add up to much.

Yes, exactly. Ackshooly, I figured out that I could use one common window proc for them all, and route the various types of controls to the appropriate original window proc (using CallWindowProc() ),but like you say, it's so small that it's 6 of one and half a dozen of the other.
Assembly language programming should be fun. That's why I do it.