CMFCToolbar : Unable to display icon on Toolbar button dynamically

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,

We want to load an icon and want to display that icon in a toolbar button. But we are unable display the icon on a dynamically added toolbar button. This was working fine with the old CToolbar class. Please have a look at the given sample code. We set PNG image on Toolbar. Might be it failed in updating existing png image with HBITMAP.



//hIcon is handler of new icon image

 if(hIcon)
{
      CMFCToolBarImages *pImgList;
     pImgList = mytoolbar.GetImages();
      int Index = mytoolbar.CommandToIndex(nID);
      CMFCToolBarButton *pButtonInfo = mytoolbar.GetButton(nIndex);

      //UpdateImg is failed in updating existing image with icon
      pImgList->UpdateImage(pButtonInfo->GetImage(),(HBITMAP)hIcon);

      mytoolbar.SetUserImages(pImgList);
      mytoolbar.Invalidate(TRUE);
      ::DestroyIcon( hIcon );
}
 

 

View the full article
 
Back
Top