toolbar
He Zhidan
main content:
1, summary.
2, common functions
3, instance.
4, dynamic establishment toolbar
5, embed in the toolbar
6, use the dialog box plus the chart button to toolbar
We can click Right-click on the Toolbar of the Resource Editor, select Insert Toolbar, select a toolbar, double-click on the right, you can edit it. We can use graphics tools and color box to paint its appearance, its properties have an ID, long, width and mouse pointing to it.
General CToolBar definitions in CMAINFRAME, in fact, is now completed in the CMAINFRAME oncreate function.
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 (idR_mainframe))
{
Trace0 ("Failed to Create Toolbar / N);
Return -1; // fail to create
}
m_wndtoolbar.enabledocking (CBRS_ALIGN_ANY);
Enabledocking (CBRS_ALIGN_ANY);
DockControlbar (& M_WndToolbar);
Bool Create (CWND * PParentWnd,
DWORD DWSTU; E = WS_CHILD | WS_VISIBLE | CBRS_TOP,
UINT NID = AFX_IDW_TOOLBAR);
PParentWnd Specifies the you belong to.
DWStyle Specify Toolbar Style
The CBRS_TOP allows the toolbar to be located at the top of the frame window.
CBRS_BOTTOM Allow toolbars in the bottom end of the frame window
CBRS_NOALIGN parent window changed the size of the toolbar position unchanged
CBRS_ToolTIPS toolbar display prompt bar
CBRS_SIZE_DYNAMIC Tools is dynamic
The CBRS_SIZE_FIXED toolbar is fixed
The CBRS_FLOATING toolbar is floating
CBRS_FLYBY Displays prompt information when the mouse brings over the command button
CBRS_HIDE_INPLACE toolbar is not visible to users
The setButtonStyle () function is used to set the style or spacer of the command button, or set to a set of styles of the button determine the appearance of the button and the user's reaction method.
Void setButtonStyle (int NINDEX, UINT NSTYLE);
NINDEX Specifies the index number of the buttons or interval in the toolbar.
NStyle TBBS_BUTTON standard button, this is the default value
TBBS_SEPARATOR interval
TBBS_CHECKBOX automatic confirmation area
TBBS_GROUP is marked as a set of buttons
TBBS_CHECKGROUP is marked as a set of confirmation box Enabledocking functions of the Controlbar class and the DockControlbar function of the CFraMewnd class, setting the capable activity of the toolbar.
Void EANBLEDOCKING (DWORD DWSTYLE)
CBRS_ALIGN_TOP allows the toolbar to be on the upper side of the client area
CBRS_ALIGN_BOTTOM allows the toolbar to be located on the lower side of the room
CBRS_ALIGN_LEFT allows the toolbar to be located on the left side of the client area
CBRS_ALIGN_RIGHT allows the toolbar to be on the right side of the client area
CBRS_ALIGN_ANY Allows the toolbar in any location of the client area
CBRS_FLOAT_MULTI allows multiple control bar to float in a mini frame window
Void DockControlbar (....)
PBAR to float the control bar pointer.
NDOCKBARID specifies that the location allowed to float, or 0 does not allow floating, which can be combined by the following value:
The AFX_IDW_DOCKBAR_TOP control bar is placed on the upper side of the frame window;
AFX_IDW_DOCKBAR_BOTTOM control bar is placed on the lower side of the frame window
AFX_IDW_DOCKBAR_LEFT control bar is placed on the left side of the frame window
The AFX_IDW_DOCKBAR_RIGHT control bar is placed on the right side of the frame window.
Change the command button style of the toolbar, the toolbar's button is generally the default to the command button. When the standard mouse is released, the command button will "bounce", if we want the command button to stay in the pressed state, you can put the command The button's style is set to a confirmation box. In the ON_UPDATE_COMMAND_UI message handler, use the setCheck () member function and the setradio () member function to change the button status.
SetCheck () parameter 0 indicates the delete state, 1 indicates the confirmation status, 2 indicates that the case is not confirmed.
SetRadio () parameter 0 represents the delete state, non-0 means a confirmation state.
We build a single document program with the application wizard. Add a button in the toolbar. The ID is set to ID_TIME. Add a Boolean data type M_BTIME to the CMAINFRAME class, the initial value is false.
Ctrl W Add id_time's ON_COMMANDT and ON_UPDATE_COMMAND_U message response function.
Void CMAINFRAME :: OnShowTime ()
{
m_btime =! m_btime;
}
Void CMAINFRAME :: onupdateshowtime (ccmdui * pcmdui)
{
PCMDUI -> setCheck (m_btime);
}
Note If there is a menu of the same ID, it will automatically hook the hook according to the button.
In fact, we can build a toolbar without Toolbar resources. code show as below:
Uint nid [] =
{ID_FILE_NEW,
ID_FILE_OPEN,
ID_TIME
}
m_wndtoolbar.create (this);
m_wndtoolbar.loadbitmap (idb_bitmap1);
M_WndToolBar.SetButtons (NID, SIZEOF (NID) / SIZEOF (UINT));
The size of the bitmap should be appropriate, otherwise it will affect the beauty, and the last line makes several IDs and related toolbars and related. If you want to set the style of each button, you can add the last line to:
M_WndToolBar.SetButtonStyle (1, TBBS_SEPARATOR);
Also m_wndtoolbar.create (this);
m_wndtoolbar.loadbitmap (idb_bitmap1);
M_WndtoolBar.setButtons (NULL, 3);
M_WndToolBar.SetButTonInfo (0, ID_FILE_NEW, TBBS_BUTTON, 0);
M_WndToolBar.SetButTonInfo (1, ID_File_Open, TBBS_Button, 2);
Embed a control in the toolbar, such as editing boxes
1. Define an editing control object and cannot be partial variables, otherwise it will be released.
2, call CREATE, the only thing to note is that the location is to be on the site of the toolbar.
CRECT RECT;
m_wndtoolbar.getItemRect (1, & Re);
Edit.create (WS_CHILD | WS_VISIBLE, RECT, & M_WNDTOOLBAR, ID_EDIT);
Use the dialog to add the chart button to make the toolbar.
Insert a dialog, Styles' style is set to Child, and Border is set to None.
Changed to cdialogbar in CMAINFRAME, and add a CBitmapButton BB;
Change the sentence of the establishment of the toolbar to:
m_wndtoolbar.create (this, IDd_dialog1, ws_child | ws_visible | cbrs_top, afx_idw_status_bar);
The last ID is determined by myself. Ctrl F5, an extremely unestictable toolbar is coming out.
To finish the button, their processing functions are still Ctrl W. Hook on the Owner Drawer and Bitmap of the Button Styles. Add a sentence in the place just now.
Bb.autoload (IDC_Button1, & m_wndtoolbar);
Note that you need to add three bitmaps (one can also). As your button is named X, the name of the just three bitmap is "XUP", "XDown", "Xfocus", is abbreviated as "Xu", "XD", "XF".