1. 程式人生 > >MFC登錄檔簡單快速讀寫

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");