Index: base/applications/mspaint/main.cpp =================================================================== --- base/applications/mspaint/main.cpp (revision 72835) +++ base/applications/mspaint/main.cpp (working copy) @@ -93,7 +93,7 @@ MSG messages; /* Here messages to the application are saved */ HMENU menu; - HANDLE haccel; + HACCEL haccel; TCHAR sfnFilename[1000]; TCHAR sfnFiletitle[256]; @@ -303,7 +303,7 @@ /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage(&messages, NULL, 0, 0)) { - TranslateAccelerator(hwnd, (HACCEL) haccel, &messages); + TranslateAccelerator(hwnd, haccel, &messages); /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); Index: base/applications/mspaint/registry.cpp =================================================================== --- base/applications/mspaint/registry.cpp (revision 72835) +++ base/applications/mspaint/registry.cpp (working copy) @@ -27,6 +27,24 @@ return dwPrev; } +static void ReadFileHistory(HKEY hKey, LPCTSTR lpName, CString *pstrFile) +{ + DWORD nChars, Type; + LPTSTR pszFile; + LONG lRes; + + nChars = MAX_PATH; + pszFile = pstrFile->GetBuffer(nChars); + + lRes = RegQueryValueEx(hKey, lpName, NULL, &Type, (LPBYTE)pszFile, &nChars); + + /* Empty the file name if an error is detected */ + if (lRes != ERROR_SUCCESS || (lRes == ERROR_SUCCESS && Type != REG_SZ)) + pszFile[0] = '\0'; + + pstrFile->ReleaseBuffer(); +} + void RegistrySettings::SetWallpaper(TCHAR * FileName, DWORD dwStyle, DWORD dwTile) //FIXME: Has to be called 2x to apply the pattern (tiled/stretched) too { HKEY hDesktop; @@ -82,7 +100,9 @@ void RegistrySettings::Load() { HKEY hView; + LoadPresets(); + if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"), 0, KEY_READ | KEY_SET_VALUE, &hView) == ERROR_SUCCESS) @@ -103,27 +123,20 @@ cbData = sizeof(WINDOWPLACEMENT); RegQueryValueEx(hView, _T("WindowPlacement"), 0, NULL, (LPBYTE) &WindowPlacement, &cbData); + + RegCloseKey(hView); } - CRegKey hKey; - if (hKey.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List"), KEY_READ) == ERROR_SUCCESS) + if (RegOpenKeyEx(HKEY_CURRENT_USER, + _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List"), + 0, KEY_READ | KEY_SET_VALUE, &hView) == ERROR_SUCCESS) { - ULONG nChars = MAX_PATH; - LPTSTR pszFile1 = strFile1.GetBuffer(nChars); - hKey.QueryStringValue(_T("File1"), pszFile1, &nChars); - strFile1.ReleaseBuffer(); - nChars = MAX_PATH; - LPTSTR pszFile2 = strFile2.GetBuffer(nChars); - hKey.QueryStringValue(_T("File2"), pszFile2, &nChars); - strFile2.ReleaseBuffer(); - nChars = MAX_PATH; - LPTSTR pszFile3 = strFile3.GetBuffer(nChars); - hKey.QueryStringValue(_T("File3"), pszFile3, &nChars); - strFile3.ReleaseBuffer(); - nChars = MAX_PATH; - LPTSTR pszFile4 = strFile4.GetBuffer(nChars); - hKey.QueryStringValue(_T("File4"), pszFile4, &nChars); - strFile4.ReleaseBuffer(); + ReadFileHistory(hView, _T("File1"), &strFile1); + ReadFileHistory(hView, _T("File2"), &strFile2); + ReadFileHistory(hView, _T("File3"), &strFile3); + ReadFileHistory(hView, _T("File4"), &strFile4); + + RegCloseKey(hView); } } @@ -146,19 +159,20 @@ RegSetValueEx(hView, _T("ThumbYPos"), 0, REG_DWORD, (LPBYTE) &ThumbYPos, sizeof(DWORD)); RegSetValueEx(hView, _T("UnitSetting"), 0, REG_DWORD, (LPBYTE) &UnitSetting, sizeof(DWORD)); RegSetValueEx(hView, _T("WindowPlacement"), 0, REG_BINARY, (LPBYTE) &WindowPlacement, sizeof(WINDOWPLACEMENT)); + + RegCloseKey(hView); } - CRegKey hKey; - if (hKey.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List")) == ERROR_SUCCESS) + if (RegOpenKeyEx(HKEY_CURRENT_USER, + _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List"), + 0, KEY_READ | KEY_SET_VALUE, &hView) == ERROR_SUCCESS) { - if (!strFile1.IsEmpty()) - hKey.SetStringValue(_T("File1"), strFile1); - if (!strFile2.IsEmpty()) - hKey.SetStringValue(_T("File2"), strFile2); - if (!strFile3.IsEmpty()) - hKey.SetStringValue(_T("File3"), strFile3); - if (!strFile4.IsEmpty()) - hKey.SetStringValue(_T("File4"), strFile4); + RegSetValueEx(hView, _T("File1"), 0, REG_SZ, (LPBYTE)(LPCTSTR)strFile1, (strFile1.GetLength()+1)*sizeof(TCHAR)); + RegSetValueEx(hView, _T("File2"), 0, REG_SZ, (LPBYTE)(LPCTSTR)strFile2, (strFile2.GetLength()+1)*sizeof(TCHAR)); + RegSetValueEx(hView, _T("File3"), 0, REG_SZ, (LPBYTE)(LPCTSTR)strFile3, (strFile3.GetLength()+1)*sizeof(TCHAR)); + RegSetValueEx(hView, _T("File4"), 0, REG_SZ, (LPBYTE)(LPCTSTR)strFile4, (strFile4.GetLength()+1)*sizeof(TCHAR)); + + RegCloseKey(hView); } }