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

Toolbar with image background

, 30 May 2003
Rate this:
Please Sign up or sign in to vote.
Shows how to display a bitmap in a toolbar as background.

Sample Image - imagetoolbar.jpg


The proposed class is based on Daniel Godson's: Generating inactive/disabled images for toolbar. I have fixed some errors in the original code. But there are still some shortcomings left:

  1. the function to load bitmap from the file and display it is not implemented
  2. the size of buttons on the toolbar is 24×24, I haven't give an interface to change it.

Using the code

Just 2 places you need to edit for your own use.

First is,

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;
  if (!m_wndToolBar.CreateEx(this, 
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
  int *num,i,j=m_wndToolBar.GetToolBarCtrl().GetButtonCount();
  num=new int[j+1];
  num[0]=j;//button numbers,include the separators.
     if(ID_SEPARATOR == m_wndToolBar.GetItemID( i ))
  }//get the button represent the 
  //separators.the info is used to calc 
  //the position of the buttons.

    RGB(255, 0, 255),num); //the first Parameter 
    //specify the resource id of button bitmap , 
    //second is the backgroud color of  the toolbar.
  if (!m_wndStatusBar.Create(this) ||
    TRACE0("Failed to create status bar\n");
    return -1;      // fail to create
  // TODO: Delete these three lines if
  // you don't want the toolbar to
  //  be dockable
  delete []num;
  return 0;

Second is, change the background bitmap here, by resource ID. So you must add the bitmap to your workplace first.

void CMainFrame::OnChangebk() 
  // TODO: Add your command handler code here
           RGB(255, 0, 255) , IDB_BITMAP1);
    m_wndToolBar.UpdateBk(IDR_MAINFRAME_24 ,
       RGB(255, 0, 255) , IDB_BITMAP2);


  • Thanks for xxxyyyzzz's translation!
  • Thanks for DavidRipple's suggestion!


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


China China
No Biography provided

Comments and Discussions

Generalnot working in VS 2005 PinmemberMember 423561323-Nov-09 0:38 
QuestionWhy this program only support multi-byte character set? Pinmemberbenjamin_tang27-Sep-08 21:56 
Generalif use this in rebar , the bitmap can extend to rightmost PinmemberCryingwind19-Dec-04 20:49 
GeneralDamn!!! PinmemberSchniddel14-Sep-04 9:38 
Generalmemory leak!!!!!!! Pinmemberhuangashen20-Jul-04 17:13 
Generaldo as the following , ok! Pinmemberccart77720-Aug-04 17:27 
GeneralRe: do as the following , ok! Pinmemberyaodebo25-Jan-07 4:04 
GeneralRe: WRONG Pinmemberyaodebo25-Jan-07 17:07 
Generalvery nice Pinmemberkrskumar26-Sep-03 4:14 
Generalhoe to very nice... but how ! incorporate in dialog base application PinmemberRajesh match24-Sep-03 3:26 
GeneralWorking under Windows XP PinmemberLi Zhaoming28-May-03 1:33 
GeneralRe: Working under Windows XP PinmemberCryingwind29-May-03 19:21 
GeneralBeautiful Pinmember*love*24-May-03 19:56 
GeneralTHANKS VERY MUCH!! I had changed the project PinmemberCryingwind24-May-03 19:04 
GeneralInternational forum PinmemberXSimon23-May-03 2:24 
GeneralA suggestion to Chinese authors PinmemberDavidRipple22-May-03 18:36 
GeneralRe: A suggestion to Chinese authors Pinmemberjjqiao28-Dec-03 23:47 
GeneralRe: A suggestion to Chinese authors Pinmemberhaoshenghan26-Apr-04 5:04 
GeneralRe: A suggestion to Chinese authors Pinmembermace5-May-04 3:26 
GeneralLet me try to translate it, hehe Pinmemberxxxyyyzzz22-May-03 10:28 
Generalwtf PinmemberSteve McLenithan22-May-03 3:27 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150224.1 | Last Updated 31 May 2003
Article Copyright 2003 by Cryingwind
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid