Custom Draw Toolbar

After WPF, spending time with NM_CUSTOMDRAW seemed like running somewhere, when one could catch a bus.  Someday, we may even do it’s like for pleasure.

My problem: I couldn’t get the separators to draw on my owner draw toolbar.  Apparently, the NM_CUSTOMDRAW doesn’t send a CDDS_ITEMPOSTPAINT for separators.  So, the way to do it is draw your separator over the top once drawing is complete.  Process the CDDS_POSTPAINT with something like this:

CDCHandle dc(__HDR.hdc);
CDC compatDC;
TBBUTTON button;
for (int i=0;i < ButtonCount();++i)
      CRect sepRc;
      extra::GDIBitmapObjectSelect leftBmpSel(compatDC,m_sep.Bmp());

Don’t forget to return CDRF_NOTIFYPOSTPAINT in response to a CDDS_PREPAINT. (And NOTIFYITEMDRAW if you want to draw the items.)  Also, each separator must be added with a unique command Id otherwise GetRect will always just get the first.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s