SetRegistryKey的作用
生活随笔
收集整理的這篇文章主要介紹了
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");
條條大路通羅馬。
總結
以上是生活随笔為你收集整理的SetRegistryKey的作用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vc中ASSERT()和VERIFY()
- 下一篇: 模式对话框与非模式对话框的区别