Principles of VC controls

Source: Internet
Author: User

Remember how to process controls in VB, so easy. First, draw a control in the window, then give it a name, and all the operations on the control in the Code are referenced through this name. For example, if you want to change some attributes of the control, you can call its attributes through this name and assign the expected values to the attributes. For another example, you need to use a method of the control, that is, name. xxx. That's it.

 

But what about VC? Is it that simple? Wrong, totally wrong. Everything here is hard to understand (of course, it is difficult to accept anything new when you are learning it, in your old stubborn mindset ). Controls in VC can be described into five parts: ID, control entity, control variable, attribute function, and message function.

 

The most important thing here is no longer the name, but the ID. The system identifies them through the ID of each control. Controls are similar to those in VB. They are all drawn on the form (at least on the surface ). The control variables are relatively obscure. In VB, We reference the control through name, but there is no such thing as name in VC. The relative importance is ID. However, can id be used directly, no! This is something Ms specifically designed to use for their systems (shit, just as a country's managers often decide the fate of the country through their own preferences, that's all. According to Ma Zhe's idea, the country will eventually die. The problem is that they can change the whole nation and even everyone in the nation through control of the whole country. This is intolerable! But what can we do ?), The system uses this ID to schedule everything related to space. How should I reference it? This is the control variable. At this time, the control variable is equivalent to the name in VB. When we reference a control through name in VB, name. propority is the most used, which allows us to conveniently set and change the properties of the control. Can this be done in VC? Different in VC. To protect member data, the attribute value here basically does not allow name. the property function -- name. setpropority () and name. getpropority () -- to set and obtain the corresponding properties of the control. This is the role of the control property function. There are also terrible message functions. The controls in VB provide many event functions, such as click and dblclick etc. These functions help us to respond to events such as click and double-click. They seem simple, but you do not know the truth. VC tries to let you understand these principles. It provides the message function and the message ing table. The message function is used to process messages, such as click. The message shadow table is used to indicate where the message (afxmsg) comes from (ID) And what function (afxmsg fun) is used for processing.

 

The above is the basic principle of the VC control, and is also a small part of the entire MFC framework. The technical details are vast, and many people are eager to learn from each other over the years (MS still won't let others learn, shit, keep a bunch of code to make money. Although I highly recommend MS technology, it is often the most advanced concept, after all, Ms brings together so many smart experts around the world), but it may not have been completed. I just started from the beginning. Although I followed the technology, I was not enthusiastic about it. The following is a further understanding of how to associate these five parts.

 

Controls: Object

Property function: setpropority () getpropority ()

Control ID: myid

Control variable: objname

Message: ws_click

Message function: onclick ()

 

Object is first associated with myid -- this is done when the control is created. After you draw the control entity, you will see that the ID of the control has been created in its property window.

 

Attribute function Association objname -- this is completed when the variable is declared. To declare a variable of any type, it is determined by the MFC framework class library.

Association between myid and objname -- a function is required to complete this process. This function is provided by MFC and implements data exchange between controls and variables.

Void class: dodataexchange (cdataexchange * PDX ){

Cdialog: dodataexchange (PDX );

// {Afx_data_map (class)

Ddx_control (PDX, myid, objname );

//} Afx_data_map

}

 

Ws_click is associated with onclick and myid-the message ing table. This table does look like a table. It lists messages, IDs, and message functions. We can also see that such a simple line is definitely not feasible. MS is the most clear about how it works, but no one can tell you. Of course you can find some disassembly tools to study them slowly (poor), but there are a lot of books that seem to tell you a part of the truth.

Begin_message_map (class, cdialog)

// {Afx_msg_map (class)

Ws_click (myid, onclick)

//} Afx_msg_map

End_message_map ()

This table is associated with messages, IDs, and message functions. It seems that they are not related to the inter-control entities. In fact, because the ID has been associated with the object and objname, the entire associated table has been created.

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.