/************************************************************************/
/* MFC操作注册表 */
/************************************************************************/
class CWinAppX : public CWinAppEx
{
public:
CWinAppX();
};
// 唯一的一个 CWinAppX 对象
CWinAppX theApp;
std::list<CString> pFilePath;
std::list<CString>::iterator ite;
/************************************************************************/
/* 将字符串写入注册表 */
/************************************************************************/
void WriteRegedit()//CMainFram析构时
{
CString strTmp;
if(pFilePath.size()>8)
pFilePath.resize(8);//重新设置文件路径个数
theApp.WriteProfileInt(L"ZhuiJinDaKaiWenJian",L"Counts",pFilePath.size());
ite= pFilePath.begin();
int i=0;
while(ite!= pFilePath.end())
{
strTmp.Format(L"%d",i+1);
theApp.WriteProfileStringW(L"ZhuiJinDaKaiWenJian",strTmp,*ite);
ite++;
i++;
}
}
/************************************************************************/
/* 将字符串从注册表读取出来 */
/************************************************************************/
void ReadRegedit()//CMainFram构造时
{
CString strTmp;
int counts= theApp.GetProfileIntW(L"ZhuiJinDaKaiWenJian",L"Counts",0);
for(int i=0;i<counts;i++)
{
strTmp.Format(L"%d",i+1);
CString str= theApp.GetProfileStringW(L"ZhuiJinDaKaiWenJian",strTmp,L"");
if(str.IsEmpty())
continue;
m_vLately.push_back(str);
}
}
【框架-MFC】MFC操作注册表
最新推荐文章于 2025-11-07 11:03:30 发布
本文介绍了一个使用MFC类库操作Windows注册表的示例。通过具体代码展示了如何将字符串写入注册表及从注册表中读取字符串的方法。此示例包括了CWinAppX类的定义,用于在应用程序退出前保存最近打开的文件路径,并在启动时读取这些路径。
1775

被折叠的 条评论
为什么被折叠?



