Enter the last step of Appwizard. The prompt information in the dialog box indicates the objects and related files to be automatically created by the system, as well as the base class of the MFC derived from these objects. In this step, you can also select the base class of the View class and click Finish. 1.8
Figure
OK button. The system automatically generates a basic framework for the application that uses the basic MFC class library. The content of this framework will be described in detail later. 1.9
Next we will introduce classwizard, a very important tool provided in the VC integration environment, which is mainly used to manage objects and messages in programs. This tool is especially important for MFC programming. Click the classwizard item in the View menu to run the MFC classwizard. In this dialog box, you can manage the objects and messages in the program. 1.10
Figure
Under the message maps tab in the dialog box, the content in the project column represents the name of the current program.ClassnameThe drop-down list lists the names of all classes currently used by the program.,InMessageThe column lists all messages that can be received by a selected class.In Windows program design, messages are an extremely important concept. The user finally converts various operations on the window interface to various messages sent to objects in the program, the following describes some of the most common messages in Windows programming:Window message: wm_create, wm_destroy, wm_close
When we create a window object, what this window object receives during creation is
Wm_create message. The process of processing this message is generally used to set initialization before the display window, such as setting the window size and background color. The wm_destroy message indicates that the window is about to be withdrawn, in this message processing process, we can do some work before window undo. The wm_close message occurs before the window is closed. After receiving the message, the general operation is to recycle all resources allocated to the window. Resources in windows are very limited, so it is very important to recycle resources.
2
Keyboard Message: wm_char, wm_keydown, wm_keyup
These three messages are used to process users' keyboard data. When a user presses a key on the keyboard
The wm_keydown message is generated again when the button is released. Therefore, messages of wm_keydown and wm_keyup are always paired, the wm_char message occurs only when the user's keyboard input can generate valid ascii code. Note that the use of the first two messages is different from that of the wm_char message. In the first two messages, the virtual key code of the key is transmitted along with the message. Therefore, the two messages can process non-printable characters, such as direction keys and function keys. The parameters that accompany the wm_char message are the ASCII code of the key, and the ASCII code can be case-sensitive. The virtual key code cannot be case sensitive.
3
Mouse message: wm_mousemove, wm_lbuttondown, wm_lbuttonup, wm_lbuttondbclick, wm_rbuttondown, wm_rbuttonup, wm_rbuttondbclick
This group of messages is related to mouse input,
When the wm_mousemove message moves the mouse, the remaining six messages correspond to the press, release, and double-click events of the left and right mouse keys, respectively, note that the windows system does not produce the mousemove message every time the mouse moves a pixel.
4
Another set of window messages: wm_move, wm_size, and wm_paint: wm_move messages are generated when the window moves, and wm_size messages are generated when the window size changes, the wm_paint message is generated when the content in the window workspace needs to be re-painted.
5
Focus message wm_setfocus, wm_killfocus
When a window changes from inactive to active with input focus, it will receive
Wm_setfocus message. When the window loses the input focus, it receives the wm_killfocus message.
6
Timer message: wm_timer
After a timer resource is set for a window, the system will send the timer resource to the window at the specified interval.
In the end
As described above
Click
Wm_timer message, in which you can process things that need to be processed regularly. In Windows, messages come from multiple sources. The most common is that user operations generate messages, and the system sends system messages to programs when necessary, other running programs can also send messages to the program. In addition, you can actively generate messages as needed within the program. For example, you can actively generate the wm_paint message to implement the required re-painting function. The main messages in the message column are listed in the member function column as member functions of the currently selected class. These member functions are generally one-to-one correspondence with messages that can be received by this class. That is to say, a member function is generally used to process a specific message. If a message in the message column needs to be processed in the program, but no class member function is available yet, for example, the message wm_timer is selected here, at present, it does not have the corresponding class member function. Add function button, Figure 1.11
The system automatically
Note:
Click and select
Figure
The corresponding ontimer member function is added to the wm_timer message in the class. Click the editcode button to find that the system has automatically generated the basic code required to complete the ontimer function, we only need to add the required Code on the basis of the basic code. Add class button, which adds a new class to and from the current application. New, 1.12
System pop-up
Figure
Class Wizard
Finally, we will introduce an important tool provided by the integrated environment.
Click
The new class dialog box is used to generate a new class. In this dialog box, you must set a class name and the class file name. In addition, You must select an existing class as the base class in the drop-down list box in the base class column, after setting the required information, click OK to generate a new class. 1.13 There are some very powerful functions. I will not introduce them in detail here. You will learn more and learn more. The resoucr editor is the resource editor. A large number of bitmap, menu, toolbar, dialog box and other resources are used in VC-developed applications. These resources are relatively independent for the program, so they can be edited separately and then used in the program. The resouce Editor provides a visual development method for editing resources. This greatly reduces the burden on programmers. File menu, and then select open test. RC file in the dialog box to start using the resource editor. In the work area on the left, all resources used in the program are listed by type. Double-click a type, for example, double-click the menu resource, the menu directory lists the existing menu resources of the system. select one of the resources and double-click the resources to list the current status of the resource in the workspace on the right, we can visually edit and modify Resources in the workspace. Fig 1.14
How to add a resource? Click
Figure
Insert menu: select the resource menu. The insert resource dialog box is displayed. 1.15. 1.15In the Graph
Based on the introduction of this part, we believe that you have
Figure
1.15 In this dialog box, select a resource type, for example, select the cursor type, and then click the new button. The identifier of the newly generated resource is displayed in the workspace on the left. Double-click the identifier to visually edit the new pointer shape resource in the workspace on the right. 1.16. Visual c ++ develops 1.16 of the MFC applicationsI have some knowledge about the basic steps. In the next chapter, we will combine
The working principle of Windows explains in detail the basic structure of the MFC class library and the basic framework of the MFC Application-document/view structure.
1