Sun Xin VC ++ lecture notes-(3, 4)

Source: Internet
Author: User

Sun Xin VC ++ lecture notes-(3)-Introduction to the principle of MFC programming

 

To tell the truth, this lesson is only the embodiment of the content of the first lesson in the MFC programming. If you have learned a thorough understanding of the first lesson, you need to implement the MFC programming, at the same time, we need to have a clear sense of the entire process of MFC, as long as we have Sun The test program provided by the teacher is enough. Remember that all the breakpoints in the program have been set, so it is best not to delete a breakpoint at will, in the debugging process, I tried to figure out what each breakpoint was doing. Why? If you don't understand anything, let's take a closer look at the explanation of the video lecture about 23 minutes from the beginning of 1 hour to 20, which will help you understand the framework of MFC. If reading this is not enough, I suggest you take a look at Hou Jie's in-depth introduction to MFC.

Later in this section, we will focus on the process of creating and destroying windows in the framework and view categories of a Single-document program, as well as the relationship between windows and objects. Here, Sun The instructor introduced a button class and its usage, emphasizing the relationship between windows and objects. This is a blind spot for self-taught VC people like me.

 

Sun Xin VC ++ lecture notes-(4)

 

This lesson explains how to use the classwizard of MFC to help us create message ing and message response functions.

 

Next we will explain that DC is the context device. When using CDC, we usually need to create or obtain the DC device through getdc, and then release the DC Through releasedc, the corresponding other cclientdc and cwindowsdc do not need to perform this operation. When these DC objects are constructed, they are automatically releasedc when they are parsed by getdc. The difference between ccliendc and cwindowsdc is that cclientdc acquires the DC of the customer zone of the resource device. Its role is similar to that of CDC, and it uses the customer zone environment, cwindowsdc obtains the customer and non-customer areas (menu bar, border, and title bar) of the device ). Here, I will briefly introduce three DC types, namely, cpaintdc, memory DC, and printer DC. cpaintdc is a DC that can only respond to wm_paint messages, that is, after the DC is created, it does not work in other messages. The code written to cpaintdc only works when the window receives the wm_paint message. The memory DC is actually an instance of the CDC class, however, instead of using getdc to get the context of the resource device, the constructed DC uses the createcompatibledc () function of DC to set the context of the memory device. Obviously, it is not associated with any resources, memory DC is widely used in image rendering to overcome image flickering. Printer DC is also an example of CDC, it uses createdc to create the DC related to the printer driver and other information after the construction. Of course, the printer DC must be released with deletedc after use.

 

Introducing the process of DC, Sun The instructor demonstrated simple line-drawing programming, including cpen, cbrush, and other classes.

 

The last lecture Sun The instructor introduced static member variables and static member functions of the class by calling functions such as cbrush: fromhandle (hbrush) getstockobject (null_brush. Static members of a class only belong to the class code. In the memory model, if a class containing static members is included in the program code, when the program code is compiled, the code of the static member will be loaded in. Once the program runs, this part will be allocated in the memory. The corresponding non-static member, the Code belongs to the object. If the program code contains a class but the class does not instantiate any object, the code of some non-static members of the class will not be loaded during compilation, therefore, no space will be allocated to the code when the program is running.

Note: static member functions can only access static member variables. static member variables can only be initialized outside the class.

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.