From a81f229065be314c5171e8107f42ca140c5d31d8 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Fri, 17 Mar 2023 07:26:44 +0900 Subject: [PATCH] [MSPAINT] Restore the main window saved show state (#5158) Our mspaint didn't remember the maximized status of the main window. CORE-18867 --- base/applications/mspaint/main.cpp | 11 ++++------- base/applications/mspaint/registry.cpp | 11 ++++++++--- base/applications/mspaint/registry.h | 4 ++-- base/applications/mspaint/winproc.cpp | 1 + 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp index 598064d19d1..5ee34cd3240 100644 --- a/base/applications/mspaint/main.cpp +++ b/base/applications/mspaint/main.cpp @@ -137,7 +137,7 @@ OFNHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) /* entry point */ int WINAPI -_tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument, int nFunsterStil) +_tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument, INT nCmdShow) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ @@ -176,12 +176,12 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument LoadString(hThisInstance, IDS_MINIATURETITLE, miniaturetitle, _countof(miniaturetitle)); /* load settings from registry */ - registrySettings.Load(); + registrySettings.Load(nCmdShow); showMiniature = registrySettings.ShowThumbnail; imageModel.Crop(registrySettings.BMPWidth, registrySettings.BMPHeight); /* create main window */ - RECT mainWindowPos = {0, 0, 544, 375}; // FIXME: use equivalent of CW_USEDEFAULT for position + RECT mainWindowPos = registrySettings.WindowPlacement.rcNormalPosition; hwnd = mainWindow.Create(HWND_DESKTOP, mainWindowPos, strTitle, WS_OVERLAPPEDWINDOW); RECT fullscreenWindowPos = {0, 0, 100, 100}; @@ -323,11 +323,8 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument /* placing the size boxes around the image */ imageArea.SendMessage(WM_SIZE, 0, 0); - /* by moving the window, the things in WM_SIZE are done */ - mainWindow.SetWindowPlacement(&(registrySettings.WindowPlacement)); - /* Make the window visible on the screen */ - ShowWindow (hwnd, nFunsterStil); + ShowWindow(hwnd, registrySettings.WindowPlacement.showCmd); /* inform the system, that the main window accepts dropped files */ DragAcceptFiles(hwnd, TRUE); diff --git a/base/applications/mspaint/registry.cpp b/base/applications/mspaint/registry.cpp index 1702c8d2c01..c027fcac0e7 100644 --- a/base/applications/mspaint/registry.cpp +++ b/base/applications/mspaint/registry.cpp @@ -53,7 +53,7 @@ void RegistrySettings::SetWallpaper(LPCTSTR szFileName, RegistrySettings::Wallpa SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) szFileName, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); } -void RegistrySettings::LoadPresets() +void RegistrySettings::LoadPresets(INT nCmdShow) { BMPHeight = GetSystemMetrics(SM_CYSCREEN) / 2; BMPWidth = GetSystemMetrics(SM_CXSCREEN) / 2; @@ -81,11 +81,16 @@ void RegistrySettings::LoadPresets() strFontName = lf.lfFaceName; ZeroMemory(&WindowPlacement, sizeof(WindowPlacement)); + RECT& rc = WindowPlacement.rcNormalPosition; + rc.left = rc.top = CW_USEDEFAULT; + rc.right = rc.left + 544; + rc.bottom = rc.top + 375; + WindowPlacement.showCmd = nCmdShow; } -void RegistrySettings::Load() +void RegistrySettings::Load(INT nCmdShow) { - LoadPresets(); + LoadPresets(nCmdShow); CRegKey view; if (view.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"), KEY_READ) == ERROR_SUCCESS) diff --git a/base/applications/mspaint/registry.h b/base/applications/mspaint/registry.h index be90c104d9c..e7b4cc644ee 100644 --- a/base/applications/mspaint/registry.h +++ b/base/applications/mspaint/registry.h @@ -11,7 +11,7 @@ class RegistrySettings { private: - void LoadPresets(); + void LoadPresets(INT nCmdShow); public: DWORD BMPHeight; @@ -51,7 +51,7 @@ public: static void SetWallpaper(LPCTSTR szFileName, WallpaperStyle style); - void Load(); + void Load(INT nCmdShow); void Store(); void SetMostRecentFile(LPCTSTR szPathName); }; diff --git a/base/applications/mspaint/winproc.cpp b/base/applications/mspaint/winproc.cpp index 5cb8cccf379..ac96bb2cfcd 100644 --- a/base/applications/mspaint/winproc.cpp +++ b/base/applications/mspaint/winproc.cpp @@ -258,6 +258,7 @@ LRESULT CMainWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { + registrySettings.WindowPlacement.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(&(registrySettings.WindowPlacement)); DoHtmlHelpW(NULL, NULL, HH_CLOSE_ALL, 0);