The common control library sometimes sends an NMCUSTOMDRAW message for the NM_CUSTOMDRAW notification.

I just fixed a bug in our UI that was caused by a misunderstanding of the API contract for the NM_CUSTOMDRAW handler for some of the common controls.

On of October 3rd, 2008 The common control documentation for the NM_CUSTOMDRAW message says:

lpNMCustomDraw
A pointer to a custom draw-related structure that contains information about the drawing operation. The following list specifies the controls and their associated structures. List view
NMLVCUSTOMDRAW ToolTip
NMTTCUSTOMDRAW Tree view
NMTVCUSTOMDRAW Toolbar
NMTBCUSTOMDRAW All other supported controls
NMCUSTOMDRAW

While this is correct in general it is NOT true for the CDDS_PREPAINT draw stage.  It turns out that some of the common controls only provide an NMCUSTOMDRAW structure when the drawing logic is in the CDDS_PREPAINT stage. 

If you look VERY carefully at MSDN, you can find this page which mentions that the first NM_CUSTOMDRAW notification receives an NMCUSTOMDRAW structure and not an NMLVCUSTOMDRAW handler but that’s the only page I was able to find to indicate this.

 

I’ve notified the relevant documentation folks about this and hopefully the documents will be updated in the future.  You can consider this blog post as a pre-update to the SDK documentation.