VC + + Discussion on the usage of cmfctoolbar in VS2010

Source: Internet
Author: User
Tags visual studio 2010

This article will introduce you to the usage of cmfctoolbar in Visual Studio 2010, CMFCToolBar allows you to customize the toolbar icons using static member functions SetUserImages () Sets a CMFCToolBarImages object to be shared by all CMFCToolBar objects.

AD:

Some features have been added to the menu since VS2008, but these features are rarely explained in help, causing a lot of trouble for users. The author through the search and his own groping, the use of its preliminary understanding, the formation of this article, if you can solve some problems for the later, I will be pleased.

First, the wizard automatically generated cmfctoolbar

The wizard-generated menus are really beautiful because of the system style applied. Such as:

However, in some cases (as far as the author is not sure), the menu generated by the wizard will not have a name and will appear empty under the submenu of the Toolbars and docking window. Such as:

The solution to this situation is to give the toolbar a name. Name the toolbar in the CMainFrame::OnCreate () event:

    1. int CMainFrame::OnCreate (lpcreatestruct lpcreatestruct)
    2. {
    3. ......
    4. TODO: If you don't want toolbars and menu bars to be docked, delete the five elements
    5. M_wndmenubar.enabledocking (Cbrs_align_any);
    6. M_wndtoolbar.enabledocking (Cbrs_align_any);
    7. EnableDocking (Cbrs_align_any);
    8. DockPane (&m_wndmenubar);
    9. DockPane (&m_wndtoolbar);
    10. M_wndtoolbar.setwindowtext (_t ("toolbar")); //This is a self-added
    11. ......
    12. return 0;
    13. }

Second, add a toolbar yourself

Toolbars that you add yourself will not appear in the menu if you follow the wizard's build, although the toolbar has been created. Such as:

To make a menu appear in toolbars and docking windows, you can't do it exactly as the wizard generates. You need to imitate the wizard-generated look but still change a bit.

(1) Create your own toolbars

Define a toolbar variable in the header file. CMFCToolBar m_wndtoolbar2;

To create and load a toolbar in the CMainFrame::OnCreate () event:

  1. if (!m_wndtoolbar.createex (this, Tbstyle_flat, Ws_child | ws_visible | Cbrs_top | Cbrs_gripper | Cbrs_tooltips | cbrs_flyby |  Cbrs_size_dynamic) | |
  2. !m_wndtoolbar.loadtoolbar (theapp.m_bhicoloricons? Idr_mainframe_256:idr_mainframe))
  3. {
  4. TRACE0 ("Failed to create Toolbar"); return-1; //Failed to create
  5. }//toolbars created by yourself
  6. if (!m_wndtoolbar2.createex (this, Tbstyle_flat, Ws_child | ws_visible | Cbrs_top | Cbrs_gripper | Cbrs_tooltips | cbrs_flyby | Cbrs_size_dynamic,crect (1,1,1,1), theapp.m_bhicoloricons?  idr_mainframe_256 +1:idr_mainframe+1) | |
  7. !m_wndtoolbar2.loadtoolbar (theapp.m_bhicoloricons? Idr_mainframe_256:idr_mainframe))
  8. {
  9. TRACE0 ("Failed to create Toolbar"); return-1; //Failed to create
  10. }

(2) own toolbar floating or docking window

    1. TODO: If you don't want toolbars and menu bars to be docked, delete the five elements
    2. M_wndmenubar.enabledocking (Cbrs_align_any);
    3. M_wndtoolbar.enabledocking (Cbrs_align_any);
    4. M_wndtoolbar2.enabledocking (Cbrs_align_any); //self-created toolbars
    5. EnableDocking (Cbrs_align_any);
    6. DockPane (&m_wndmenubar);
    7. DockPane (&m_wndtoolbar);
    8. DockPane (&M_WNDTOOLBAR2); //self-created toolbars

Running the program at this time will show such as:

(3) Give your own toolbar a name

M_wndtoolbar2.setwindowtext (_t ("My Toolbars"));

At this point the program runs as follows:

Three, floating my toolbar

In the previous CToolBar, the floating toolbar can use the FloatControlBar () function. But you can't use it in CMFCToolBar, you need to use the Cmfctoolbar::floatpane () function. , M_wndtoolbar2.floatpane (CRect (80,150,130,200));

Four, show or hide my toolbars

When CToolBar, the Show or hide toolbar can use the Showcontrolbar () function, but you need to use the Cmfctoolbar::showpane () function when cmfctoolbar.

This->showpane (&m_wndtoolbar2,false,false,true);

This->showpane (&m_wndtoolbar2,true,false,true);

Or

M_wndtoolbar2.showpane (false,false,true);

M_wndtoolbar2.showpane (true,false,true);

V. Remaining issues

How to make a toolbar two or more rows, or how to make a toolbar two or more columns.

Original link:http://www.cnblogs.com/luoshupeng/archive/2011/08/15/2139645.html

VC + + Discussion on the usage of cmfctoolbar in VS2010

Related Article

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.