I have a custom Windows controls that superclass standard ones. I would like my custom controls to notify its parent window of certain events. What’s the best practice for doing so?
-
Send the parent window a window message in the
WM_USERorWM_APPrange. This won’t work since the values could collide if another child control tried the same thing. -
Send the parent window
WM_NOTIFY. This seems like the right thing to do, but since I’m extending a standard Windows control, how can I ensure that the notification code I use won’t collide with one normally sent by the base class (now or in the future)? -
Send the parent window a window message from
RegisterWindowMessage. This should be sufficient to avoid unintentional collisions, but Microsoft recommends using it only for inter-process messages. -
Have the control provide a mechanism for the application to specify what
WM_APPmessage to use for notifications. This seems like the only robust approach, but it also feels a bit like overkill. (Or, instead of specifying a window message, I suppose that the application could pass down a function pointer.)
I’ve seen a similar question, but the sole answer there is tied to MFC and doesn’t really address avoiding collisions.
What do other people usually do? Do they use one of the first three approaches and not worry about it? I’d like my controls to be suitable for broader consumption outside of my application, so I’d also prefer using standard Win32.
Edit: Tried to clarify what I’m looking for.
So I noticed that the notification code ranges defined in CommCtrl.h all look like:
So Microsoft’s common controls at least have defined ranges (and are likely to always be large unsigned values). Therefore if I super- or subclass standard controls and use notification codes incrementing from 0, I think that I should be safe against current and future versions of Windows.
(If I were deriving from third-party controls, then those third-party controls would need to define their own reserved ranges. Otherwise all bets would be off.)