锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
緗戜笂濂藉鍏充簬tinyxml鐨勬枃妗g湅浜嗗ソ澶氭繪槸瑙夊緱姣旇緝楹葷儲錛屾墍浠ュ喅瀹氳嚜宸卞啓涓涓被鏉ュ皝瑁呭畠
榪欎釜綾誨皝瑁呯殑涓嶆槸寰堝叏闈紝浣嗗凡緇忓熀鏈鎴戜嬌鐢ㄤ簡錛屾湁鍏磋叮鐨勬湅鍙嬪彲浠ュ啀緇х畫瀹屽杽浠栵紝
璁╀笉鎳倄ml鍐呴儴鍘熺悊鐨勬湅鍙嬩滑涔熷彲浠ユ柟渚夸嬌鐢▁ml鏍煎紡鏂囦歡瀛樺偍鏁版嵁
榪欐槸嫻嬭瘯欏圭洰錛寁c71鐗堟湰錛屾垜鍠滄鐢?003錛屽搱鍝?br>/Files/hwawai/CXML_vc71.7z
濡傛灉澶у鏈変粈涔堟洿濂界殑浠g爜鏉ュ鐞唜ml甯屾湜韙婅穬浜ゆ祦
澶存枃浠?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鏂囦歡
#pragma once
#include <iostream>
#include <tchar.h>
鐢ㄦ潵嫻嬭瘯鐨勪富cpp鏂囦歡
#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;
}
鐢熸垚鐨剎ml鏂囦歡
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>
榪欐槸鏍規嵁鍘熶唬鐮佷緥瀛愭敼鐨勪腑鏂囩増鐣岄潰,涓昏鏄湪OnInitDialog閲岄潰鐨勪唬鐮佹垜閮藉啓浜嗘敞閲?鏈夊叴瓚eぇ瀹朵竴璧風爺絀朵竴涓?/p>
BOOL CPropGridDlg::OnInitDialog()
{
// CDialog::OnInitDialog();
CPropertyGridDlgBase::OnInitDialog();
// 灝哱“鍏充簬...\”鑿滃崟欏規坊鍔犲埌緋葷粺鑿滃崟涓?/p>
// IDM_ABOUTBOX 蹇呴』鍦ㄧ郴緇熷懡浠よ寖鍥村唴銆?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);
}
}
// 璁劇疆姝ゅ璇濇鐨勫浘鏍囥傚綋搴旂敤紼嬪簭涓葷獥鍙d笉鏄璇濇鏃訛紝妗嗘灦灝嗚嚜鍔?br> // 鎵ц姝ゆ搷浣?br> SetIcon(m_hIcon, TRUE); // 璁劇疆澶у浘鏍?br> SetIcon(m_hIcon, FALSE); // 璁劇疆灝忓浘鏍?/p>
// TODO: 鍦ㄦ娣誨姞棰濆鐨勫垵濮嬪寲浠g爜
//////////////////////////////////////////////////////////////////////////
// 鑾峰緱鍥劇墖妗嗙煩褰?br> CRect rc;
m_wndPlaceHolder.GetWindowRect( &rc );
// 杞負紿楀彛鍧愭爣
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();
// 灝哻ombo榪炴帴鍒板瓧絎︿覆鍐呭涓?br> // 嫻嬭瘯緇撴灉 鍙涓嶆槸鍙鐨勫瓧絎︿覆鍐呭灝卞彲榪炴帴combo 姝ラ濡備笅
// 鑾峰彇item鐨凜onstraints
CXTPPropertyGridItemConstraints* pList = pItemLanguage->GetConstraints();
// 娣誨姞combo鍐呭
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涓哄彲緙栬緫緇勫悎妗?br> pItemLanguage->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
//////////////////////////////////////////////////////////////////////////
// Dynamic Options
// 寤虹珛鍒嗙被
CXTPPropertyGridItem* pCategoryDynamic = m_wndPropertyGrid.AddCategory(_T("Dynamic Options"));
// 寤虹珛bool鍐呭
// 榪欐槸絎?縐嶆柟寮?nbsp;寮哄埗杞崲鎸囬拡鏂瑰紡
CXTPPropertyGridItemBool* pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
new CXTPPropertyGridItemBool(_T("Advanced"), FALSE));
// 璁劇疆ID
pItemBool->SetID(501);
// 璁劇疆checkbox鏍峰紡
pItemBool->SetCheckBoxStyle();
// 寤虹珛bool鍐呭checkbox鏍峰紡騫墮殣钘?br> pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
new CXTPPropertyGridItemBool(_T("Option 1"), FALSE));
pItemBool->SetHidden(TRUE);
pItemBool->SetCheckBoxStyle();
// 寤虹珛bool鍐呭checkbox鏍峰紡騫墮殣钘?br> pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
new CXTPPropertyGridItemBool(_T("Option 2"), FALSE));
pItemBool->SetHidden(TRUE);
pItemBool->SetCheckBoxStyle();
// 寤虹珛bool鍐呭checkbox鏍峰紡騫墮殣钘?br> pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
new CXTPPropertyGridItemBool(_T("Option 3"), FALSE));
pItemBool->SetHidden(TRUE);
pItemBool->SetCheckBoxStyle();
// 寤虹珛bool鍐呭checkbox鏍峰紡騫墮殣钘忓拰鍙
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")));
// 寤虹珛澶氳瀛楃涓蹭笅鎷夋 甯姪鏂囦歡涓病鏈?br> pStandard->AddChildItem(new CXTPPropertyGridItemMultilineString(_T("Multiline String item"), _T("1\r\n2")));
// 寤虹珛鏁存暟鍐呭
pStandard->AddChildItem(new CXTPPropertyGridItemNumber(_T("Integer item")));
// 寤虹珛double鍐呭騫惰緗垵濮嬪煎拰鏁版嵁鏍煎紡
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鏃墮棿綾籆OleDateTime
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));
// 娣誨姞enum璁板綍鍒癳num鍐呭鍛坈ombo鏍峰紡
pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 1);
pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 2);
pItem->GetConstraints()->AddConstraint(_T("Windows XP"), 3);
// 寤虹珛flag鍐呭 絎?涓弬鏁?1+2"涓哄垵濮嬪?nbsp;鍗?Windows 98"鍜?Windows 2000"涓虹湡
// 涓攆lag鐨勫厓绱犳暟鍊奸渶涓?,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")));
// 璁劇疆涓篶ombo鏍峰紡
pItem->SetFlags(xtpGridItemHasComboButton);
// 寤虹珛瀛楃涓插唴瀹?br> pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Expand Button")));
// 璁劇疆涓哄彲緙栬緫騫跺甫鏈夋墿灞曟寜閽牱寮?br> pItem->SetFlags(xtpGridItemHasEdit | xtpGridItemHasExpandButton);
// 寤虹珛瀛楃涓插唴瀹?br> pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("2 Buttons")));
// 璁劇疆ID
pItem->SetID(510);
// 璁劇疆涓哄彲緙栬緫騫跺甫鏈夋墿灞曟寜閽牱寮忓拰combo
pItem->SetFlags(xtpGridItemHasEdit | xtpGridItemHasComboButton | xtpGridItemHasExpandButton);
// 娣誨姞combo鍐呭
pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 1);
pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 2);
// 寤虹珛瀛楃涓插唴瀹?br> pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Text Button")));
// 娣誨姞鎸夐挳鍒板瓧絎︿覆鍐呭琛屽熬
CXTPPropertyGridInplaceButton* pButton = pItem->GetInplaceButtons()->AddButton(new CXTPPropertyGridInplaceButton(1));
// 璁劇疆鎸夐挳鏂囨湰
pButton->SetCaption(_T("Find"));
// 璁劇疆鎸夐挳瀹藉害
pButton->SetWidth(100);
// 寤虹珛瀛楃涓插唴瀹?br> pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Image Button")));
// 娣誨姞鎸夐挳鍒板瓧絎︿覆鍐呭琛屽熬
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> // 娣誨姞姘村鉤婊戝潡榪炴帴鍒版暣褰㈠唴瀹?br> pItem->AddSliderControl();
// 娣誨姞涓婁笅鎸夐挳榪炴帴鍒版暣褰㈠唴瀹?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璁板綍騫跺甫鏈夊浘鐗?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);
// 璁劇疆涓篶ombo鏍峰紡
pItem->SetFlags(xtpGridItemHasComboButton);
// 寤虹珛澶氳瀛楃涓插唴瀹?br> // 璨屼技鍦ㄥ琛屼腑鏃犳硶鐪熸鐨勫琛岀紪杈?娌℃湁鎵懼埌璁╂枃鏈崲琛屽嵆鏀寔鏂囨湰鍥炶濺鐨勬柟寮?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.
// 寤虹珛鍒嗙被
// 浠ヤ笅涓鴻嚜瀹氫箟綾誨瀷 浠g爜瑙丆ustomItems.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")));
// 璁劇疆瀛楃涓睲ASK
pItemMaskEdit->SetMask(_T("Phone No: (000) 000-0000"), _T("Phone No: (___) ___-____"));
// 寤虹珛瀛楃涓插唴瀹?br> CXTPPropertyGridItem* pItemPassword = pCustom->AddChildItem(new CXTPPropertyGridItem(_T("Password"), _T("Text")));
// 璁劇疆瀛楃涓睵assword
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; // 闄ら潪璁劇疆浜嗘帶浠剁殑鐒︾偣錛屽惁鍒欒繑鍥?TRUE
}