Detailed analysis of C language MFC (3)

Source: Internet
Author: User

3. Use Wizard

Visual c ++

First, we will introduce

  • Click

Library for programming executable programs. For example

It is a powerful universal programming language. It provides various wizard and tools to help us implement the required functions, and to some extent, implements automatic generation and Visual Programming of the software. The following describes how to use the most important development tools in the VC integration environment. Appwizard tool, which helps us to generate a new application step by step and automatically generate the basic code required by the application. The following describes how to use Appwizard to generate an application. File menu new menu item. The dialog box popped up allows us to select the file type to be created. The files here are divided into four types: files, project, workspaces, and other documents, each type contains many specific file types. The projects tag is selected. The workspace under the tag lists different application types, such as dynamic link libraries of the DLL type, exe-type executable programs. Here, select the MFC Appwizard (exe) option to create a basic class 1.1 using MFC:

 

Figure

  • After the selection, set the program name to test in the project name column and define the directory where the program files are stored in the location column, the Win32 entry in the platforms column in the lower-right corner of the dialog box indicates that the program to be created is based on a 32-bit Windows platform. Click OK to start the Appwizard function for developing applications using MFC. Fig 1.2

  • Wizard allows us to select the program type and the language used by the program resources. Here we can select the program type as single document interface, the language is English, and then click Next.

     

    Figure 1.4 none. Figure 1.5 Support for Winsock. The default value of the system is not changed here, as shown in 1.6. Click Next.

     

     

    • Select the support for the composite document in the program.

     

     

    Fig 1.6

     

    • In step 5, select whether to automatically generate comments for the program in the upper part of the dialog box. In the lower part of the dialog box, select whether to use the MFC class library to dynamically link the library or static link, when dynamic link library is used, the executable applications generated later do not really contain the objects in the MFC class library, the code in the MFC Library is generated as part of the application, and the generated application is relatively larger. Select and click Next. 1.7

    Figure

    • 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

       

      • Click

       

      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.15

      In 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 applications

      I 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

    Figure

    Figure 1.3 shows whether to provide database support. Here, select none and click Next.

  • Then select other features of the program, such

1.1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.