SetRegistryKey的作用
SetRegistryKey
(2011-01-30 10:47:25)标签: 杂谈 | 分类:c 特殊语言用法 |
| SetRegistryKey | Causes application settings to be stored in the registryinstead of .INI files. |
SetRegistryKey 这个函数功能是设置MFC程序的注册表访问键,并把读写 ini文件的成员函数映射到读写注册表。只要调用一下 SetRegistryKey并指定注册表键值,那么下面6个成员函数,就被映射到进行注册表读取了~
| WriteProfileBinary | Writes binary data to an entry in the application's .INIfile. |
| WriteProfileInt | Writes an integer to an entry in the application's .INIfile. |
| WriteProfileString | Writes a string to an entry in the application's .INIfile. |
| GetProfileBinary | Retrieves binary data from an entry in the application's .INIfile. |
| GetProfileInt | Retrieves an integer from an entry in the application's .INIfile. |
| GetProfileString | Retrieves a string from an entry in the application's .INIfile. |
MSDN上面写上面6个函数是写到INI文件的。所以俺就忽略了其访问注册表的功能。无意中看了其MFC实现才有所了解。
例子如下:
SetRegistryKey(_T("boli's app"));//这里是准备在注册表HKEY_CURRENT_USER\\software 下面生成一个boli's app分支~为什么说是准备呢?因为如果不调用相关函数,如上面提到的6个函数,它是不会真正读写注册表的。具体本文最最下面的MFC实现摘录。
CString strUserName,strPassword;
WriteProfileString("LogInfo","UserName",strUserName);//向注册表HKEY_CURRENT_USER\\software\\boli's app\\LogInfo\\分支下写入UserName 字符串行键值~
WriteProfileString("LogInfo","Password",strPassword);//同上~
strUserName = GetProfileString("LogInfo","UserName");//这里是读取HKEY_CURRENT_USER\\software\\boli's app\\LogInfo\\分支下的UserName 字符串键值到 strUserName~
strPassword =GetProfileString("LogInfo","Password");
如果不是在CWinApp 派生的类中读写注册表,可以直接用:
strUserName = theApp.GetProfileString("LogInfo","UserName");
strPassword = theApp.GetProfileString("LogInfo","Password");
或
strUserName =AfxGetApp()->GetProfileString("LogInfo","UserName");
条条大路通罗马。
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
