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:
- int CMainFrame::OnCreate (lpcreatestruct lpcreatestruct)
- {
- ......
- TODO: If you don't want toolbars and menu bars to be docked, delete the five elements
- M_wndmenubar.enabledocking (Cbrs_align_any);
- M_wndtoolbar.enabledocking (Cbrs_align_any);
- EnableDocking (Cbrs_align_any);
- DockPane (&m_wndmenubar);
- DockPane (&m_wndtoolbar);
- M_wndtoolbar.setwindowtext (_t ("toolbar")); //This is a self-added
- ......
- return 0;
- }
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:
- if (!m_wndtoolbar.createex (this, Tbstyle_flat, Ws_child | ws_visible | Cbrs_top | Cbrs_gripper | Cbrs_tooltips | cbrs_flyby | Cbrs_size_dynamic) | |
- !m_wndtoolbar.loadtoolbar (theapp.m_bhicoloricons? Idr_mainframe_256:idr_mainframe))
- {
- TRACE0 ("Failed to create Toolbar"); return-1; //Failed to create
- }//toolbars created by yourself
- 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) | |
- !m_wndtoolbar2.loadtoolbar (theapp.m_bhicoloricons? Idr_mainframe_256:idr_mainframe))
- {
- TRACE0 ("Failed to create Toolbar"); return-1; //Failed to create
- }
(2) own toolbar floating or docking window
- TODO: If you don't want toolbars and menu bars to be docked, delete the five elements
- M_wndmenubar.enabledocking (Cbrs_align_any);
- M_wndtoolbar.enabledocking (Cbrs_align_any);
- M_wndtoolbar2.enabledocking (Cbrs_align_any); //self-created toolbars
- EnableDocking (Cbrs_align_any);
- DockPane (&m_wndmenubar);
- DockPane (&m_wndtoolbar);
- 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