Click here to Skip to main content
Click here to Skip to main content

Using Hot Toolbar Buttons

By , 15 Dec 1999
 
  • Download demo project - 30 Kb
  • Sample Image - toolbar_hotbuttons.gif

    <!-- Article Starts -->

    If you wanted to add hot toolbar buttons like the ones seen in internet explorer, it is pretty straight forward. This approach for will work for both Visual C++ 5 and 6, however you may want to read up on the enhancements to the toolbar class for VC 6.0.

    After your toolbar has been created in CMainFrame::OnCreate(), you will need to add the following code, this is assuming that you have two bitmap resources already created IDB_TOOLBAR_COLD for normal, and IDB_TOOLBAR_HOT for hot buttons:

    // Set up hot bar image lists.
    CImageList imageList;
    CBitmap    bitmap;
    
    // Create and set the normal toolbar image list.
    bitmap.LoadBitmap(IDB_TOOLBAR_COLD);
    imageList.Create(21, 20, ILC_COLORDDB|ILC_MASK, 13, 1);
    imageList.Add(&bitmap, RGB(255,0,255));
    m_hotToolBar.SendMessage(TB_SETIMAGELIST, 0, (LPARAM)imageList.m_hImageList);
    imageList.Detach();
    bitmap.Detach();
    
    // Create and set the hot toolbar image list.
    bitmap.LoadBitmap(IDB_TOOLBAR_HOT);
    imageList.Create(21, 20, ILC_COLORDDB|ILC_MASK, 13, 1);
    imageList.Add(&bitmap, RGB(255,0,255));
    m_hotToolBar.SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)imageList.m_hImageList);
    imageList.Detach();
    bitmap.Detach();
    

    The send message portion of the code has been wrapped into a CToolBarCtrl() function call for Visual C++ 6. If you will notice, I have used 24 bit color images with the toolbar shown here, so you are not limited to just 16 colors.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Kirk Stowell
    CEO Codejock Software
    United States United States
    No Biography provided

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    QuestionHow to Dock the Hot Toolbar with the Main Toolbarmembervikrant kpr11-May-07 10:01 
    GeneralExcellentmemberNeilDevlin5-Feb-05 5:54 
    GeneralRe: ExcellentmemberAlex Gibbs20-Mar-05 11:14 
    Generalvera neat !memberLi Zhaoming26-Nov-02 1:55 
    The codes are very neat and powerful !
    Here's the plain API version:

    #define IMAGEWIDTH 24
    #define IMAGEHEIGHT 24
     
    HBITMAP hbm = (HBITMAP)LoadBitmap(g_hinstance, MAKEINTRESOURCE(IDB_TOOLBAR));
    HIMAGELIST imageList = ImageList_Create(IMAGEWIDTH, IMAGEHEIGHT, ILC_COLORDDB|ILC_MASK, NUMIMAGES, 0);
    ImageList_AddMasked(imageList, hbm, RGB(191,191,191));
    DeleteObject(hbm);
    SendMessage(hwndToolbar, TB_SETIMAGELIST, 0, (LPARAM)imageList);
     
    hbm = (HBITMAP)LoadBitmap(g_hinstance, MAKEINTRESOURCE(IDB_TOOLBARHOT));
    HIMAGELIST imageList2 = ImageList_Create(IMAGEWIDTH, IMAGEHEIGHT, ILC_COLORDDB|ILC_MASK, NUMIMAGES, 0);
    ImageList_AddMasked(imageList2, hbm, RGB(191,191,191));
    DeleteObject(hbm);
    SendMessage(hwndToolbar, TB_SETHOTIMAGELIST, 0, (LPARAM)imageList2);

    Generalvera good !memberChris maunder and nish19-May-02 2:46 
    GeneralHelp memembersreenivasulu2-Jan-01 9:22 
    GeneralLittle bugmemberSerrand23-Nov-00 23:52 
    GeneralGreat stuff - and here is the Disabled flagsussMark Grieve15-Mar-00 17:27 
    GeneralIt is vera poor!!!!sussTippler11-Mar-00 7:30 
    GeneralRe: It is vera poor!!!!sussCode Police18-Jun-00 19:51 
    GeneralRe: It is vera poor!!!!sussPhartPhace5-Sep-00 20:16 
    GeneralRe: It is vera poor!!!!memberAnonymous15-May-01 19:10 
    QuestionWhat about in 256 colour mode ?sussChristian22-Jan-00 20:57 
    AnswerRe: What about in 256 colour mode ?sussTMan19-Jul-00 10:49 
    GeneralRe: What about in 256 colour mode ?sussDarkByte5-Sep-00 15:54 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web01 | 2.6.130617.1 | Last Updated 16 Dec 1999
    Article Copyright 1999 by Kirk Stowell
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid