Steps:
1, in the Framework class CMainFrame header file, add the image variable and the toolbar variable.
CMFCToolBarImages m_userimages; CMFCToolBar m_wndToolBar;
2. Dynamically create and load toolbars in the OnCreate function
//Create a tool barif(!m_wndtoolbar. CreateEx ( This, Tbstyle_flat, Ws_child | ws_visible | Cbrs_top | Cbrs_gripper | Cbrs_tooltips | cbrs_flyby | Cbrs_size_dynamic, CRect (1,1,1,1) , NID) {return false;//failed to create}//Set the toolbar button size and image size (because the picture you want to use is 24*24)M_wndtoolbar.setsizes (CSize ( to, -), CSize ( -, -));//To set the tool bar nameM_wndtoolbar.setwindowtext (_t ("test")) ... ..... .....//Set the dockable location (where you can set any position)m_wndtoolbar.enabledocking (cbrs_align_any);//Tool Bar DockingDockPane (&m_wndtoolbar); ......//Loading bitmap Imagesm_userimages.setimagesize (CSize ( -, -), FALSE);//Set Image sizeif(!m_userimages.load (Strbmppath))//Loading bitmap files{return false;} M_wndtoolbar.setuserimages (&m_userimages.);//Create a toolbar buttonm_wndToolBar. Insertbutton (CMFCToolBarButton (M_ncurstartid + i, I, NULL, TRUE,0));//here CMFCToolBarButton () the fourth parameter needs to be set to true so that the image that you set is called when redrawing. //Set button Promptm_wndToolBar. SetButtonText (nindex,strtemp);
So it's over.
VC + + Dynamically creates a single toolbar and loads an external bitmap (BMP) file as a toolbar image