简体   繁体   中英

Try to Save user the input MFC

如何保存用户在IPAddress控件中输入的文本,以便下次打开应用程序时将其保留?什么是最好的方法?

EDIT

You may use something like:

HKEY hkey; 
CString strIP ="127.0.0.1"; 

if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\YourApp",0,KEY_WRITE,&hkey) == ERROR_SUCCESS)
{
   RegSetValueEx(hkey,"IPAddress",0,REG_SZ,(unsigned char*)strIP .GetBuffer(0),strIP .GetLength());
   RegCloseKey(hkey); 
}

for example you can save the IP adress in a file on your drive :

void CIPAdressDialogDlg::OnBnClickedOk()
{
    // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle
    // OnOK();
    BYTE field0, field1, field2, field3;
    m_Ip.GetAddress(field0, field1, field2, field3);

    CString strIp = _T("");
    strIp.Format(_T("%u.%u.%u.%u"), field0, field1, field2, field3);

    CString strFilePath = _T("C:\\test.txt");

    CFile theFile(strFilePath, CFile::modeWrite | CFile::modeCreate);
    theFile.Write(strIp, strIp.GetLength() * sizeof(TCHAR));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM