先附上流程图:

(1) 创建工程

 (2)插入一个对话框

双击.rc文件

右键-》选中添加资源

修改对话框ID:IDD_OPTION_SHEET

在上面添加一个Tab控件, 修改ID:IDC_TAB

(3)为此对话框添加映射类COptionSheet,基类为CAcUiTabMainDialog

 (4)再插入一个对话框资源(IDD_TEXT_PAGE)

右击,选“插入dialog”

放置一个文本框

 (5)创建文字选项卡的映射类CTextPage

 (6)插入第二个选项卡对应的资源对话框(IDD_CONREOL_PAGE)

添加Group Box按钮

内部放置两个单选按钮(ID分别为:IDC_RADIO1和IDC_RADIO2),只勾选第一个按钮的Group选项

添加一个复选框控件

点击一下对话框,修改属性

创建这个选项卡对话框的映射类CControlPage

 (7)在COptionSheet类中,为Tab控件添加映射成员变量

点击Tab控件框,右键选择“添加变量”

(8) 在COptionSheet类中添加两个成员变量

CTextPage m_textPage;

CControlPage m_controlPage;

注:上图中的变量名应为:m_textPage

 (9)创建IDD_OPTION_SHEET对话框的初始化事件

 (10)在命令的实现函数中加入下面的代码,并添加头文件:#include "OptionSheet.h"

这时候 编译程序,并打开CAD,看看是否能弹出对话框

(11)添加一个新类CIniFile(C++常规类) ,用于读写INI文件中的键值

(13)类的实现内容 

IniFile.h:

#pragma once
class CIniFile
{
public:CIniFile();//~CIniFile();CIniFile(const TCHAR* fileName);virtual ~CIniFile();//指定字段和键的名称,获得对应的键值bool GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, CString &strValue, int bufferLength = 1000) const;bool GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, int &nValue) const;bool GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, byte &byteValue) const;bool GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, bool &bValue) const;bool GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, double &dValue) const;//指定字段名和键的名称,写入对应的键值bool SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, const TCHAR* strValue);bool SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, int nValue);bool SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, byte byteValue);bool SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, bool bValue);//decimalplaces小数点位数bool SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, double dValue, int decimalPlaces = 2);private:CString m_strFile;//INI文件的保存位置
};

IniFile.cpp

#include "stdafx.h"
#include "IniFile.h"CIniFile::CIniFile()
{
}CIniFile::~CIniFile()
{
}CIniFile::CIniFile(const TCHAR* fileName)
{m_strFile = fileName;
}//指定字段和键的名称,获得对应的键值
bool CIniFile::GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, CString &strValue, int bufferLength) const
{assert(m_strFile.GetLength() > 0);CString strDefault = TEXT("NotExist");//如果找不到对应的键,则返回该值CString strTemp;DWORD dwCharacters = ::GetPrivateProfileString(strFieldName,strKeyName,strDefault,strTemp.GetBuffer(bufferLength),bufferLength,m_strFile);strTemp.ReleaseBuffer();//注意GetPrivateProfileString函数的错误形式if (strTemp.Compare(strDefault) == 0){return false;}else{strValue = strTemp;return true;}
}bool CIniFile::GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, int &nValue) const
{CString strValue = TEXT("");if (GetValueOfKey(strFieldName, strKeyName, strValue)){nValue = _ttoi(strValue);return true;}else{return false;}
}bool CIniFile::GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, byte &byteValue) const
{CString strValue = TEXT("");if (GetValueOfKey(strFieldName, strKeyName, strValue)){byteValue = (byte)(_ttoi(strValue));return true;}else{return false;}
}bool CIniFile::GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, bool &bValue) const
{CString strValue = TEXT("");if (GetValueOfKey(strFieldName, strKeyName, strValue)){bValue = bool(_ttoi(strValue) == 1);return true;}else{return false;}
}bool CIniFile::GetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, double &dValue) const
{CString strValue = TEXT("");if (GetValueOfKey(strFieldName, strKeyName, strValue)){//dValue = _tstof(strValue)//CString转doubleTCHAR* szStop = NULL;dValue = _tcstod(strValue, &szStop);//CString转doublereturn true;}else{return false;}
}//指定字段名和键的名称,写入对应的键值
bool CIniFile::SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, const TCHAR* strValue)
{//防止在调用函数之前m_strFile未被初始化if (m_strFile.IsEmpty()){AfxMessageBox(TEXT("在调用函数SetValueOfKey时,m_strFile未被赋值,异常退出"));return false;}BOOL bRet = ::WritePrivateProfileString(strFieldName,strKeyName,strValue,m_strFile);if (bRet){return true;}elsereturn false;
}bool CIniFile::SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, int nValue)
{CString strValue = TEXT("");strValue.Format(TEXT("%d"), nValue);//returns the string formatreturn SetValueOfKey(strFieldName, strKeyName, strValue);
}bool CIniFile::SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, byte byteValue)
{CString strValue = TEXT("");strValue.Format(TEXT("%u"), byteValue);return SetValueOfKey(strFieldName, strKeyName, strValue);
}bool CIniFile::SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, bool bValue)
{CString strValue = TEXT("");strValue.Format(TEXT("%d"), bValue);return SetValueOfKey(strFieldName, strKeyName, strValue);
}//decimalplaces小数点位数
bool CIniFile::SetValueOfKey(const TCHAR* strFieldName, const TCHAR* strKeyName, double dValue, int decimalPlaces)
{assert(decimalPlaces >= 0);CString strFormat = TEXT("");strFormat.Format(TEXT("%%0.%df"), decimalPlaces);CString strValue = TEXT("");strValue.Format(strFormat, dValue);return SetValueOfKey(strFieldName, strKeyName, strValue);
}

(13)为CTextPage窗体中的文字高度的文本框映射double类型的成员变量m_textHeight

同理,为文字样式组合框映射CComboBox成员变量m_cboTextStyle

(14)创建CTextPage窗体的初始化事件

填充文字样式组合框,从INI文件中加载默认的参数值:

//填充文字样式组合框std::vector<CString> textStyles;CTextStyleUtil::GetAll(textStyles);for (int i = 0; i < textStyles.size(); i++){m_cboTextStyle.AddString(textStyles[i]);}if (m_cboTextStyle.GetCount() > 0){m_cboTextStyle.SetCurSel(0);}//从INI文件中加载参数值CIniFile iniFile(CAppDirectoryUtil::GetCurrentDirectory() + TEXT("\\OptionSheet.ini"));CString field = TEXT("OptionSheet");iniFile.GetValueOfKey(field, TEXT("textHeight"), m_textHeight);CString strTextStyle;iniFile.GetValueOfKey(field, TEXT("textStyle"), strTextStyle);//设置组合框的当前选择项for (int i = 0; i < m_cboTextStyle.GetCount(); i++){CString strItem;m_cboTextStyle.GetLBText(i, strItem);//retrieves a string from the list box of a combo boxif (strItem.CompareNoCase(strTextStyle) == 0)//Zero if the strings are identical (ignoring case), {m_cboTextStyle.SetCurSel(i);break;}}UpdateData(FALSE);

添加类AppDirectoryUtil

类AppDirectoryUtil的实现

AppDirectoryUtil.h

// AppDirectoryUtil.h: interface for the CAppDirectoryUtil class.#if !defined(AFX_APPDIRECTORYUTIL_H__DD493023_982A_4370_8A6F_C271F5FD388F__INCLUDED_)
#define AFX_APPDIRECTORYUTIL_H__DD493023_982A_4370_8A6F_C271F5FD388F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CAppDirectoryUtil
{
public:CAppDirectoryUtil();// 功能: 获得当前的ARX文件所在的路径static CString GetCurrentDirectory(HMODULE hInstance = _hdllInstance);// 功能: 获得当前的ARX文件所在的文件夹的上级目录static CString GetParentDirectory(HMODULE hInstance = _hdllInstance);~CAppDirectoryUtil();
};#endif // !defined(AFX_APPDIRECTORYUTIL_H__DD493023_982A_4370_8A6F_C271F5FD388F__INCLUDED_)

AppDirectoryUtil.cpp

#include "stdafx.h"
#include "AppDirectoryUtil.h"#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif//
// Construction/Destruction
//CAppDirectoryUtil::CAppDirectoryUtil()
{
}CAppDirectoryUtil::~CAppDirectoryUtil()
{
}CString CAppDirectoryUtil::GetCurrentDirectory(HMODULE hInstance)
{TCHAR szPath[256];GetModuleFileName(hInstance, szPath, sizeof(szPath));*(_tcsrchr(szPath, '\\')) = 0;       // 将最后一个\所在的位置修改为\0CString strResult = szPath;return strResult;
}CString CAppDirectoryUtil::GetParentDirectory(HMODULE hInstance)
{TCHAR szPath[256];GetModuleFileName(hInstance, szPath, sizeof(szPath));*(_tcsrchr(szPath, '\\')) = 0;       // 将最后一个\所在的位置设置为\0*(_tcsrchr(szPath, '\\')) = 0;        // 继续将最后一个\所在的位置设计为\0CString strResult = szPath;return strResult;
}

添加C++常规类:CTextStyleUtil

CTextStyleUtil.h:

#if !defined(AFX_TEXTSTYLEUTIL_H__F392A987_01EA_4AD0_BCE3_C39921CAC013__INCLUDED_)
#define AFX_TEXTSTYLEUTIL_H__F392A987_01EA_4AD0_BCE3_C39921CAC013__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#include <vector>
class CTextStyleUtil
{
public:CTextStyleUtil();virtual ~CTextStyleUtil();// 获得某个文字样式的IDstatic AcDbObjectId GetAt(const TCHAR* name);// 获得文字样式名称列表static void GetAll(std::vector<CString> &textStyles);// 创建一种文字样式static AcDbObjectId Add(const TCHAR* name, const TCHAR* fontFileName = TEXT("txt.shx"),const TCHAR* bigFontFileName = TEXT("gbcbig.shx"));//~CTextStyleUtil();
};#endif // !defined(AFX_TEXTSTYLEUTIL_H__F392A987_01EA_4AD0_BCE3_C39921CAC013__INCLUDED_)

CTextStyleUtil.cpp:

#include "stdafx.h"
#include "TextStyleUtil.h"
#include <dbsymtb.h>
#include <acutmem.h>#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif//
// Construction/Destruction
//CTextStyleUtil::CTextStyleUtil()
{
}CTextStyleUtil::~CTextStyleUtil()
{
}AcDbObjectId CTextStyleUtil::GetAt(const TCHAR* name)
{AcDbObjectId textStyleId;if (_tcslen(name) > 0)//Unicode字符串的长度{AcDbTextStyleTable* pTextStyleTable = NULL;acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pTextStyleTable, AcDb::kForRead);pTextStyleTable->getAt(name, textStyleId);    // 如果不存在,textStyleId不会被赋值pTextStyleTable->close();}return textStyleId;
}void CTextStyleUtil::GetAll(std::vector<CString> &textStyles)
{textStyles.clear();AcDbTextStyleTable *pTextStyleTbl = NULL;acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pTextStyleTbl, AcDb::kForRead);AcDbTextStyleTableIterator *pIt = NULL;pTextStyleTbl->newIterator(pIt);for (; !pIt->done(); pIt->step()){AcDbTextStyleTableRecord *pRcd = NULL;if (pIt->getRecord(pRcd, AcDb::kForRead) == Acad::eOk){TCHAR *szName = NULL;pRcd->getName(szName);if (_tcslen(szName) > 0)        // 过滤掉名称为空的文字样式{textStyles.push_back(szName);}acutDelString(szName);pRcd->close();}}delete pIt;pTextStyleTbl->close();
}AcDbObjectId CTextStyleUtil::Add(const TCHAR* name, const TCHAR* fontFileName, const TCHAR* bigFontFileName)
{Acad::ErrorStatus es;AcDbTextStyleTable* pTextStyleTable = NULL;es = acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pTextStyleTable, AcDb::kForWrite);AcDbTextStyleTableRecord* pTextStyleRecord = new AcDbTextStyleTableRecord();es = pTextStyleRecord->setName(name);es = pTextStyleRecord->setBigFontFileName(bigFontFileName);      // 大字体文件es = pTextStyleRecord->setFileName(fontFileName);   // 字体文件es = pTextStyleRecord->setXScale(1.0);       // 文字高宽比(一般这里都设置为1,在文字属性中决定高宽比)es = pTextStyleTable->add(pTextStyleRecord);AcDbObjectId styleId = pTextStyleRecord->objectId();pTextStyleTable->close();pTextStyleRecord->close();return styleId;
}

在TextPage.cpp文件中添加以下头文件:

#include "AppDirectoryUtil.h"
#include "IniFile.h"
#include <vector>
#include <string.h>
#include "TextStyleUtil.h"

这时候编译会出错:

需要强制类型转换:

(15)在CTextPage类中添加公有成员函数SaveProfiles,用于将用户在控件中输入的参数值保存到INI中

函数的代码:

bool CTextPage::SaveProfile()
{if (!UpdateData()){return false;}//保存参数值CIniFile iniFile(CAppDirectoryUtil::GetCurrentDirectory() +TEXT("\\OptionSheet.ini"));CString field = TEXT("OptionSheet");iniFile.SetValueOfKey(field, TEXT("textHeight"), m_textHeight);CString strTextStyle;m_cboTextStyle.GetLBText(m_cboTextStyle.GetCurSel(), strTextStyle);iniFile.SetValueOfKey(field, TEXT("textStyle"), strTextStyle);return false;
}

 (16)对CControlPage窗体中的单选按钮映射int类型的成员变量m_nRadio1

对CControlPage窗体中的复选框按钮映射BOOL类型的成员变量m_bCheck1

这是编译发现出错:

 强制类型转换:

 (17)创建CControlPage窗体的初始化事件


BOOL CControlPage::OnInitDialog()
{CAcUiTabChildDialog::OnInitDialog();// TODO:  在此添加额外的初始化//从INI文件中加载参数值CIniFile iniFile(CAppDirectoryUtil::GetCurrentDirectory() +TEXT("\\OptionSheet.ini"));CString field = TEXT("OptionSheet");iniFile.GetValueOfKey(field, TEXT("nRadio1"), m_nRadio1);iniFile.GetValueOfKey(field, TEXT("bCheck1"), m_bCheck1);UpdateData(FALSE);return TRUE;  // return TRUE unless you set the focus to a control// 异常: OCX 属性页应返回 FALSE
}

添加头文件

#include "AppDirectoryUtil.h"
#include "IniFile.h"

(18)在CControlPage 类中添加函数SaveProfiles

bool CControlPage::SaveProfiles()
{CIniFile iniFile(CAppDirectoryUtil::GetCurrentDirectory() +TEXT("\\OptionSheet.ini"));CString field = TEXT("OptionSheet");iniFile.SetValueOfKey(field, TEXT("nRadio1"), m_nRadio1);iniFile.SetValueOfKey(field, TEXT("bCheck1"), m_bCheck1);return false;
}

(19)为COptionSheet窗体添加OnOK消息处理函数

void COptionSheet::OnOK()
{// TODO: 在此添加专用代码和/或调用基类if (!m_textPage.SaveProfile() || !m_controlPage.SaveProfiles()){return;}CAcUiTabMainDialog::OnOK();
}

效果:

项目源代码:在ObjectARX中使用MFC-标签式对话框 项目源代码

参考资料:

《AutoCAD ObjectARX(VC)开发基础与实例教程》

在ObjectARX中使用MFC-标签式对话框相关推荐

  1. (在ObjectARX中使用MFC)

    要实现的功能是: 执行ArxModal命令,弹出如图所示对话框 选择点,则得到点坐标,选择角度则得到角度值. 步骤一: 新建基于MFC的ObjectArx项目, 参考: http://www.cnbl ...

  2. CAD二次开发学习笔记五(在ObjectARX中使用MFC)

    要实现的功能是: 执行ArxModal命令,弹出如图所示对话框 选择点,则得到点坐标,选择角度则得到角度值. 步骤一: 新建基于MFC的ObjectArx项目, 参考:http://www.cnblo ...

  3. Visual C++ 2010中更换MFC对话框默认图标

    1.菜单栏的"文件"->新建->项目->选择左侧 "Visual C++" 下的 "MFC"项->在右边选择&quo ...

  4. 关于JFace中的向导式对话框(WizardDialog类)

    向导式对话框是一种非常友好的界面,它能够引导用户一步步的输入信息.Eclipse的"新建项目",就是这样的向导式对话框. 在Eclipse中向导式对话框的开发是很简单的,它由Wiz ...

  5. vue如何在style标签中使用data响应式数据?

    文章目录 一.面临到的需求? 二.如何在css中使用变量? 三.vue如何在style标签中使用data响应式数据? 一.面临到的需求? 首先我们知道css对应是有伪类的,如:hover, :acti ...

  6. MFC标签页控件的使用

    随笔- 11  文章- 0  评论- 3 MFC标签页控件的使用 1.在对话框中添加一个标签页控件,并为此控件关联一个CTabCtrl类变量m_tabctrl. 2.创建若干个对话框资源作为标签页控件 ...

  7. MFC非模态对话框实例

    [转载]MFC非模态对话框实例 2012-06-17 16:21:41|  分类: C++/MFC |  标签: |字号大中小 订阅 实例目的 在Windows环境中,对话框是一种常用的输入输出手段. ...

  8. MFC创建模态对话框与非模态对话框 执行顺序

    创建模态对话框 CDialog::DoModal virtual int DoModal(); 返回值: 整数值,指定了传递给CDialog::EndDialog 的nResult参数值.该函数用于关 ...

  9. 5弹出阴影遮罩_千文详述Cocos Creator弹出式对话框实现技术,着实硬核

    正文 在Cocos Creator游戏开发中,经常需要使用到弹出式对话框,下面我们就一起来封装下自己的弹出式对话框. 一.弹出式对话框原理解析 1:对话框的结构: 1. `根节点 -->`2. ...

最新文章

  1. 深圳Uber优步司机奖励政策(12月28日到1月3日)
  2. Python爬虫入门教程 18-100 煎蛋网XXOO图片抓取
  3. 下面介绍一个开源的OCR引擎Tesseract2。值得庆幸的是虽然是开源的但是它的识别率较高,并不比其他引擎差劲。网上介绍Tessnet2也是当时时间排名第三的识别引擎,只是后来慢慢不维护了,目前是G
  4. NOI2012 Day2
  5. 辰皇怎么过鸿蒙,诛仙3最厉害的职业是什么 强弱对应原因解析
  6. 专注于钢铁行业电子商务的服务网站,钢铁行业的网上贸易市场 一起成长
  7. heavy dark--读《《暗时间》》
  8. boost python实现_Boost Python官方样例(一)
  9. 台式机创建文件服务器,如何将台式机做成云存储服务器
  10. 2023AB斗篷玩法全攻略
  11. 开源中Web开发的各种资源
  12. CAD图纸怎么转换PDF格式?怎样转换更加高效?
  13. 3G门户网总裁张向东:怎分享3G大蛋糕
  14. 安卓市场 android2.1.1,iLike安卓数据恢复专业版
  15. Python 练习实例5 题目:输入三个整数x,y,z,请把这三个数由小到大输出。
  16. 正弦定理c语言,高二数学正弦定理测试题
  17. Android 检测设备是否为模拟器
  18. 华为 配置STP预防环路
  19. 8-Arm PEG-DBCO分子量决定外观性状,用于修饰生物分子
  20. 项目管理的重要性及其对企业和个人的意义

热门文章

  1. RTOS环境下低功耗设计思路
  2. 因计算机丢失d3dx9-30,win10安装游戏或软件后发现d3dx9_30.dll丢失打不开怎么办
  3. 模拟电子技术基础之场效应管
  4. 大龙管理系统2.0出炉
  5. 最新织梦CMS程序 小黑屋QQ技术导航新增手机版源码分享
  6. 借贷领域需求强烈,Trister‘s Lend上线TVL超2000万美元值得关注!
  7. 墙裂推荐c++的学习网站(OJ)
  8. 创建xml并解析xml_构建,解析和提取XML
  9. 【已解决:teamview使用的设备数量受限,您已达到设备数量上限】
  10. 从用户粘性谈“联盟啦“如何服务站长十四年?