C + + about the use of CMFCPropertyGridCtrl _c language

Source: Internet
Author: User
Tags instance method

Digression:

Recently in writing an important program, want to do more flexible, so want to take the form of a dialog box, as shown in the figure

But several major departments of the C + + and MFC books, there are many online data, this aspect of the introduction is very few. Fortunately, however, VS2013 is half open source. Haha, the code is not visible, but the function statement can be seen. This provides me with a good way to solve the problem, another online MSDN is also a good way to learn, however, the Chinese translation is not to compliment, it is called a rotten, basically do not understand what he said, can only chew English.

So, learning things is not easy, learned, must not forget to summarize, otherwise, after a period of time to forget, it is a pity.

Don't talk nonsense, the word is turning

One, about CMFCPropertyGridCtrl and CMFCPropertyGridProperty is a pair of good brothers, they call is to use together. Don't look at it wrong.

CMFCPropertyGridCtrl is a container containing several cmfcpropertygridproperty items. And CMFCPropertyGridProperty is the real project content.

and CMFCPropertyGridProperty magical Place is that he can be nested, one belongs to a set of attributes.

In my case, the black outer frame can be thought of as a CMFCPropertyGridCtrl container, and in my diagram I have added 5 top-level attributes. If "Overview" is the first top-level property, you can use the CMFCPropertyGridCtrl AddProperty () method: The Declaration of the method is as follows

int AddProperty (cmfcpropertygridproperty* pprop, bool Bredraw = true, bool Badjustlayout = TRUE);
Before joining this belong, you need to construct a property. Within this attribute, there are several two levels of "title" and "level" two belonging under "Overview", which belong to the large attribute "Overview".

So, after we declare a property, we want to add a child attribute to the attribute. The method is also quite simple, using the CMFCPropertyGridProperty instance method:

BOOL Addsubitem (cmfcpropertygridproperty* pprop);
The use of this belongs to the addition of other sub-attributes into the current attribute. Declare a declaration of how it belongs? Look at the following declaration function, it's clear at a glance

The group constructor Property
CMFCPropertyGridProperty (const cstring& strgroupname, Dword_ptr dwdata = 0, BOOL Bisvaluelist = FALSE);

The simple  property is used to generate properties for child attributes
CMFCPropertyGridProperty (const cstring& strName, const colevariant& Varvalue, LPCTSTR LPSZDESCR = null, dword_ptr dwdata = 0,
  lpctstr lpszeditmask = null, LPCTSTR lpszedittemplate = null , LPCTSTR lpszvalidchars = NULL);

There are two constructors, which are used to construct a new property. Here, these two constructors are different in function.

If you simply declare a schema, such as the top-level attribute "overview" on the above figure. This belongs to no attribute value, he is just a title. Declares a property that does not have a property value, with the first constructor. A property that declares a specific value uses the 2nd constructor.

Then it is possible to construct a CMFCPropertyGridCtrl.

Put a piece of code, first look at the process of constructing a property

CMFCPropertyGridCtrl m_wndproplist;
COleVariant var0;
Var0.intval = 0;
Var0. ChangeType (VT_I4);
cmfcpropertygridproperty* pGroup1 = new CMFCPropertyGridProperty (_t ("Overview"));
    Pgroup1->addsubitem (New CMFCPropertyGridProperty (_t ("title"), (_variant_t) _t ("Heading 1"), _t ("caption content to display in view"));
    Pgroup1->addsubitem (New CMFCPropertyGridProperty (_t ("level"), Var0, _t ("Level of current show Plan"));
M_wndproplist.addproperty (PGROUP1);

Let's briefly introduce the CMFCPropertyGridCtrl control today. Concrete details, we speak slowly from the second section.

Something to Add.

CMFCPropertyGridCtrl before you actually use it, you need to make some settings, which is generally very simple

  M_wndproplist.enableheaderctrl (FALSE);
  M_wndproplist.enabledescriptionarea ();
  M_wndproplist.setvsdotnetlook ();
  M_wndproplist.markmodifiedproperties ();

Here is the setting of whether to display the caption, whether to display the description area, whether or not to flag modify properties. I want to be smart with you, I can see it.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.