When looking at the design of the MFC windows program, I felt that I had not mastered some areas and felt that it was necessary to record these skills and knowledge points. So I sorted them out and published these Reading Notes, it can deepen your understanding, and contribute a little bit of power.
Create a toolbar:
1. ctoolbar: Create create Toolbar
M_wndtoolbar.create (this, ws_child | ws_visible | cbrs_bottom, afx_idw_toolbar );
You can also: m_wndtoolbar.create (this );
M_wndtoolbar.setbarstyle (m_wndtoolbar.getbarstyle ()&~ Cbrs_top) | cbrs_bottom );
Call the ctoolbar: loadbitmap command to load the include button
Id static uint nbuttonids [] = {id_file_new, id_file_open ,...};
M_wndtoolbar.create (this );
M_wndtoolbar.loadbitmap (idb_bitmap );
M_wndtoolbar.setbuttons (nbuttonids, 10 );
Ctoolbar: setsizes to change the image and button size
2. Load -- ctoolbar: loadtoolbarctoolbar: setbuttontext from the resource file to change the string m_wndtoolbar.create (this) on the button surface );
M_wndtoolbar.loadtoolbar (idr_toolbar );
M_wndtoolbar.setbuttontext (0, _ T ("new "));
M_wndtoolbar.setbuttontext (1, _ T ("open "));
M_wndtoolbar.setsizes (csize (48, 42), csize (40, 19 ));
Tbbs_checkbox to create a check button tbbs_checkgroup is equivalent to tbbs_checkbox | tbbs_group. These attributes are useful for ctoolbar: setbuttonstyle. You can add a single button to the toolbar and select one of them as the default button.
Int nstate = m_wndtoolbar.gettoolbarctrl (). getstate (id_part_left );
M_wndtoolbar.gettoolbarctrl (). setstate (id_part_left, nstate | tbstate_checked );
Only the ccontrolbar: enabledocking function of the toolbar and the cframewnd: enabledocking function of the Framework Window are called, and their respective bits indicate that the side of the Framework Window is used as the tool bar installation position, the toolbar is valid only when it is float and can be placed.
M_wndtoolbar.enabledocking (cbrs_align_any );
Enabledocking (cbrs_align_any );
You can use the member functions dockcontrolbar and floatcontrolbar of cframewnd to move the toolbar to a floating dockcontrolbar (& m_wndtoolbar) on either side of the parent window );
Floatcontrolbar (& m_wndtoolbar, cpoint (x, y ));
The coordinate system tbbs_wrapped of the parent window is equivalent to the carriage return, and the buttons are placed in the next line.
M_wndtoolbar.setbuttonstyle (1, m_wndtoolbar.getbuttonstyle (0) | tbbs_wrapped );
Toolbar visibility:
1. cframewnd: onbarcheck to hide or display the menu item cframewnd: onupdatecontrolbarmenu to select or cancel the menu item whose ID matches the toolbar ID
On_update_command_ui (id_view_status_bar, onupdatecontrolbarmenu)
On_command_ex (id_view_status_bar, onbarcheck)
Write your own commands and update programs and use cframewnd: showcontrolbar to hide or display them. Check ws_visible to see if they are displayed.
On_command (id_view_toolbar, onvi1_lbar) on_update_command_ui (id_view_toolbar, onupdateviewtoolbar)
Void cmainframe: onviewtoolbar ()
{
Showcontrolbar (& m_wndtoolbar, (m_wndtoolbar.getstyle () & ws_visible) = 0, false );
}
Void cmainframe: onupdateviewtoolbar (ccmdui * pcmdui)
{
Pcmdui-> setcheck (m_wndtoolbar.getstyle () & ws_visible )? 1-0 );
}
You can only modify ws_visible to hide the view. When the toolbar is hidden, MFC adjusts the View Size to adapt to the changes in the client area of the Framework Window. ccontrolbar: onupdatecmdui is a virtual function, the main structure is called when the CPU is idle, and the two functions that are permanently updated in the toolbar of the control settings without the UI update Handler are reloaded: cframewnd: savebarstate and cframewnd :: loadbarstatesavebarstate writes the parking or floating status, location, direction, and visibility of Each toolbar to the Registry. In oncreate of the main framework window, call loadbarstate, call savebarstate in onclose, and add other button controls in the toolbar. 1. add a button separator or a white button to the toolbar resource, any ID and Image
2. Call ctoolbar: setbuttoninfo to increase the reserved position width so that it can accommodate the control. In this blank space, create the control setbuttoninfo (8, idc_combobox, tbbs_aggregator, nwidth );
Crect rect;
Getitemrect (8, & rect );
Rect. botton = rect. Top = nheight;
M_wndcombox.create (ws_child | ws_visible | ws_vscroll | cbs_dropdownlist, rect, this, idc_combobox );
Hresult callback dllgetversion (dllversioninfo * pdvi );
This function is not an API function. You need to use loadlibrary and getprocaddress to obtain the function pointer // check the void getcommonctrlversion of common CTRL (DWORD & dwmajor, DWORD & dwminor)
{
Dwmajor = dwminor = 0;
Hinstance hlib =: loadlibrary (_ T ("contrl32.dll "));
If (hlib! = NULL)
{
Dllgetversionproc pdllgetversion = (dllgetversionproc): getprocaddress (hlib, _ T ("dllgetversion "));
If (pdllgetversion)
{
Dllversioninfo DVI;
Zeromemory (& DVI, sizeof (DVI ));
DVI. cbsize = sizeof (DVI );
Hresult hR = (* pdllgetversion) (& DVI );
If (succeeded (HR ))
{Dwmajor = DVI. dwmajorversion; dwminor = DVI. dwminorversion ;}
}
Else
{Dwmajor = 4; dwmor = 0 ;}
: Freelibrary (hlib) ;}} DWORD dwmajor, dwminor; getcomctlversion (dwmajor, dwminor); If (dwmajor = 4 & dwminor> = 70) | dwmajor> 4)
{// The feature is supported}
Else
{// Not supported}
In the SDK windows program, wm_menuselect messages are usually used to update the descriptive text status bar of the status bar by creating the static uint nindicator [] = {id_separator, id_indicator_ins };
M_wndstatusbar.create (this );
M_wndstatusbar.setindicators (nindicators, 2 );
Use setpaneinfo to adjust the pane Information
M_wndstatusbar.setpaneinfo (0, id_separator, sbps_noborders, 64 );
You can update the pane of the status bar through message ing.
On_update_command_ui (id_indicators, onupdatetime)
Void cmainframe: onupdatetime (ccmdui * pcmdui)
{... Pcmdui-> settext (...);}
Add "/t" to the front of the German text in the status bar, align the text in the pane with two "/T", align the right pane to create a rebar first create toolbarm_wndtoolbar.createex (this );
M_wndtoolbar.loadtoolbar (idr_toolbar );
M_wndrebar.create (this );
M_wndrebar.addbar (& m_wndtoolbar );
You can use the 2nd and 3 parameters of addbar to specify the tag and background.
M_bitmap.loadbitmap (idb_bkgnd); m_wndrebar.addbar (& m_wndtoolbar, _ T ("Main"), & m_bitmap );
Note: This is the toolbar in chapter 1, which describes the status bar. There are some knowledge points in the subsequent sections, which I will release from time to time, hoping to improve myself.