Let the toolbar "Call," to go "Preface: The purpose of the toolbar design is to use convenience; but people's" lazy "is endless: When we work in the view area, we must reach out Toolbars often feel that it is "30,000 feet". So, the dynamic menu became everyone's darling. But it doesn't want to call like the dynamic menu, "Is it like a dynamic menu? ? Everyone is a window, why do you have to be high? ! ! Therefore, there is a play toolbar of this article. Method: 1. First, in the main frame class CMAINFRAME class declare a public CToolBar: public: ctoolbar m_wndtoolbar;
2, create it in CMAINFRAME :: OnCreate, and make it have Docking features: int CMAINFRAME :: OnCreate (lpcreatestruct lpcreateStruct) {if (cmdiframeWnd :: oncreate (lpcreateStruct) == -1) Return -1;
if (! m_wndToolBar.Create (this) ||! m_wndToolBar.LoadBitmap (IDR_MAINFRAME) ||! m_wndToolBar.SetButtons (buttons, sizeof (buttons) / sizeof (UINT) 1)) {TRACE0 ( "Failed to create toolbar / n "); RETURN -1; // Fail to Create}
IF (! M_WndStatusbar.create (this) ||! m_wndstatusbar.setindicators (INDICATORS, SIZEOF (INDCATORS) / SIZEOF (TRACE0 ("Failed to Create Status Bar / N); Return-1; // Fail TO CREATE}
// Make M_WndToolBar features automatic docking: m_wndtoolbar.enabledocking (cbrs_align_any); Enabledocking (CBRS_ALIGN_ANY); DockControlbar;
Return 0;}
3. Add a WM_RBUTTONDOWN's response function in your view class and add a BOOL variable M_Bmove (default true). When M_Bmove is True, the summoning toolbar is on the mouse; when m_bmove is false, let the toolbar back. Not much to say, look at the code first, you will find it very simple. Void cdynamenuview :: OnRButtondown (uint nflags, cpoint point) {
CMainFrame * pMainFrame = (CMainFrame *) AfxGetMainWnd (); CToolBar * pToolBar = & pMainFrame-> m_wndToolBar; CRect rect; pToolBar-> GetWindowRect (& rect); if (m_bMove) {pToolBar-> SetParent (NULL); ClientToScreen (& point) Ptoolbar-> MoveWindow (Point.x, Point.y, Rect.Width (), Rect.Height (), true; m_bmove = false;} else {ptoolbar-> setParent (PMAINFRAME); // PMainframe-> DockControlbar (ptoolbar); ptoolbar-> movewindow (0, 0, rect.width (), Rect.Height (), true; m_bmove = true;} cview :: OnRButtondown (nflags, point);}
postscript:
I want to write some things you have to do, and the name is called "Play MFC Series" (Play With MFC). Why is this name? Because I want to implement some strange ideas with VC, so you can make yourself creative, and you can master MFC in this process. But I am afraid that there is not so much free time ... Hey!