VC + + Dynamically creates a single toolbar and loads an external bitmap (BMP) file as a toolbar image

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.