[英]How does the MFC PropertyGrid control work in the dialog editor in visual studio?
In the visual studio dialog editor i can add a MFC Property Grid control to the dailog.在 Visual Studio 对话框编辑器中,我可以将 MFC 属性网格控件添加到 dailog。 How can i customize its content, and set options like allowing the user to edit the contents of it when the program using it is running, or how i can change the contents of it using c++?
我如何自定义它的内容,并设置选项,例如允许用户在使用它的程序运行时编辑它的内容,或者我如何使用 C++ 更改它的内容? When i add something like a button or and edit control it displays on the dailog box when the program is running, while when i add a MFC Property Grid the dailog isnt even being displayed.
当我添加按钮或编辑控件之类的东西时,它会在程序运行时显示在 dailog 框中,而当我添加 MFC 属性网格时,dailog 甚至没有显示。
Here is a picture of the visual studio dialog editor and a MFC property control grid in the middle of the dailog with contents i dont know how to change.这是一个 Visual Studio 对话框编辑器的图片和一个位于 dailog 中间的 MFC 属性控件网格,其中包含我不知道如何更改的内容。
Simple tutorial of CMFCPropertyGridCtrl: CMFCPropertyGridCtrl 简单教程:
1.Create a dialog-based MFC project, drag a CMFCPropertyGridCtrl into it, and adjust the size. 1.创建一个基于对话框的MFC项目,拖一个CMFCPropertyGridCtrl进去,调整大小。 Then change the ID for the control to IDC_MFCPROPERTYGRID_TEST, and use Add Varible to add a variable m_propertyGrid to the control.
然后将控件的 ID 更改为 IDC_MFCPROPERTYGRID_TEST,并使用 Add Varible 向控件添加变量 m_propertyGrid。 Change the setting of Notify to
True
.将 Notify 的设置更改为
True
。
Description Rows Count refers
to the number of rows in the description section below. Description Rows Count refers
下面描述部分中的行数。
Enable Description Area
indicates whether to enable the following description function. Enable Description Area
指示是否启用以下描述功能。
Enable Header
indicates whether to start the header. Enable Header
表示是否启动头部。
Mark Modified Properties
indicates whether to highlight the changes. Mark Modified Properties
指示是否突出显示更改。
2.Set interface Add the following code in OnInitDialog()
2.设置接口在
OnInitDialog()
添加如下代码
HDITEM item;
item.cxy=120;
item.mask=HDI_WIDTH;
m_propertyGrid.GetHeaderCtrl().SetItem(0, new HDITEM(item));
Add the following code in OnInitDialog()
在
OnInitDialog()
添加以下代码
CMFCPropertyGridProperty* pProp2 = new CMFCPropertyGridProperty(
_T("choose"),
_T("select"),
_T(""));
pProp2->AddOption(_T("1"));
pProp2->AddOption(_T("2"));
pProp2->AddOption(_T("3"));
pProp2->AllowEdit(FALSE); //Editing of options is not allowed
m_propertyGrid.AddProperty(pProp2);
The three parameters passed in when calling the constructor are item name
, default options
and description text
.调用构造函数时传入的三个参数是
item name
、 default options
和description text
。
Also, you could add drop-down menu:此外,您可以添加下拉菜单:
CMFCPropertyGridProperty* pProp2 = new CMFCPropertyGridProperty(
_T("choose"),
_T("select"),
_T(""));
pProp2->AddOption(_T("1"));
pProp2->AddOption(_T("2"));
pProp2->AddOption(_T("3"));
pProp2->AllowEdit(FALSE); //Editing of options is not allowed
m_propertyGrid.AddProperty(pProp2);
In addition, there are three similar projects:此外,还有三个类似的项目:
CMFCPropertyGridColorProperty * pProp3 = new CMFCPropertyGridColorProperty(
_T("colour"), RGB(0, 111, 200));
m_propertyGrid.AddProperty(pProp3);
CMFCPropertyGridFileProperty * pProp4 = new CMFCPropertyGridFileProperty(
_T("open file"), TRUE, _T("D:\\test.txt"));
m_propertyGrid.AddProperty(pProp4);
LOGFONT font = { NULL };
CMFCPropertyGridFontProperty * pProp5 = new CMFCPropertyGridFontProperty(
_T("select font"), font);
m_propertyGrid.AddProperty(pProp5);
Finally, This is the final program running interface:最后,这是最终的程序运行界面:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.