1, the purpose of the experiment
Learn how to create an application using the MFC Application Wizard.
Learn how to create a new dialog box resource.
Learn how to generate dialog boxes.
2. Experimental content
Using the application to create a default dialog box application, in the dialog box can go to the next dialog box, in the New dialog box to complete the calculation of the total price function. As follows:
3, the Experiment Step 1, the new project
Open vs2017, new MFC project
Select based on the dialog box, and then the others are the default settings, click Finish.
2. modifying resources, adding controls
In the resource file, click Mfcdlg.rc
Then expand the Dialog folder and click Dialog to open the dialog box operator interface
To manipulate the dialog interface, you can add controls through the toolbox.
After the control has been truncated modified:
Select the button control, right-click the property, and in the caption of the property, make the following changes, you can see the key display turned into a calculation.
3. Insert a new dialog box template
Insert a new dialog box template below
Set the new dialog box properties as follows,
4. Create a dialog box class
Select the calculation dialog box, right-click, select Add Class
Click OK to generate a Cmydlg.h file
5. Add the control handler for the Open dialog box
Check the Idd_mfcdlg_dialog dialog box and double-click the Calculate button to open the MfcDLG.cpp file
Add handler diamagnetic as follows:
void Cmfcdlgdlg::onbnclickedbutton1 () { // TODO: Add control Notification Handler code CMyDlg dlg; defines the object of the Cmdlg class Dlg dlg. DoModal (); // Show dialog Box }
6. Adding controls in the Idd_compute_dialog dialog box
Add three edit box controls at a time, three static text controls, and a button control, as shown below
After adding the finished layout is as follows:
Modify the properties of the Statictext control and the button's property caption to display the following
7. Add member variables for Edit control controls
Select Edit Control, right-click, select Add Variable
Because the input is the price number, so the category selection value, variable type choose float, access is set to public, the name corresponds to M_price\m_number\m_total
When all settings are complete, open Cmydlg.h and you can see that the member variables are already included under the class.
And the member variables are already included in the Cmydlg.cpp.
This is all we do to add member variables, and if you find that you have errors in the process of adding member variables, you can delete the above. h and. cpp in the Red box section, reset, of course, you can also directly through the source code modification.
8. Add Control handler function
In this case, the processing function is relatively simple, double-clicking the calculation button into the control event function, and then adding the code as follows:
void Cmydlg::onbnclickedbutton1 () { // TODO: Add control Notification Handler code UpdateData (True ); = M_price * m_number; UpdateData (false);}
9. Add Control handler function
Choose Build-to-build solution, then click Debug-and start execution to get the following block diagram
Click Calculate to open the Calculate dialog box
Enter the price, quantity, click Calculate to get the total price.
Design a simple pricing program with MFC