SetRegistryKey的作用
生活随笔
收集整理的這篇文章主要介紹了
SetRegistryKey的作用
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
SetRegistryKey
(2011-01-30 10:47:25) 轉(zhuǎn)載▼標(biāo)簽: 雜談 | 分類(lèi):c 特殊語(yǔ)言用法 |
?
| SetRegistryKey | Causes application settings to be stored in the registryinstead of .INI files. |
?
SetRegistryKey 這個(gè)函數(shù)功能是設(shè)置MFC程序的注冊(cè)表訪問(wèn)鍵,并把讀寫(xiě) ini文件的成員函數(shù)映射到讀寫(xiě)注冊(cè)表。只要調(diào)用一下 SetRegistryKey并指定注冊(cè)表鍵值,那么下面6個(gè)成員函數(shù),就被映射到進(jìn)行注冊(cè)表讀取了~
| 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上面寫(xiě)上面6個(gè)函數(shù)是寫(xiě)到INI文件的。所以俺就忽略了其訪問(wèn)注冊(cè)表的功能。無(wú)意中看了其MFC實(shí)現(xiàn)才有所了解。
例子如下:
SetRegistryKey(_T("boli's app"));//這里是準(zhǔn)備在注冊(cè)表HKEY_CURRENT_USER\\software 下面生成一個(gè)boli's app分支~為什么說(shuō)是準(zhǔn)備呢?因?yàn)槿绻徽{(diào)用相關(guān)函數(shù),如上面提到的6個(gè)函數(shù),它是不會(huì)真正讀寫(xiě)注冊(cè)表的。具體本文最最下面的MFC實(shí)現(xiàn)摘錄。
CString strUserName,strPassword;
WriteProfileString("LogInfo","UserName",strUserName);//向注冊(cè)表HKEY_CURRENT_USER\\software\\boli's app\\LogInfo\\分支下寫(xiě)入U(xiǎn)serName 字符串行鍵值~
WriteProfileString("LogInfo","Password",strPassword);//同上~
strUserName = GetProfileString("LogInfo","UserName");//這里是讀取HKEY_CURRENT_USER\\software\\boli's app\\LogInfo\\分支下的UserName 字符串鍵值到 strUserName~
strPassword =GetProfileString("LogInfo","Password");?
如果不是在CWinApp 派生的類(lèi)中讀寫(xiě)注冊(cè)表,可以直接用:
strUserName = theApp.GetProfileString("LogInfo","UserName");
strPassword = theApp.GetProfileString("LogInfo","Password");
或?
strUserName =AfxGetApp()->GetProfileString("LogInfo","UserName");
條條大路通羅馬。
總結(jié)
以上是生活随笔為你收集整理的SetRegistryKey的作用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: vc中ASSERT()和VERIFY()
- 下一篇: 模式对话框与非模式对话框的区别