[WinAPI] Curiosity question about owner draw and custom draw

asked 2021-11-03T11:30:22.243+00:00
NorthernSun 81 Reputation points

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.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
1,888 questions
No comments
{count} votes

3 answers

Sort by: Most helpful
  1. answered 2021-11-03T12:04:26.827+00:00
    Castorix31 65,246 Reputation points

    In the parent, you can handle the drawing for several windows
    Otherwise, you would have to subclass each window

  2. answered 2021-11-04T08:12:17.22+00:00
    Xiaopo Yang - MSFT 5,821 Reputation points Microsoft Employee

    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.

    No comments

  3. answered 2021-11-04T09:11:39.41+00:00
    RLWA32 28,531 Reputation points

    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.

    No comments