MFC 保存用户配置

void CMFCAppMoveWindowApp::InitProfile()
{
    // CMyApp is derived from CWinApp.

    LPCWSTR pszKey = L"StudentInfo";
    LPCWSTR pszName = L"Julian";
    int iAge = 26;

    // Change the registry key under which our settings are stored.

    SetRegistryKey(_T("MyAppMoveWindowApp"));
    //HKEY_CURRENT_USER\Software\MyAppMoveWindowApp\MFCAppMoveWindow\StudentInfo

    // Write the information to the registry.

    WriteProfileString(pszKey, L"Name", pszName);
    WriteProfileInt(pszKey, L"Age", iAge);

    // Read the information from the registry.

    CString strName = GetProfileString(pszKey, L"Name");
    int iAge2 = GetProfileInt(pszKey, L"Age", 0);
}

在BOOL CMFCApp::InitInstance()中调用InitProfile()

posted @ 2020-09-01 18:31  黑马网仔  阅读(237)  评论(0)    收藏  举报