In the parent, you can handle the drawing for several windows
Otherwise, you would have to subclass each window
[WinAPI] Curiosity question about owner draw and custom draw
I am curious about why NM_CUSTOMDRAW and WM_DRAWITEM are sent to the parent. Why aren't these two messages/notifications instead sent to the controls themselves? I don't get why we are supposed to do the drawing in the parent. For example, receiving NM_CUSTOMDRAW in a subclassed Listview procedure would make sense to me to easily change some item text colors/fonts etc. without having to draw the control fully the control yourself. Why would it have to happen within the parent?
I would appreciate it if somebody could clarify this for me.
3 answers
Sort by: Most helpful
-
Castorix31 86,971 Reputation points
2021-11-03T12:04:26.827+00:00 -
Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
2021-11-04T08:12:17.22+00:00 The document hasn‘t claimed the reason why the destination of the message must be the HWND of the parent of the control. But the fact is the destination of the message must be the HWND of the parent of the control.
-
RLWA32 46,941 Reputation points
2021-11-04T09:11:39.41+00:00 The concept of handling a control's notification messages in the control instead of its parent window is implemented in Microsoft's MFC framework. MFC refers to this as message reflection. ( Message Reflection for Windows Controls ) An example would be to derive your own class from the MFC class that encapsulates the Windows control. In the derived class you would include code to handle the NM_CUSTOMDRAW notification that is reflected back to it instead of handling the notification in the parent window.