[WinAPI] Curiosity question about owner draw and custom draw

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

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.
2,422 questions
0 comments No comments
{count} votes

3 answers

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

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


  2. Xiaopo Yang - MSFT 11,336 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.

    0 comments No comments

  3. RLWA32 40,286 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.

    0 comments No comments