Using 256 color bitmaps in toolbar

This tip was contributed by Kevin Bentley. He has tried this on a 256 color display as well.

I recently needed to have 256 color toolbars in my app. If you create 256 color bitmaps in devstudio, and try to use them with CToolbar it won't work.

The problem is in the LoadBitmap() member or CToolbar. Appwizard will create the following line in your CMainFrame class:


m_wndToolBar.LoadBitmap(IDR_MAINFRAME) 

Here is the fix, just replace the load bitmap call with a call to the control itself:


m_wndToolBar.GetToolBarCtrl().AddBitmap(iNumButtons,IDR_MAINFRAME);

It really is that easy, I found this solution after writing my own toolbar class that used the tool control directly, and 256 color bitmaps worked fine. I couldn't believe it, but it works!



Comments

  • Change bitmaps in toolbar in time of running

    Posted by Legacy on 11/04/2003 12:00am

    Originally posted by: Elina Lazebnik

    I need change bitmaps for my toolbar (in FormView).
    I can insert more from one bitmap to CToolBarCtrl by using CToolBarCtrl::AddBitmap() func. But I don't now how to change it in time of running.

    Thanks

    Reply
  • How to put a .ico file on the toolbar button

    Posted by Legacy on 09/11/2003 12:00am

    Originally posted by: Gaurav Gumber

    Hi,
    The article is superb. But the problem with me is that I have a number of ".ico" files, each containing an icon. Kindly tell me how to put that on a toolbar button.

    Regards
    Gaurav

    Reply
  • finish method

    Posted by Legacy on 08/12/2002 12:00am

    Originally posted by: storein

    It can load 256 Colors bitmap ,and you can dispose bitmap backgroud ,RGB (192,192,192 ) is Color Mask .and bitmap backgroud is RGB (192,192,192)

    CImageList *pImgList = m_wndToolBar.GetToolBarCtrl().GetImageList();
    pImgList->DeleteImageList();
    pImgList->Create(48, 48, ILC_COLOR8 | ILC_MASK, 0, 10);

    CBitmap ToolBarBm;
    ToolBarBm.LoadBitmap (IDB_ToolBar);
    pImgList->Add (&ToolBarBm,RGB(192,192,192));


    CBitmap DisToolBarBm;
    DisToolBarBm.LoadBitmap (IDB_DisaToolBar);
    CImageList* pDisaImgList;
    pDisaImgList=new CImageList ;
    pDisaImgList->Create(48, 48, ILC_COLOR8 | ILC_MASK, 0, 10);
    pDisaImgList->Add (&DisToolBarBm,RGB(192,192,192));

    m_wndToolBar.GetToolBarCtrl().SetImageList(pImgList);
    m_wndToolBar.GetToolBarCtrl().SetDisabledImageList (pDisaImgList);

    Reply
  • How to Highlight the button on toolbar ?

    Posted by Legacy on 03/25/2002 12:00am

    Originally posted by: anuradha

    How to Highlight the button on toolbar when cursor place on that button?
    
    it is just like facility provided in win XP.

    i wants the codes for that? will u please help me?

    Reply
  • 256 color toolbar with disabled buttons.

    Posted by Legacy on 01/21/2002 12:00am

    Originally posted by: Rai, Fumihiko

    I followed the steps but the disabled buttons were mixed up.
    
    Therefore, I use the following codes to make it work.


    CImageList *pImgList = m_wndToolBar.GetToolBarCtrl().GetImageList();
    pImgList->DeleteImageList();
    pImgList->Create(16, 16, ILC_COLOR8 | ILC_MASK, 0, nBtnCnt);
    m_wndToolBar.GetToolBarCtrl().SetImageList(pImgList);
    m_wndToolBar.GetToolBarCtrl().AddBitmap(nBtnCnt, IDR_MAINFRAME_256);

    Also, the palette of your bitmap should be 256 colors.

    Thanks, And hope it will help !!

    Reply
  • As usual... it doesnt work

    Posted by Legacy on 11/01/2001 12:00am

    Originally posted by: John

    When i try this example, the program either fails to run or crashes.

    Reply
  • Bitmaps go black when changing color depth

    Posted by Legacy on 09/06/2001 12:00am

    Originally posted by: Dan

    If you change from 32 bit -> 16 bit color (actually between any two color depths), the bitmaps go black. Does anyone know of a solution for this or is it a bug in the toolbar control?

    Reply
  • How can i change the background color of ToolBar

    Posted by Legacy on 05/30/2001 12:00am

    Originally posted by: fhlove

    I just want to change the background color of ToolBar.
    How can i do that??

    Reply
  • Error in ~CToolBar()

    Posted by Legacy on 11/22/2000 12:00am

    Originally posted by: serrand

    Bad argument in	AfxDeleteObject((HGDIOBJ*)&m_hbmImageWell);
    

    Reply
  • Works Great!!

    Posted by Legacy on 02/16/2000 12:00am

    Originally posted by: Raghav Gupta

    Works great! Thanks a lot!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • When individual departments procure cloud service for their own use, they usually don't consider the hazardous organization-wide implications. Read this paper to learn best practices for setting up an internal, IT-based cloud brokerage function that service the entire organization. Find out how this approach enables you to retain top-down visibility and control of network security and manage the impact of cloud traffic on your WAN.

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there is simply not enough quality talent to go around. Tiempo Development is a nearshore software development company. Our headquarters are in AZ, but we are a pioneer and leader in outsourcing to Mexico, based on our three software development centers there. We have a proven process and we are experts at providing our customers with powerful solutions. We transform ideas into reality.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date