1. MFC dialog box
1. Execution of domodal Functions
1.1 search for and load dialog box Resources
1.2 set the parent window to unavailable
1.3 create and display dialog box
1.4 enter the message loop in the dialog box
1.5 click OK or cancel or close to hide the dialog box window.
1.6 set the parent window to available and active
1.7 destruction dialog box
1.8 release dialog box Resources
1.9 Return the execution result (idok/idcancel)
Dialog Box 2 Data Exchange Technology (DDX)
The data exchange technology of the dialog box is introduced to facilitate the operation of controls. Set
The member variable is bound to the control in the dialog box.
.
1 related functions:
1.1 requires a series of binding Functions
(Function binding is used to bind member variables to controls)
Ddx_control (PDX, Control ID, control type variable name );
Ddx_text (PDX, Control ID, value type variable name );
1.2 data exchange function dodataexchange
Contains all the binding functions in the dialog box.
Cdialog: The oninitdialog function indirectly calls the dodataexchange function,
After the dialog box is started, the control and variable are bound.
1.3 updatedata (bool)-when the value entered by the user in the control is bound to the value of the control
This function is called when data is exchanged.
Updatedata (true)-the value of the control is passed to the member variable.
Updatedata (false)-the value of the member variable is passed to the control.
2. Use DDX for a logon example
Use of the three MFC controls
1 static controls (cstatic) include images, static text, and group boxes. The default ID of the control is
Idc_static: to bind a member variable to a static control, you must first
Modify the Control ID.
The two button controls (cbutton) include general buttons, complex buttons, and single-choice buttons. Single choice
To bind a member variable, select the group attribute. Radio button
Group. The order of the tabs in the same group of buttons must be continuous, and the number of the tabs in the group must be small.
You can set the group attribute in several groups.
3. Combo box control and list box Control
A single-choice box is usually used. A list box can be selected one by one or more. You can use
Attribute setting data items.
4. Example of playing an animation
4.1 file dialog box
Cfiledialog (
Bool bopenfiledialog, // indicates opening or saving as a dialog box
Lpctstr lpszdefext = NULL. It is used in the Save As dialog box to indicate the default extension.
Lpctstr lpszfilename = NULL, used in the Save As dialog box to indicate the default file name
// Dialog box style
DWORD dwflags = ofn_hidereadonly | ofn_overwriteprompt,
Lpctstr lpszfilter = NULL, // sets the file type filter string
Cwnd * pparentwnd = NULL // parent window, usually null
);
Set the format of the filter string for the file type:
1 multiple data items are separated by "|", and the entire string ends with "|;
2 each data item consists of two parts: display part and filter part. These two
Parts are separated by "|.
"Video file (*. AVI) | *. Avi | all files (*. *) | *. * | ";
4.2 Use of clistbox and ccombobox
4.2.1 add data items
Clistbox: addstring
Ccombobox: addstring
4.2.2 search for data items
Clistbox: findstring lb_err
Ccombobox: findstring cb_err
4.2.3 deleting data items
Clistbox: deletestring
Ccombobox: deletestring
4.2.4 obtain/set the selected data item
Clistbox: getcursel/setcursel
Ccombobox: getcursel/setcursel
4.2.5 obtain/set additional data for data items
Clistbox: getitemdata/setitemdata
Ccombobox: getitemdata/setitemdata
...
---------------------------------------
I. Use of controls
Demonstrate the rotation button (cspinbuttonctrl), progress bar (cprogressctrl), and
Use of the slider control (csliderctrl.
1. Set the value range represented by the control.
Setrange/getrange
Setrange32/getrange32
2. Set the step or increment of the control.
Cspinbuttonctrl: setaccel
Cprogressctrl: setstep
Csliderctrl: pagesize
Csliderctrl: linesize
3. Set/obtain the current location
Setpos/getpos
List controls
1. Related Classes
Clistview-essentially a View class. It is equivalent to including
A clistctrl control.
Getlistctrl () to get the control contained in the view.
Clistctrl-essentially a control, which is often used to display data in a dialog box.
2. Analyze the clistctrl control:
Controls can display data in different styles, including icons, icons, lists, and
Reports and other four styles. If the data is displayed in the report style, the control can also
Contains multiple columns. A control contains multiple data items. Information Package for each data item
Including icons and text. The icons of different data items are also different.
Contains two icons (large icon list and small icon list ).
3. Use of controls
3.1 set the widget icon list (large icon list and small icon List)
Clistctrl: setimagelist
3.2 modify the display style of the control
Cwnd: modifystyle
3.3 Add Columns
Clistctrl: insertcolumn
3.4 add data items
Clistctrl: insertitem
3.5 set column text
Clistctrl: setitemtext
3.6 set/obtain additional data for data items
Clistctrl: setitemdata/getitemdata
3.7 set the background image of the control
Clistctrl: setbkimage
The initialization of the OLE library afxoleinit () is required ();
3.8 set the background color of Text
Clistctrl: settextbkcolor (clr_none)
...
Three-tree control
1. Related Classes
Ctreeview-is a view that contains a ctreectrl in the cview customer Zone
Control. Call gettreectrl () to obtain the control contained in the view.
Ctreectrl-is a control that displays data in the dialog box.
2 Use of ctreectrl
2.1 ctreectrl Analysis
The ctreectrl control is used to display data with hierarchies. The tree control is
It is composed of nodes. The information of each node includes text and icons,
The node Icons can be selected or not.
2.2 Specific Use
2.2.1 set the icon list
Ctreectrl: setimagelist
2.2.2 insert a node
Ctreectrl: insertitem
2.2.3 set the node height
Ctreectrl: setitemheight
2.2.4 set the expand status of a node
Ctreectrl: Expand
2.2.5 set/obtain additional data of a tree node
Ctreectrl: setitemdata/getitemdata
...
In almost all function operations, a node handle is used as a parameter!
VC extension interface library...
Four properties page dialog box
1 category
Tag property page and Wizard property page
2 related classes
Cpropertypage class-Dialog Box class, with its own resource window.
Cpropertysheet class-framework window class, contains multiple page dialog boxes.
3. Tab property page (example: use the property page to set the line width and color of the image)
Used to set parameters, options, and other configurations
---------------------------------
One property page dialog box
1 category
Tag property page and Wizard property page
2 related classes
Cpropertypage class-Dialog Box class, with its own resource window.
Cpropertysheet class-framework window class, contains multiple page dialog boxes.
3. Tab property page (example: use the property page to set the line width and color of the image)
Used to set parameters, options, and other configurations
3.1 insert a dialog box resource. Pay attention to the type of the dialog box resource. Double-click to generate the corresponding
The parent class must be cpropertypage. Repeat this step.
Add multiple page dialog box.
3.2 Add the csheet class subclass of the cpropertysheet class and add the page
Object. In the csheet class constructor, add the Page Object to the form.
Addpage (& m_page1 );
Addpage (& m_page2 );
3.3 In the message processing function of the menu, create and display the property page
Cpropertysheet: domodal
3.4 set the application button to available
Cpropertypage: setmodified
3.5 Message Processing (rewrite virtual functions)
Cpropertypage: onapply
Cpropertypage: onok
Cpropertypage: oncancel
4. Wizard properties page
It is usually used to guide the user to select or set the final step by step according to the set steps
Complete a function.
4.1 and 3.1 are the same
4.2 and 3.2 are the same
4.3 set to wizard mode before creating and displaying the dialog box
Cpropertysheet: setwizardmode ()
Cpropertysheet: domodal ()
4.4 set the wizard button for each page, right-click the cpage1 class, and select Add
Virtual function, select onsetactive () in the list, in the function:
(Cpropertysheet *) getparent ()-> setwizardbuttons (
Pswizb_next );
In the same way, set
Wizard button.
4.5 obtain information selected by the user on each page. The common method is to give the control
Bind member variables.
4.5.1cpage1 processing:
Bind a member variable to a single-choice button and a list box. Add cpage1
In the oninitdialog function:
M_wndcity.addstring ("Beijing ");
M_wndcity.addstring ("Shanghai ");
M_wndcity.addstring ("Tianjin ");
M_wndcity.addstring ("Chongqing ");
4.5.2 null judgment
Right-click the cpage1 class, select Add virtual function, and select onwizardnext,
In the function:
Updatedata (true );
If (-1 = m_njob)
{
MessageBox ("select your career! ");
Return-1;
}
If (m_strcity = "")
{
MessageBox ("select your city ");
Return-1;
}
4.5.3 handling of cpage2 and cpage3 classes binds member variables to the control.
It is null in onwizardnext and onwizardfinish respectively.
Note that the onwizardfinish return value type is bool.
4.6 In onwizardprop, the message processing function of the menu in the View:
4.6.1 add member variables to the view and initialize them in the constructor
Int m_njob;
Cstring m_strcity;
Bool m_bflag [4];
Cstring m_strsalary;
4.6.2 In the onwizardprop of the View class, pass the values on the page
Pass to view:
// Create and display the wizard property page
Csheet sheet ("Wizard property page ");
// Set the display mode to wizard mode.
Sheet. setwizardmode ();
If (id_wizfinish! = Sheet. domodal () return;
// 1 pass the value of each page to the view
M_njob = sheet. m_page1.m_njob;
M_strcity = sheet. m_page1.m_strcity;
// 2 re-paint the view to display new data
Invalidate (true );
4.6.3 output the values of each variable in the ondraw Function
MFC Multithreading
Com 4 days
Database (ODBC and ADO) + network communication (socket) 3 days
VOD System (4)