Toolbar with 16M colour images



Download Source Code and Example  66KB

I tried Kevin Bentley's trick to use 256 colours but it didn't work.
I needed to have more than 256 colours - so I tried to find some alternative way - fortunately I found it.

Here's how can you use hi-color bitmaps on your toolbars:

At first, create your toolbar in Developer Studio - no matter what do you draw on buttons. Make a hi-color bitmap with a bitmap-editor (for example Paint Shop Pro). This new bitmap must be the same size as Toolbar.bmp in your project's \res folder. Then import the resource into your application as bitmap, name it IDB_TOOLBARHI. Here's what you must to do:

  • Make a CBitmap type global variable m_bmToolbarHi in your CMainFrame class
  • Include these lines in the function CMainFrame::OnCreate() after initializing the toolbar:
    if (!m_wndToolBar.Create(this) ||
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
        TRACE0("Failed to create toolbar\n");
        return -1; // fail to create
    }

// ===========================================================
    m_bmToolbarHi.LoadBitmap( IDB_TOOLBARHI );
    m_wndToolBar.SetBitmap( (HBITMAP)m_bmToolbarHi );
// ===========================================================
  • Include this line in the destructor of CMainFrame:
CMainFrame::~CMainFrame()
{
// ===========================================================
    m_bmToolbarHi.DeleteObject();
// ===========================================================
}

That's all.

Last updated: 16 July 1998



Comments

  • Great Code - Works on the Dialog Based Application !

    Posted by Legacy on 10/08/2003 12:00am

    Originally posted by: Milan Ristic

    This is the most powerfull code for the Toolbar I ever seen, the great thing is that works on Dialog based applications. This is The full code, 24-bit Toolbar + invisible background :
    
    

    cToolBar.Create(this);
    cToolBar.LoadToolBar(IDR_TOOLBAR);

    m_bmToolbarHi.LoadBitmap( IDB_BTOOLBAR );
    cToolBar.SetBitmap( (HBITMAP)m_bmToolbarHi );

    m_toolList.Create(30, 18, ILC_COLOR24|ILC_MASK, 18, 1);

    // Load the list from resource, and select the transperency color

    CBitmap bmpFaces;
    bmpFaces.LoadBitmap(IDB_BTOOLBAR);
    m_toolList.Add(&bmpFaces, RGB(192, 192, 192));

    // Finally, set the new image list to the toolbar
    cToolBar.GetToolBarCtrl().SetImageList(&m_toolList);


    // cToolBar.SetBorders(50, 20, 150, 120); // Polozaj gde da se nalazi Toolbar, moze da bude korisno
    cToolBar.ShowWindow(SW_SHOW);
    cToolBar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY);
    cToolBar.ModifyStyle(0, 0x0800);
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);

    Reply
  • Almost good ...

    Posted by Legacy on 07/02/2003 12:00am

    Originally posted by: Adri Gerritsen

    It's great!
    But .... UPDATE_COMMAND_UI is not handled (after defining it in ClassWizard).

    How to fix it???

    Reply
  • Great! I love you!

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

    Originally posted by: LLL

    !!!
    

    Reply
  • How do you control the Toolbars background color.

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

    Originally posted by: Sam Sabliny

    Thanks a lot. It works. There is still one thing. You still get the error message (The bitmap has been imported correctly, however because it contains more than 256 colors, it cannot be loaded in the bitmap editor)when you import the hi-color toolbar bitmap. is there a way around it?
    Is three a way to control the backgroud color of the toolbar, and to get rid of the rectangle border when you hover over the each button in the toolbar ?

    Thanks.
    Sam

    Reply
  • Toolbars with more than 256 colors - Hi-color bitmaps.

    Posted by Legacy on 11/15/2002 12:00am

    Originally posted by: Sam Sabliny

    Thanks a lot. It works. There is still one thing. You still get the error message (The bitmap has been imported correctly, however because it contains more than 256 colors, it cannot be loaded in the bitmap editor)when you import the hi-color toolbar bitmap. is there a way around it?

    Is three a way to control the backgroud of the toolbar, and to get rid of the rectangle border when you hove over the each button in the toolbar ?

    Thanks.
    Sam

    Reply
  • Thanks a lot. It works. Toolbars with more than 256 colors - Hi-color bitmaps.

    Posted by Legacy on 10/30/2002 12:00am

    Originally posted by: Sam Sabliny

    Thanks a lot. It works. There is still one thing. You still get the error message (The bitmap has been imported correctly, however because it contains more than 256 colors, it cannot be loaded in the bitmap editor)when you import the hi-color toolbar bitmap. is there a way around it?
    This solution worked for toolbars. Does it apply for importing pushbutton bitmaps with more than 256 colors?

    Thanks again.

    Sam.

    Reply
  • Awesome!...but....

    Posted by Legacy on 10/17/2002 12:00am

    Originally posted by: Brett

    This is a really cool tip!! But, how do I make the image different for whether the button is checked or not? For example, when the button is clicked the first time it stays down until clicked again. I want a different image for when the button is down.

    Thanks!!!

    Reply
  • Not quite right.....

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

    Originally posted by: Scott Lemmer

    When I followed these directions, it added the toolbar button and it looked good, BUT it copied it over the top of one of my other toolbar buttons and the rest of my toolbar buttons were no longer visible.... Can anyone help? I just want to add one toolbar button with more colors to the toolbar with the rest of my usual buttons...

    Thanks,
    Scott

    Reply
  • Don't work

    Posted by Legacy on 07/27/2002 12:00am

    Originally posted by: malik_mumtaz

    I have downloaded and added it in my application.If i change the ID's of controls in IDR_TOOLBAR1 mean all must have ID_TEST as ID if not then bitmap image is not displayed correctly.

    I have made ID_TEST then how i can generate event for each button in Bitmap.

    waiting for reply.

    Reply
  • Easy and Working.

    Posted by Legacy on 07/14/2002 12:00am

    Originally posted by: Shachar

    Excellent. Thanks.

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

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