MFC+D3D+ToolKitPro

MFC+D3D+ToolKitPro

C++博客 首页 新随笔 联系 聚合 管理
  3 Posts :: 0 Stories :: 9 Comments :: 0 Trackbacks

2008年8月21日 #

由于最近写工具要使用xml来存储脚本,所以看了一些xml的c++相关内容
网上好多关于tinyxml的文档看了好多总是觉得比较麻烦,所以决定自己写一个类来封装它
这个类封装的不是很全面,但已经基本够我使用了,有兴趣的朋友可以再继续完善他,
让不懂xml内部原理的朋友们也可以方便使用xml格式文件存储数据

这是测试项目,vc71版本,我喜欢用2003,哈哈
/Files/hwawai/CXML_vc71.7z
如果大家有什么更好的代码来处理xml希望踊跃交流

头文件
#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使用,属临时变量
 TiXmlElement* getFirstElement(const char* ElementMark,TiXmlElement* pcrElement);
};

源文件
#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;
}


生成的xml文件
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>

posted @ 2008-08-21 15:45 hwawai 阅读(3016) | 评论 (6)编辑 收藏

2008年8月19日 #

最近做了个模型查看器使用了ToolKitPro
中的属性表组件









觉得这个组件太适合写一些游戏工具之类的了。
posted @ 2008-08-19 13:51 hwawai 阅读(1153) | 评论 (0)编辑 收藏


这篇是好久之前自己最初贴在cdsn上的帖子,现在也挪到这里算是开篇吧




 




这是根据原代码例子改的中文版界面,主要是在OnInitDialog里面的代码我都写了注释,有兴趣大家一起研究一下

BOOL CPropGridDlg::OnInitDialog()
{
 //  CDialog::OnInitDialog();
 CPropertyGridDlgBase::OnInitDialog();

 // 将\“关于...\”菜单项添加到系统菜单中。

 // IDM_ABOUTBOX 必须在系统命令范围内。
 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);
  }
 }

 // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
 //  执行此操作
 SetIcon(m_hIcon, TRUE);   // 设置大图标
 SetIcon(m_hIcon, FALSE);  // 设置小图标

 // TODO: 在此添加额外的初始化代码
 //////////////////////////////////////////////////////////////////////////
 // 获得图片框矩形
 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.
  // 建立只读字符串内容
  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.
  // 建立只读字符串内容
  CXTPPropertyGridItem* pItemVersion  = pVersion->AddChildItem(new CXTPPropertyGridItem(_T("AppVersion"), _T("1.0")));
  pItemVersion->SetReadOnly(TRUE);
  // 使用资源建立字符串内容
  CXTPPropertyGridItem* pItemLanguage = pVersion->AddChildItem(new CXTPPropertyGridItem(ID_ITEM_VERSION_LANGUAGE, _T("English (United States)")));
  // 展开分类
  pVersion->Expand();

  // 将combo连接到字符串内容中
  // 测试结果 只要不是只读的字符串内容就可连接combo 步骤如下
  // 获取item的Constraints
  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为可编辑组合框
  pItemLanguage->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);

  //////////////////////////////////////////////////////////////////////////
  // Dynamic Options
  // 建立分类
  CXTPPropertyGridItem* pCategoryDynamic = m_wndPropertyGrid.AddCategory(_T("Dynamic Options"));
  // 建立bool内容
  // 这是第2种方式 强制转换指针方式
  CXTPPropertyGridItemBool* pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
   new CXTPPropertyGridItemBool(_T("Advanced"), FALSE));
  // 设置ID
  pItemBool->SetID(501);
  // 设置checkbox样式
  pItemBool->SetCheckBoxStyle();
  // 建立bool内容checkbox样式并隐藏
  pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
   new CXTPPropertyGridItemBool(_T("Option 1"), FALSE));
  pItemBool->SetHidden(TRUE);
  pItemBool->SetCheckBoxStyle();
  // 建立bool内容checkbox样式并隐藏
  pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
   new CXTPPropertyGridItemBool(_T("Option 2"), FALSE));
  pItemBool->SetHidden(TRUE);
  pItemBool->SetCheckBoxStyle();
  // 建立bool内容checkbox样式并隐藏
  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"));
  // 建立字符串内容
  pStandard->AddChildItem(new CXTPPropertyGridItem(_T("String item")));
  // 建立多行字符串下拉框 帮助文件中没有
  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时间类COleDateTime
  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记录到enum内容呈combo样式
  pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 1);
  pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 2);
  pItem->GetConstraints()->AddConstraint(_T("Windows XP"), 3);

  // 建立flag内容 第2个参数"1+2"为初始值 即"Windows 98"和"Windows 2000"为真
  // 且flag的元素数值需为1,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);
  // 建立字符串内容
  pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Expand Button")));
  // 设置为可编辑并带有扩展按钮样式
  pItem->SetFlags(xtpGridItemHasEdit | xtpGridItemHasExpandButton);
  // 建立字符串内容
  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);
  // 建立字符串内容
  pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Text Button")));
  // 添加按钮到字符串内容行尾
  CXTPPropertyGridInplaceButton* pButton = pItem->GetInplaceButtons()->AddButton(new CXTPPropertyGridInplaceButton(1));
  // 设置按钮文本
  pButton->SetCaption(_T("Find"));
  // 设置按钮宽度
  pButton->SetWidth(100);
  // 建立字符串内容
  pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Image Button")));
  // 添加按钮到字符串内容行尾
  pButton = pItem->GetInplaceButtons()->AddButton(new CXTPPropertyGridInplaceButton(1));
  // 设置按钮图标索引
  pButton->SetIconIndex(100);
  // UINT数组  估计是一个临时存储单元用于添加图标到按钮
  // 上面的100和下面的100以及设置图标语句中的btnFilter是相联系的
  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暂时没有找到设置范围的方法
  // 添加水平滑块连接到整形内容
  pItem->AddSliderControl();
  // 添加上下按钮连接到整形内容
  pItem->AddSpinButton();

  //////////////////////////////////////////////////////////////////////////
  // 建立分类
  CXTPPropertyGridItem* pMetrics   = m_wndPropertyGrid.AddCategory(_T("Custom Metrics"));
  // 建立字符串内容
  pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("Value Colors"), _T("")));
  // 设置文字颜色 可以采用RGB宏或DWORD
  // 文字和背景颜色会呈现混合效果
  pItem->GetValueMetrics()->m_clrFore = 0x00ff00;
  // 设置背景颜色
  pItem->GetValueMetrics()->m_clrBack = RGB(255, 0, 255);
  // 建立字符串内容
  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记录并带有图片
  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内容的内容图片
  pItem->GetValueMetrics()->m_nImage = 2;
  // 设置enum内容的标题图片
  pItem->GetCaptionMetrics()->m_nImage = 4;
  // 设置mask颜色
  m_wndPropertyGrid.GetImageManager()->SetMaskColor(0xC0C0C0);
  // 设置图标
  m_wndPropertyGrid.GetImageManager()->SetIcons(IDB_BITMAP_CONSTRAINTS, 0, 5, CSize(20, 14));
  // 建立字符串内容
  pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("Variable Height"), _T("Item")));
  // 建立内容块高度
  pItem->SetHeight(32);
  // 设置为combo样式
  pItem->SetFlags(xtpGridItemHasComboButton);
  // 建立多行字符串内容
  // 貌似在多行中无法真正的多行编辑 没有找到让文本换行即支持文本回车的方式
  pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("MultiLine"), _T("Codejock Software\r\n428 Corunna Avenue\r\nOwosso, Michigan 48867 USA")));
  // 设置能见得文本行数
  pItem->SetMultiLinesCount(3);

 

  // create custom items category.
  // 建立分类
  // 以下为自定义类型 代码见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为4个数的组合
  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)));
  // 建立打开对话框内容
  pCustom->AddChildItem(new CCustomItemFileBox(_T("File Box")));
  // 建立字符串内容
  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: (___) ___-____"));
  // 建立字符串内容
  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")));
  // 建立字符串内容
  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);
  // 建立自定义按钮
  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

posted @ 2008-08-19 13:37 hwawai 阅读(3954) | 评论 (3)编辑 收藏

仅列出标题