VC learning notes

xiaoxiao2021-03-06  60

1. Password dialog

The process of creation of the program:

1 Create a framework and dialog;

2 Create a dialog box class with a dialog (CPasswordDLG, derived by cdialog). And add member variables for this dialog class (used to get the password content m_strpassword placed in the edit box;

3 Modify the constructor of the dialog box, assign the newly added dialog member variable;

4 Add a dialog header file (PasswordDlg.h) in the program main file password.cpp; and complete in the initialization function (cpasswordapp :: initInstance ()): Create a new dialog, call and display the dialog, add a business Logic - Get the user's input (password) and judge;

5 In the frame display file (ie password input successfully or enter the content of the frame to display, in this for passwordView), add a display screen (here, first add new string variables in header file passwordView.h Display the text you want to print, then add the code that displays these texts in PasswordView.cpp).

This section focus:

1 The entry point of the program is the CXXXXXAPP creation code in the program main file (here is the CPasswordApp THEAPP statement in the password.cpp file). Therefore, the creation of the dialog, calls and display is best located in the initial function in initial () function in CXXXXAPP.

2 Basic class structure: cxxxxapp is the business logic class of the program (the entry point of the program is here); cxxxxxdlg is the program's dialog class; CXXXXVIEW is the program's view class, that is, the frame interface to the user; CMAINFRAME is the program framework class.

3 The role of the CXXXXXDOC class? ? ?

2. Button, list box, and combo box

The process of creation of the program:

1 Create a project engineering, this example is a single document, and the view class is derived by CeditView;

2 Add a dialogue resource and add the various controls you need to the dialog box;

3 Create a dialog class class by "View | ClassWizard" (Normal Plus C) CREGISTER before the class is preceded, and add a message processing function to the respective controls in the dialog;

4 Continue to add member variables to each control in the dialog;

5 Add a public variable CWnd * m_pparent to the header file (cregisterdlg.h) of the dialog box to indicate the parent window of the dialog; then in the initialization function on the dialog box is "department" list Box add content; then assign initial values ​​for the respective controls of the dialog in the constructor of the dialog, and specify the parent window of the dialog box is the main frame window of the project; the message processing function of the "Enter" button in the dialog button ONIN () Add business logic, including read and determine the user's input, display the user's input, etc.

6 Add a menu item in the frame window to call the call to call the dialog, similar to the previous, and modify the message processing function to meet the requirements.

This section focus:

The first class name is generally plus a capital C (such as cxxxdlg), and the file name is not used; 2 When the corresponding member variable and message processing function adds the control, which control is increased (Is it the menu of the framework? Or dialog box; if the class of the control does not exist, you need to create such a class first, this step can be done through "View | ClassWizard" to complete the class wizard. The steps to increase the corresponding member variables and message processing functions for: Select the item, select the class, select the message name (my understanding, the object ID), and select the message processing function (my understanding, messages). After completing these steps, you can see the result of the added results in the Member Function. Finally, the user can modify the corresponding functions of the corresponding class (ie, message processing functions) to meet the needs of users.

3 Mode dialog box: CREGISTERDLG DLG (this); DLG.Domodal (); note, THIS indicates that the parent window of this dialog is the framework of the project; Domodal () is a function specifically used to start the dialog;

4 Note that the return value of the initInstance () function of the CXXXXAPP class is a Boolean value, (Bool Cgujianapp :: InitInstance ()), so only when cxxxxapp :: InitInstance () return value is true (of course, the startup of the frame must also be correct) In order to display the framework of the program normally, it will not. As for the first dialog or the main frame, you have to see whether the dialog is started before, or the display of the frame is before.

3. Find, replace dialog

The process of creation of the program:

1 Create a main framework of the project;

2 Create a non-Mode dialog resource, that is, "Find and Replace dialog box". The control required for business logic is the dialog control, and the dialog is responsible for receiving the search editing box and replacement editing box for the user input;

3 Create a class associated with the above three controls, here as the CREPLACEDLG class; and variables associated with two editing boxes: cstring type m_strfind and m_strreplace, and increase the corresponding default message processing function;

4 Increment in the menu resource to start the menu option to start this search replacement box, and add the user-defined message processing function of this menu (note that the message processing function is in the CXXXXVIEW class);

5 Complete this lookup and replacement dialog object: first to clarify this dialog box is started by the CXXXXXVIEW class (menu item), and complete the initialization of the dialog box in the CXXXXXVIEW class Work (step 7) and the message processing function of the response menu item (step 8);

6 Add a CREPLACEDLG * type member variable DLG for the CXXXXXVIEW class to point to this dialog;

7 State two classes in the XXXXXView.h header file: Class Creplacedlg; Class Creplacedoc; In XXXXView.cpp, first add header filedlg.h: #include "replacedlg.h", and give it in the constructor of the CXXXXVIEW class Step 5 The new member variable defined in the first value of NULL; 8 Modify the custom message processing function in step 4: Decision has such a dialog, if already existing, activate (DLG-> setActiveWindow (); Otherwise, first create (DLG = New CREPLACEDLG (this); DLG-> CREATE (THIS), then display this dialog (DLG-> ShowWindow);

9 Finally Write the Complete Finding Dialog Box object, including business logic: Modify the default message processing function added in step 3, add a member variable for the CREPLACEDLG class to point to the parent window, and then change Creplacedlg Oncancel () functions, onok () functions, and postncdestroy () functions in the class. Note To complete the task of saving and closing the dialog pointer and closing the dialog window in the oncance () function, delete the dialog object in the PostNCDESTROY () function, completing the business logic in the onok () function.

This section focus:

1 Creation and destruction of the Non-Mode dialog: Creplacedlg * DLG = New Creplacedlg (this); DLG-> Create (Idd_replace, this); dlg-> showwindow (sw_show); Destruction work includes dialog box pointing, shut down and delete Dialog window.

4. Progress strip and slide

The process of creation of the program:

1

This section focus:

1 Create a user-default default file save format: In the StringTab resource directory, double-click Open, modify IDD_MAINFRAME, change to: xxx / n / nxxx / n file format Description /N.XX/nxxx.document/nxxxxxxx.Document/nxxx document, where, File format Description Users for the user's instructions and annotations for the default file format, .xx is a user-defined file format, and the rest remains unchanged.

转载请注明原文地址:https://www.9cbs.com/read-112585.html

New Post(0)