??xml version="1.0" encoding="utf-8" standalone="yes"?>
|上好多关于tinyxml的文看了好多L觉得比较ȝQ所以决定自己写一个类来封装它
q个cd装的不是很全面,但已l基本够我用了Q有兴趣的朋友可以再l箋完善他,
让不懂xml内部原理的朋友们也可以方便用xml格式文g存储数据
q是试目Qvc71版本Q我喜欢?003Q哈?br>/Files/hwawai/CXML_vc71.7z
如果大家有什么更好的代码来处理xml希望t跃交流
头文?br>#pragma once
#include<string>
#include "tinyxml.h"
using namespace std;
class CXML
{
public:
CXML(void);
~CXML(void);
bool ParseXmlFile(const char* xmlFile);
TiXmlElement* GetElement(const char* parentTitle,const char* title);//此函数需一层一层递进
bool getElementAttributeValue(TiXmlElement* Element,const char* AttributeName,string& reslut);
bool getFirstElementValue(const char* title,string& result);
bool getNextElementValue(const char* title,string& result);
TiXmlElement* getRootElement();
void Clear();
//////////////////////////////////////////////////////////////////////////
TiXmlElement* addXmlRootElement(const char* title);
TiXmlElement* addXmlChildElement(TiXmlElement* pElement,const char* title);
void addXmlAttribute(TiXmlElement* pElement,const char* name,const char* value);
void addXmlDeclaration(const char* vesion="1.0",const char* encoding="gb2312",const char* standalone="");
void addElementValue(TiXmlElement* pElement,const char* value);
void addXmlComment(TiXmlElement* pElement,const char* Comment);
void saveFile(const char* file);
protected:
TiXmlDocument m_xml;
TiXmlElement* pElement; // 获取NextElementValue使用,属时变?br> TiXmlElement* getFirstElement(const char* ElementMark,TiXmlElement* pcrElement);
};
源文?br>#include "StdAfx.h"
#include ".\xml.h"
CXML::CXML(void)
{
}
CXML::~CXML(void)
{
}
bool CXML::ParseXmlFile(const char* xmlFile)
{
return m_xml.LoadFile(xmlFile)?1:0;
}
TiXmlElement* CXML::GetElement(const char* parentTitle,const char* title)
{
TiXmlNode* _=m_xml.FirstChildElement(parentTitle);
for(_=_->FirstChild();_;_=_->NextSibling())
{
if (!strcmp(title,_->Value()))
{
return _->ToElement();
}
}
return 0;
}
bool CXML::getElementAttributeValue(TiXmlElement* Element,const char* AttributeName,string& reslut)
{
if(Element->Attribute(AttributeName))
{
reslut=Element->Attribute(AttributeName);
return 1;
}
return 0;
}
bool CXML::getFirstElementValue(const char* title,string& result)
{
if(!title)
return 0;
TiXmlElement* _(0);
_=m_xml.RootElement();
_=getFirstElement(title,_);
if(_)
{
pElement=_;
result=pElement->GetText();
return 1;
}
return 0;
}
bool CXML::getNextElementValue(const char* title,string& result)
{
result="";
pElement=pElement->NextSiblingElement(title);
if(pElement)
{
result=pElement->GetText();
return 1;
}
return 0;
}
TiXmlElement* CXML::getRootElement()
{
return m_xml.RootElement();
}
void CXML::Clear()
{
m_xml.Clear();
}
//////////////////////////////////////////////////////////////////////////
TiXmlElement* CXML::addXmlRootElement(const char* title)
{
TiXmlElement* _=new TiXmlElement(title);
m_xml.LinkEndChild(_);
return _;
}
TiXmlElement* CXML::addXmlChildElement(TiXmlElement* pElement,const char* title)
{
if(pElement)
{
TiXmlElement* _=new TiXmlElement(title);
pElement->LinkEndChild(_);
return _;
}
return 0;
}
void CXML::addXmlAttribute(TiXmlElement* pElement,const char* name,const char* value)
{
if(pElement)
{
pElement->SetAttribute(name,value);
}
}
void CXML::addXmlDeclaration(const char* vesion,const char* encoding,const char* standalone)
{
TiXmlDeclaration *_=new TiXmlDeclaration(vesion,encoding,standalone);
m_xml.LinkEndChild(_);
}
void CXML::addElementValue(TiXmlElement *pElement,const char* value)
{
if(pElement)
{
TiXmlText *_=new TiXmlText(value);
pElement->LinkEndChild(_);
}
}
void CXML::addXmlComment(TiXmlElement* pElement,const char* Comment)
{
if(pElement)
{
TiXmlComment *_=new TiXmlComment(Comment);
pElement->LinkEndChild(_);
}
}
void CXML::saveFile(const char* file)
{
m_xml.SaveFile(file);
}
//////////////////////////////////////////////////////////////////////////
TiXmlElement* CXML::getFirstElement(const char* ElementMark,TiXmlElement* pcrElement)
{
TiXmlElement* _=pcrElement;
while(_)
{
if(strcmp(_->Value(),ElementMark)==0)
{
//printf("%s\r\n",pElementtmp->Value());
return _;
}
else
{
TiXmlElement* nextElement=_->FirstChildElement();
while(nextElement)
{
//printf("%s\r\n",nextElement->Value());
if(strcmp(nextElement->Value(),ElementMark)==0)
{
return nextElement;
}
else
{
TiXmlElement* reElement=NULL;
reElement=getFirstElement(ElementMark,nextElement);
if(reElement)
{
return reElement;
}
}
nextElement=nextElement->NextSiblingElement();
}
}
_=_->NextSiblingElement();
}
return NULL;
}
stdafx文g
#pragma once
#include <iostream>
#include <tchar.h>
用来试的主cpp文g
#include "stdafx.h"
#include "tinyxml//XML.h"
#include <iostream>
void createXML()
{
CXML xml;
xml.addXmlDeclaration("1.0","gb2312","");
TiXmlElement* root=xml.addXmlRootElement("fields");
TiXmlElement* pElement=xml.addXmlChildElement(root,"pos");
xml.addXmlAttribute(pElement,"x","100");
xml.addXmlAttribute(pElement,"y","200.1");
xml.addXmlAttribute(pElement,"z","0.123");
TiXmlElement* pElement2=xml.addXmlChildElement(root,"dest");
xml.addXmlAttribute(pElement2,"x","一二三");
xml.addXmlAttribute(pElement2,"y","一?);
xml.addXmlAttribute(pElement2,"z","一");
xml.saveFile("1.xml");
}
void CreateXML1()
{
CXML xml;
xml.addXmlDeclaration();
TiXmlElement* root=xml.addXmlRootElement("fields");
xml.addXmlComment(root,"AAAAAAA");
TiXmlElement* pElement=xml.addXmlChildElement(root,"pos_x");
xml.addElementValue(pElement,"1.3");
pElement=xml.addXmlChildElement(root,"pos_x");
xml.addElementValue(pElement,"30.1");
pElement=xml.addXmlChildElement(root,"pos_x");
xml.addElementValue(pElement,"30ssss.1");
xml.saveFile("2.xml");
}
void LoadXML()
{
CXML xml;
xml.ParseXmlFile("1.xml");
string a;
TiXmlElement* pElement=xml.GetElement("fields","dest");
xml.getElementAttributeValue(pElement,"x",a);
cout<<a<<endl;
xml.getElementAttributeValue(pElement,"y",a);
cout<<a<<endl;
xml.getElementAttributeValue(pElement,"z",a);
cout<<a<<endl;
}
void LoadXML1()
{
CXML xml;
xml.ParseXmlFile("2.xml");
string a;
xml.getFirstElementValue("pos_x",a);
cout<<a<<endl;
xml.getNextElementValue("pos_x",a);
cout<<a<<endl;
xml.getNextElementValue("pos_x",a);
cout<<a<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
// createXML();
// LoadXML();
CreateXML1();
LoadXML1();
getchar();
return 0;
}
生成的xml文g
1.xml
<?xml version="1.0" encoding="gb2312" ?>
<fields>
<pos x="100" y="200.1" z="0.123" />
<dest x="一二三" y="一? z="一" />
</fields>
2.xml
<?xml version="1.0" encoding="gb2312" ?>
<fields>
<!--AAAAAAA-->
<pos_x>1.3</pos_x>
<pos_x>30.1</pos_x>
<pos_x>30ssss.1</pos_x>
</fields>
q是Ҏ原代码例子改的中文版界面,主要是在OnInitDialog里面的代码我都写了注?有兴大家一LI一?/p>
BOOL CPropGridDlg::OnInitDialog()
{
// CDialog::OnInitDialog();
CPropertyGridDlgBase::OnInitDialog();
// \“关于...\”菜单Ҏ加到pȝ菜单中?/p>
// IDM_ABOUTBOX 必须在系l命令范围内?br> ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 讄此对话框的图标。当应用E序ȝ口不是对话框Ӟ框架自?br> // 执行此操?br> SetIcon(m_hIcon, TRUE); // 讄大图?br> SetIcon(m_hIcon, FALSE); // 讄图?/p>
// TODO: 在此d额外的初始化代码
//////////////////////////////////////////////////////////////////////////
// 获得囄框矩?br> CRect rc;
m_wndPlaceHolder.GetWindowRect( &rc );
// 转ؓH口坐标
ScreenToClient( &rc );
// 建立属性表
if ( m_wndPropertyGrid.Create( rc, this, IDC_PROPERTY_GRID ) )
{
m_wndPropertyGrid.SetVariableItemsHeight(TRUE);
// 获取逻辑字体
LOGFONT lf;
GetFont()->GetLogFont( &lf );
// create document settings category.
// 建立分类
CXTPPropertyGridItem* pSettings = m_wndPropertyGrid.AddCategory(_T("Document Settings"));
// 讄TOOLTIP
pSettings->SetTooltip(_T("Document Settings Category"));
// add child items to category.
// 建立bool内容
CXTPPropertyGridItem* pItemSaveOnClose = pSettings->AddChildItem(new CXTPPropertyGridItemBool(_T("SaveOnClose"), TRUE));
// 建立字体内容
pSettings->AddChildItem(new CXTPPropertyGridItemFont(_T("WindowFont"), lf));
// 建立size内容
pSettings->AddChildItem(new CXTPPropertyGridItemSize(_T("WindowSize"), CSize(100, 100)));
// 展开
pSettings->Expand();
// 选择
pItemSaveOnClose->Select();
// create global settings category.
// 建立分类
CXTPPropertyGridItem* pGlobals = m_wndPropertyGrid.AddCategory(_T("Global Settings"));
// add child items to category.
// 建立只读字符串内?br> CXTPPropertyGridItem* pItemGreeting = pGlobals->AddChildItem(new CXTPPropertyGridItem(_T("Greeting Text"), _T("Welcome to your application!")));
pItemGreeting->SetReadOnly(TRUE);
// 建立整数内容
pGlobals->AddChildItem(new CXTPPropertyGridItemNumber(_T("ItemsInMRUList"), 4));
// 讄说明
CXTPPropertyGridItem* pItemRate = pGlobals->AddChildItem(new CXTPPropertyGridItemNumber(_T("MaxRepeatRate"), 10));
pItemRate->SetDescription(_T("The rate in milliseconds that the text will repeat."));
// 建立color内容
pGlobals->AddChildItem(new CXTPPropertyGridItemColor(_T("ToolbarColor"), RGB(255, 192,128)));
//////////////////////////////////////////////////////////////////////////
// Version category.
// 建立分类
CXTPPropertyGridItem* pVersion = m_wndPropertyGrid.AddCategory(_T("Version"));
// add child items to category.
// 建立只读字符串内?br> CXTPPropertyGridItem* pItemVersion = pVersion->AddChildItem(new CXTPPropertyGridItem(_T("AppVersion"), _T("1.0")));
pItemVersion->SetReadOnly(TRUE);
// 使用资源建立字符串内?br> CXTPPropertyGridItem* pItemLanguage = pVersion->AddChildItem(new CXTPPropertyGridItem(ID_ITEM_VERSION_LANGUAGE, _T("English (United States)")));
// 展开分类
pVersion->Expand();
// comboq接到字W串内容?br> // 试l果 只要不是只读的字W串内容可q接combo 步骤如下
// 获取item的Constraints
CXTPPropertyGridItemConstraints* pList = pItemLanguage->GetConstraints();
// dcombo内容
pList->AddConstraint(_T("Neutral"));
pList->AddConstraint(_T("Arabic"));
pList->AddConstraint(_T("German"));
pList->AddConstraint(_T("Chinese(Taiwan)"));
pList->AddConstraint(_T("English (United Kingdom)"));
pList->AddConstraint(_T("English (United States)"));
pList->AddConstraint(_T("France"));
pList->AddConstraint(_T("Russian"));
pList->AddConstraint(_T("体中?));
pList->AddConstraint(_T("英文"));
pList->AddConstraint(_T("日文"));
// 讄combo为可~辑l合?br> pItemLanguage->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
//////////////////////////////////////////////////////////////////////////
// Dynamic Options
// 建立分类
CXTPPropertyGridItem* pCategoryDynamic = m_wndPropertyGrid.AddCategory(_T("Dynamic Options"));
// 建立bool内容
// q是W?U方?nbsp;强制转换指针方式
CXTPPropertyGridItemBool* pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
new CXTPPropertyGridItemBool(_T("Advanced"), FALSE));
// 讄ID
pItemBool->SetID(501);
// 讄checkbox样式
pItemBool->SetCheckBoxStyle();
// 建立bool内容checkbox样式q?br> pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
new CXTPPropertyGridItemBool(_T("Option 1"), FALSE));
pItemBool->SetHidden(TRUE);
pItemBool->SetCheckBoxStyle();
// 建立bool内容checkbox样式q?br> pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
new CXTPPropertyGridItemBool(_T("Option 2"), FALSE));
pItemBool->SetHidden(TRUE);
pItemBool->SetCheckBoxStyle();
// 建立bool内容checkbox样式q?br> pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
new CXTPPropertyGridItemBool(_T("Option 3"), FALSE));
pItemBool->SetHidden(TRUE);
pItemBool->SetCheckBoxStyle();
// 建立bool内容checkbox样式q藏和只读
pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
new CXTPPropertyGridItemBool(_T("Option 4"), TRUE));
pItemBool->SetHidden(TRUE);
pItemBool->SetCheckBoxStyle();
pItemBool->SetReadOnly();
// create standard items category.
// 建立分类
CXTPPropertyGridItem* pStandard = m_wndPropertyGrid.AddCategory(_T("Standard Items"));
// 建立字符串内?br> pStandard->AddChildItem(new CXTPPropertyGridItem(_T("String item")));
// 建立多行字符串下拉框 帮助文g中没?br> pStandard->AddChildItem(new CXTPPropertyGridItemMultilineString(_T("Multiline String item"), _T("1\r\n2")));
// 建立整数内容
pStandard->AddChildItem(new CXTPPropertyGridItemNumber(_T("Integer item")));
// 建立double内容q设|初始值和数据格式
pStandard->AddChildItem(new CXTPPropertyGridItemDouble(_T("Double item"),0,"%0.3f"));
// 建立颜色bool字体
pStandard->AddChildItem(new CXTPPropertyGridItemColor(_T("Color item")));
pStandard->AddChildItem(new CXTPPropertyGridItemBool(_T("Bool item")));
pStandard->AddChildItem(new CXTPPropertyGridItemFont(_T("Font item"), lf));
// mfc旉cCOleDateTime
COleDateTime dates(1981, 1, 26, 0, 0, 0 );
// 使用COleDateTime建立旉内容
pStandard->AddChildItem(new CXTPPropertyGridItemDate(_T("Date item"), dates));
// 建立size内容
pStandard->AddChildItem(new CXTPPropertyGridItemSize(_T("Size item")));
// 建立enum内容
CXTPPropertyGridItem* pItem = pStandard->AddChildItem(new CXTPPropertyGridItemEnum(_T("Enum item"), 1));
// denum记录到enum内容呈combo样式
pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 1);
pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 2);
pItem->GetConstraints()->AddConstraint(_T("Windows XP"), 3);
// 建立flag内容 W?个参?1+2"为初始?nbsp;?Windows 98"?Windows 2000"为真
// 且flag的元素数值需?,2,4,8,16,32...
pItem = pStandard->AddChildItem(new CXTPPropertyGridItemFlags(_T("Flag item"), 1 + 2));
pItem->GetConstraints()->AddConstraint(_T("All Windows"), 1 + 2 + 4);
pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 1);
pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 2);
pItem->GetConstraints()->AddConstraint(_T("Windows XP"), 4);
//////////////////////////////////////////////////////////////////////////
// 建立分类
CXTPPropertyGridItem* pButtons = m_wndPropertyGrid.AddCategory(_T("Standard Buttons"));
// 建立bool内容
pItem = pButtons->AddChildItem(new CXTPPropertyGridItemBool(_T("Combo Button")));
// 讄为combo样式
pItem->SetFlags(xtpGridItemHasComboButton);
// 建立字符串内?br> pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Expand Button")));
// 讄为可~辑q带有扩展按钮样?br> pItem->SetFlags(xtpGridItemHasEdit | xtpGridItemHasExpandButton);
// 建立字符串内?br> pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("2 Buttons")));
// 讄ID
pItem->SetID(510);
// 讄为可~辑q带有扩展按钮样式和combo
pItem->SetFlags(xtpGridItemHasEdit | xtpGridItemHasComboButton | xtpGridItemHasExpandButton);
// dcombo内容
pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 1);
pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 2);
// 建立字符串内?br> pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Text Button")));
// d按钮到字W串内容行尾
CXTPPropertyGridInplaceButton* pButton = pItem->GetInplaceButtons()->AddButton(new CXTPPropertyGridInplaceButton(1));
// 讄按钮文本
pButton->SetCaption(_T("Find"));
// 讄按钮宽度
pButton->SetWidth(100);
// 建立字符串内?br> pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Image Button")));
// d按钮到字W串内容行尾
pButton = pItem->GetInplaceButtons()->AddButton(new CXTPPropertyGridInplaceButton(1));
// 讄按钮图标索引
pButton->SetIconIndex(100);
// UINT数组 估计是一个时存储单元用于添加图标到按钮
// 上面?00和下面的100以及讄图标语句中的btnFilter是相联系?br> UINT btnFilter[] = {100};
// 讄图标
m_wndPropertyGrid.GetImageManager()->SetIcons(IDB_BITMAP_FILTER, btnFilter, 1, 0);
// 讄ToolTip在图标上
pButton->SetTooltip(_T("Set Filter for item"));
// 建立整Ş内容
pItem = pButtons->AddChildItem(new CXTPPropertyGridItemNumber(_T("Spin And Slider"), 60));
// 默认0-100暂时没有扑ֈ讄范围的方?br> // d水^滑块q接到整形内?br> pItem->AddSliderControl();
// d上下按钮q接到整形内?br> pItem->AddSpinButton();
//////////////////////////////////////////////////////////////////////////
// 建立分类
CXTPPropertyGridItem* pMetrics = m_wndPropertyGrid.AddCategory(_T("Custom Metrics"));
// 建立字符串内?br> pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("Value Colors"), _T("")));
// 讄文字颜色 可以采用RGB宏或DWORD
// 文字和背景颜色会呈现混合效果
pItem->GetValueMetrics()->m_clrFore = 0x00ff00;
// 讄背景颜色
pItem->GetValueMetrics()->m_clrBack = RGB(255, 0, 255);
// 建立字符串内?br> pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("Caption Colors"), _T("")));
// 讄文字颜色
pItem->GetCaptionMetrics()->m_clrFore = 0xFF0000;
// 讄背景颜色
pItem->GetCaptionMetrics()->m_clrBack = RGB(235, 235, 235);
// 建立enum内容
pItem = pMetrics->AddChildItem(new CXTPPropertyGridItemEnum(_T("Images"), 2));
// 内加enum记录q带有图?br> pItem->GetConstraints()->AddConstraint(_T("Green"), 0, 0);
pItem->GetConstraints()->AddConstraint(_T("Red"), 1, 1);
pItem->GetConstraints()->AddConstraint(_T("Yellow"), 2, 2);
pItem->GetConstraints()->AddConstraint(_T("Blue"), 3, 3);
// 讄enum内容的内容图?br> pItem->GetValueMetrics()->m_nImage = 2;
// 讄enum内容的标题图?br> pItem->GetCaptionMetrics()->m_nImage = 4;
// 讄mask颜色
m_wndPropertyGrid.GetImageManager()->SetMaskColor(0xC0C0C0);
// 讄图标
m_wndPropertyGrid.GetImageManager()->SetIcons(IDB_BITMAP_CONSTRAINTS, 0, 5, CSize(20, 14));
// 建立字符串内?br> pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("Variable Height"), _T("Item")));
// 建立内容块高?br> pItem->SetHeight(32);
// 讄为combo样式
pItem->SetFlags(xtpGridItemHasComboButton);
// 建立多行字符串内?br> // 貌似在多行中无法真正的多行编?没有扑ֈ让文本换行即支持文本回R的方?br> pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("MultiLine"), _T("Codejock Software\r\n428 Corunna Avenue\r\nOwosso, Michigan 48867 USA")));
// 讄能见得文本行?br> pItem->SetMultiLinesCount(3);
// create custom items category.
// 建立分类
// 以下定义cd 代码见CustomItems.h
CXTPPropertyGridItem* pCustom = m_wndPropertyGrid.AddCategory(_T("Custom Items"));
// add child items to category.
// 建立icon内容
CXTPPropertyGridItem* pItemIcon = pCustom->AddChildItem(new CCustomItemIcon(_T("Icon"), m_hIcon));
pItemIcon->SetDescription(_T("This sample shows how to override draw function"));
// 建立DockPadding内容
// DockPadding?个数的组?br> CXTPPropertyGridItem* pItemDock = pCustom->AddChildItem(new CCustomItemChilds(_T("DockPadding"), CRect(100, 20, 400, 50)));
pItemDock->SetDescription(_T("This sample shows how to add item with childs"));
// 建立颜色内容
pCustom->AddChildItem(new CCustomItemColor(_T("CustomCombolist"), RGB(0xFF, 0x80, 0x40)));
// 建立打开对话框内?br> pCustom->AddChildItem(new CCustomItemFileBox(_T("File Box")));
// 建立字符串内?br> CXTPPropertyGridItem* pItemMaskEdit = pCustom->AddChildItem(new CXTPPropertyGridItem(_T("Mask Edit"), _T("Phone No: (816) 220-0000")));
// 讄字符串MASK
pItemMaskEdit->SetMask(_T("Phone No: (000) 000-0000"), _T("Phone No: (___) ___-____"));
// 建立字符串内?br> CXTPPropertyGridItem* pItemPassword = pCustom->AddChildItem(new CXTPPropertyGridItem(_T("Password"), _T("Text")));
// 讄字符串Password
pItemPassword->SetPasswordMask();
// 建立日期内容
COleDateTime date(1981, 1, 26, 0, 0, 0 );
pCustom->AddChildItem(new CXTPPropertyGridItemDate(_T("Date"), date));
// 建立大写字母内容
pCustom->AddChildItem(new CCustomItemUpperCase(_T("UpperCase")));
// 建立ip地址内容
pCustom->AddChildItem(new CCustomItemIPAddress(_T("IP Address")));
// 建立PopupMenu内容
pCustom->AddChildItem(new CCustomItemMenu(_T("Popup Menu")));
// 建立字符串内?br> pCustom->AddChildItem(new CCustomItemEdit(_T("Output"), _T("Debug")));
// add multi level tree node.
// 建立树Ş内容
CXTPPropertyGridItem* pCategoryOne = pCustom->AddChildItem(new CXTPPropertyGridItemCategory(_T("First Sub Category")));
CXTPPropertyGridItem* pCategoryTwo = pCategoryOne->AddChildItem(new CXTPPropertyGridItemCategory(_T("Second Sub Category 1")));
pCategoryTwo->AddChildItem(new CXTPPropertyGridItem(_T("Third Level 1"), _T("")));
pCategoryTwo->AddChildItem(new CXTPPropertyGridItem(_T("Third Level 2"), _T("")));
CXTPPropertyGridItem* pCategoryTwo2 = pCategoryOne->AddChildItem(new CXTPPropertyGridItemCategory(_T("Second Sub Category 2")));
pCategoryTwo2->AddChildItem(new CXTPPropertyGridItem(_T("Third Level 1"), _T("")));
// 建立树Ş内容
CXTPPropertyGridItem* pItemOne = pCustom->AddChildItem(new CXTPPropertyGridItem(_T("First Level"), _T("")));
CXTPPropertyGridItem* pItemTwo = pItemOne->AddChildItem(new CXTPPropertyGridItem(_T("Second Level"), _T("")));
CXTPPropertyGridItem* pItemThird = pItemTwo->AddChildItem(new CXTPPropertyGridItem(_T("Third Level"), _T("")));
pItemThird->AddChildItem(new CXTPPropertyGridItem(_T("Fourth Level 1"), _T("")));
pItemThird->AddChildItem(new CXTPPropertyGridItem(_T("Fourth Level 2"), _T("")));
// create custom items category.
// 建立分类
pCustom = m_wndPropertyGrid.AddCategory(_T("Custom Butons"));
// 建立上下按钮内容
CXTPPropertyGridItem* pItemSpin = pCustom->AddChildItem(new CCustomItemSpin(_T("SpinButton")));
pItemSpin->SetDescription(_T("This sample shows how to add new button type"));
// 建立水^滑块内容
pCustom->AddChildItem(new CCustomItemSlider(_T("Slider")));
// 建立CheckBox内容
CCustomItemCheckBox* pItemCheckBox = (CCustomItemCheckBox*)pCustom->AddChildItem(new CCustomItemCheckBox(_T("Check Box")));
pItemCheckBox->SetValue(_T("agree with conditions"));
pItemCheckBox->SetBool(TRUE);
// 建立自定义按?br> pCustom->AddChildItem(new CCustomItemButton(_T("Left Origin"), FALSE, TRUE));
pCustom->AddChildItem(new CCustomItemButton(_T("Right Origin"), FALSE, TRUE));
pCustom->AddChildItem(new CCustomItemButton(_T("Pointer"), TRUE, TRUE));
pCustom->AddChildItem(new CCustomItemButton(_T("Gradient"), TRUE, FALSE));
}
m_groupAppearance.SubclassDlgItem(IDC_GBOX_APPEAR, this);
m_groupSort.SubclassDlgItem(IDC_GBOX_SORT, this);
m_groupColor.SubclassDlgItem(IDC_GBOX_COLOR, this);
// Set control resizing.
SetResize(IDC_PROPERTY_GRID, SZ_TOP_LEFT, SZ_BOTTOM_RIGHT);
//
SetResize(IDC_GBOX_APPEAR, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_CHK_TOOLBAR, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_CHK_HELP, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_CHK_VERBS, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_CHK_DOUBLE, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_CHK_TABITEMS, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_CHK_HIGHLIGHT, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_COMBO_THEME, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_GBOX_SORT, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_SORT_CATEGORIES, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_SORT_ALPHABETICAL, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_SORT_NOSORT, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_GBOX_COLOR, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_CHK_CUSTOMCOLORS, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_BUTTON_SWITCHSTATE, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_COMBO_BORDER, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_CHECK_SHOWBUTTONS, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
SetResize(IDC_CHK_RIGHTTOLEFT, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
// Load window placement
AutoLoadPlacement(_T("PropertyGridSample"));
m_cmbTheme.AddString(_T("xtpGridThemeDefault"));
m_cmbTheme.AddString(_T("xtpGridThemeNativeWinXP"));
m_cmbTheme.AddString(_T("xtpGridThemeOffice2003"));
m_cmbTheme.AddString(_T("xtpGridThemeCool"));
m_cmbTheme.AddString(_T("xtpGridThemeSimple"));
m_cmbTheme.AddString(_T("xtpGridThemeDelphi"));
m_cmbTheme.AddString(_T("xtpGridThemeWhidbey"));
m_cmbTheme.AddString(_T("xtpGridThemeOfficeXP"));
m_cmbTheme.AddString(_T("xtpGridThemeOffice2007"));
m_cmbTheme.SetCurSel(0);
m_cmbBorder.AddString(_T("xtpGridBorderNone"));
m_cmbBorder.AddString(_T("xtpGridBorderFlat"));
m_cmbBorder.AddString(_T("xtpGridBorderStaticEdge"));
m_cmbBorder.AddString(_T("xtpGridBorderClientEdge"));
m_cmbBorder.SetCurSel(3);
return TRUE; // 除非讄了控件的焦点Q否则返?TRUE
}