title: Custom drawing of icons in CToolbar customization dialog
body: <p>I am trying to customize <code>CToolbar</code> class(<strong>MFC library</strong>) for my needs (enabling support of 32 bit icons with anti-aliasing).<br>
  For that purpose I am using <strong>custom draw method</strong> provided by CToolbar, where I paint my own Icons.<br>
  Icons are rendered fine and <strong>everything is OK, until user opens customization dialog</strong> - where he can pick needed icons and arrange them as he likes (this is standard customization dialog for MFC toolbar).</p>
  
  <p>Problem: in customization dialog the same image is drawn for all buttons.</p>
  
  <p>Here are code snippets from my project:</p>
  
  <pre><code>void CCustomToolBar::OnCustomDraw (NMHDR *pNMHDR, LRESULT *pResult)
  {
    LPNMTBCUSTOMDRAW lpNMCustomDraw = (LPNMTBCUSTOMDRAW)pNMHDR;
  
    switch (lpNMCustomDraw-&gt;nmcd.dwDrawStage)
    {
      // the Painting loop starts
    case CDDS_PREPAINT:
      {
        *pResult = CDRF_NOTIFYITEMDRAW; // register for items drawing events
        //if (m_bAdjusting)SetWindowLong (lpNMCustomDraw-&gt;nmcd.hdr.hwndFrom, DWL_MSGRESULT, CDRF_NOTIFYITEMDRAW);
      }
      break;
      // Item (button) is going to be painted, do own drawing
    case CDDS_ITEMPREPAINT:
      {
        CDC DrawDC;
        DrawDC.Attach(lpNMCustomDraw-&gt;nmcd.hdc);
  
        CToolBarCtrl&amp; ControlBar = GetToolBarCtrl();
  
        CRect btnRect = lpNMCustomDraw-&gt;nmcd.rc; 
        int State = lpNMCustomDraw-&gt;nmcd.uItemState; // CDIS_GRAYED | CDIS_CHECKED | CDIS_DEFAULT | CDIS_DISABLED | CDIS_FOCUS | CDIS_GRAYED | CDIS_HOT | CDIS_SELECTED
  
        hugeSizedImages_.SetTransparentColor(afxGlobalData.clrBtnFace);
  
        DrawDC.DrawFrameControl(&amp;btnRect, DFC_BUTTON , DFCS_BUTTONPUSH );
  
        DWORD dwItem = (DWORD)lpNMCustomDraw-&gt;nmcd.dwItemSpec;
        int btnIndex = 0;
        GUARD_IF(m_BitmapIndex.find(dwItem) != m_BitmapIndex.end())
        {
          btnIndex = m_BitmapIndex[dwItem];
        }
  
        CAfxDrawState ds;
        hugeSizedImages_.PrepareDrawImage(ds, CSize(48,48));
        hugeSizedImages_.Draw(&amp;DrawDC, btnRect.left, btnRect.top, btnIndex);
        hugeSizedImages_.EndDrawImage(ds);
        DrawDC.Detach();
  
        *pResult = CDRF_SKIPDEFAULT;  // No further drawing
        //if (m_bAdjusting) SetWindowLong (lpNMCustomDraw-&gt;nmcd.hdr.hwndFrom, DWL_MSGRESULT, CDRF_SKIPDEFAULT);
      }
      break;
    default:
      *pResult = 0;
    }
  </code></pre>
  
  <p><strong>Message map:</strong></p>
  
  <pre><code> BEGIN_MESSAGE_MAP ( CCustomToolBar, CToolBarWithHideableButtons )
        //{{AFX_MSG_MAP ( CCustomToolBar )
        ON_WM_CONTEXTMENU ()
        ON_COMMAND        ( CM_TOOLBAR_CUSTOMIZE, OnPopupCustomize )
        ON_NOTIFY_REFLECT ( TBN_QUERYDELETE,      OnQueryDelete )
        ON_NOTIFY_REFLECT ( TBN_QUERYINSERT,      OnQueryInsert )
        ON_NOTIFY_REFLECT ( TBN_GETBUTTONINFO,    OnGetButtonInfo )
        ON_NOTIFY_REFLECT ( TBN_BEGINADJUST,      OnBeginAdjust )
        ON_NOTIFY_REFLECT ( TBN_ENDADJUST,        OnEndAdjust )
        ON_NOTIFY_REFLECT ( TBN_RESET,            OnReset )
        ON_NOTIFY_REFLECT ( TBN_TOOLBARCHANGE,    OnToolBarChange )
        ON_NOTIFY_REFLECT ( TBN_INITCUSTOMIZE,    OnInitCustomize ) //only with IE 5.0 and 
        ON_NOTIFY_REFLECT ( NM_CUSTOMDRAW,        OnCustomDraw)
        ON_WM_CREATE ()
        //}}AFX_MSG_MAP
      END_MESSAGE_MAP ()
  </code></pre>
  
  <p>I have done debugging a lot, and managed to get that when customizing window appear - information that is sent to CustomDraw related to the item(button) to be drawn is missed, always zero index is sent.</p>
  
  <p>If I comment out *pResult = CDRF_SKIPDEFAULT; when system is able to draw icons in customization dialog according to their indexes(but with 4 bit depth only) - hence I think that I have ommited smth important in the custom draw.</p>
  
  <p>I have read all possible articles in MSDN and other sources related to the custom draw, but no problem of icons in customization window is mentioned there.</p>
  
  <p>So if anybody has faced with similar problem, could you please give me a hint?
  thanks in advance!</p>