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

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds