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;
compatDC.CreateCompatibleDC(dc);
TBBUTTON button;
for (int i=0;i < ButtonCount();++i)
{
   Toolbar().GetButton(i,&button);
   if(button.fsStyle&BTNS_SEP)
   {
      CRect sepRc;
      Toolbar().GetRect(button.idCommand,&sepRc);
      extra::GDIBitmapObjectSelect leftBmpSel(compatDC,m_sep.Bmp());
      dc.BitBlt(sepRc.left,sepRc.top,m_sep.Size().cx,
         m_sep.Size().cy,compatDC,0,0,SRCCOPY);
   }
}
return CDRF_SKIPDEFAULT;

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.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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