Tool bar is also a common control.The CToolBar class is used in MFC to encapsulate various operations of toolbar controls. By calling
BOOL Create (CWnd * pParentWnd, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_TOP, UINT nID = AFX_IDW_TOOLBAR); Create a window using the following special style of toolbar controls:
- CBRS_TOPThe toolbar is at the top of the parent window.
- TCBRS_BOTTOMThe toolbar is at the bottom of the parent window.
- CBRS_FLOATINGTool bar is floating
To create a toolbar, follow these steps:Create a window, and then use BOOL LoadToolBar (LPCTSTR lpszResourceName); load the toolbar directly from the resource, or load the bitmap and specify the ID of each button. The Code is as follows:
UINT uID [5] = {IDM_1, IDM_2, IDM_3, IDM_4, IDM_5 };
M_toolbar.Create (pParentWnd );
M_toolbar.LoadBitmap (IDB_TOOLBAR );
M_toolbar.SetSizes (CSize (20, 20), CSize (16, 16); // you can specify the large size of a button.
And the size of the bitmap on the button
M_toolbar.SetButtons (uID, 5 );
AppWizard also generates tool bar code when generating code, and supports the dock function. Therefore, you do not need to directly operate the toolbar object.
The messages sent to the parent window when the buttons on the toolbar are pressed are the same as those in the menu, so you can useThe ON_COMMAND macro maps rows. Likewise, the buttons in the toolbar support ON_UPDATE_COMMAND_UI operations, such as SetCheck and Enable. You can use the buttons as a menu item with the same ID.
In subsequent chapters4. D. Use AppWizard to create and use the ToolBar StatusBar Dialog Bar.