在MFC中用WriteProfileInt等方法保存应用程序配置
来源:互联网 发布:手机图纸软件 编辑:程序博客网 时间:2024/04/30 07:12
0.简介
CWinApp类中提供了一组用于读写应用程序配置的方法:
GetProfileInt
WriteProfileInt
GetProfileString
WriteProfileString
可方便的用于读写应用程序配置。
1.关于CWinApp::SetRegistryKey方法
用VC++的向导建立MFC项目之后,在InitInstance中可以看到这样的语句:
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
该函数将为以上提到的几个方法建立工作环境,此时如果用WriteProfileInt写入数据,将会被写入到如下注册表位置:
HKEY_CURRENT_USER/Software/应用程序向导生成的本地应用程序/应用程序名称/
如果在InitInstance中不执行SetRegistryKey,则用WriteProfileInt写入数据时,将写入到
%windir%/应用程序名称.ini中。
2.用法
a.如果在InitInstance中执行了SetRegistryKey("清风居");
则对于:
WriteProfileInt("section","val1",10);
将在注册表中如下路径写入数据:
[HKEY_CURRENT_USER/Software/清风居/测试应用程序/section]
"val1"=dword:0000000a
注:“测试应用程序”是应用程序的名称。
b.如果在InitInstance中没执行SetRegistryKey
则对于:
WriteProfileInt("section","val1",10);
将在“%windir%/测试应用程序.ini”中写入:
[section]
val1=10
3.实例:保存应用程序的窗口大小和位置
//改变大小时
void CMyDlg::OnSize(UINT nType, int cx, int cy)
if (m_bInitDialog && cx<nX && cy<nY)
{
//保存当前大小位置
CRect rcWindow;
GetWindowRect(&rcWindow);
theApp.WriteProfileInt("Settings","left",rcWindow.left);
theApp.WriteProfileInt("Settings","top",rcWindow.top);
theApp.WriteProfileInt("Settings","right",rcWindow.right);
theApp.WriteProfileInt("Settings","bottom",rcWindow.bottom);
}
//移动窗口时
void CMyDlg::OnMove(int x, int y)
{
if (m_bInitDialog && x!=0 && y!=0)
{
//保存当前大小位置
CRect rcWindow;
GetWindowRect(&rcWindow);
theApp.WriteProfileInt("Settings","left",rcWindow.left);
theApp.WriteProfileInt("Settings","top",rcWindow.top);
theApp.WriteProfileInt("Settings","right",rcWindow.right);
theApp.WriteProfileInt("Settings","bottom",rcWindow.bottom);
}
}
//初始化
BOOL CMyDlg::OnInitDialog()
{
CRect rcWindow;
rcWindow.left=theApp.GetProfileInt("Settings","left",200);
rcWindow.top=theApp.GetProfileInt("Settings","top",120);
rcWindow.right=theApp.GetProfileInt("Settings","right",800);
rcWindow.bottom=theApp.GetProfileInt("Settings","bottom",600);
MoveWindow(&rcWindow);
}
本文转载自:http://www.qingfengju.com/article.asp?id=75
- 在MFC中用WriteProfileInt等方法保存应用程序配置
- WriteProfileInt
- MFC中关于WriteProfileInt和WritePrivateProfileString
- SetRegistryKey导致CWinApp::WriteProfileInt等操作注册表而不是INI文件
- 在MFC中获得应用程序路径的方法
- MFC中如何将应用程序的配置信息保存到注册表中(一)
- MFC中如何将应用程序的配置信息保存到注册表中(二)
- BCG、MFC如何支持《支持应用程序设置的回复、保存等》的?他是怎么实现的呢?
- 保存应用程序的配置信息
- 怎样在应用程序中用Graphics类?
- 在控制台程序中用MFC类
- 在MFC中用AfxMessageBox显示变量
- 直接在MFC中用Directshow Transform filter
- 在mfc中用opencv显示视频
- MFC应用程序配置不正确解决方案
- 在javascript中用submit方法
- MFC退出应用程序的方法
- MFC 全局配置 读取保存配置
- 抗击惰性生活
- 你的细菌就是你
- 酒店点餐系统开发详解(一)
- 搭建 Silverlight 4 开发环境
- js 高级编程-属性/变量-访问权限
- 在MFC中用WriteProfileInt等方法保存应用程序配置
- 爱你无极限
- 尝试文件安全加密
- DIV css 相对父容器 水平、垂直 居中
- 我的快餐爱情
- 犯过的错误
- dumprep.exe 进程吃掉一半CPU
- Linux中如何释放cache内存 free
- 虚拟机上的Ubuntu与宿主机上的Windows XP共享文件夹