[MSPAINT] Restore the main window saved show state (#5158)
authorKatayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
Thu, 16 Mar 2023 22:26:44 +0000 (07:26 +0900)
committerGitHub <noreply@github.com>
Thu, 16 Mar 2023 22:26:44 +0000 (07:26 +0900)
Our mspaint didn't remember the maximized status of the main window. CORE-18867

base/applications/mspaint/main.cpp
base/applications/mspaint/registry.cpp
base/applications/mspaint/registry.h
base/applications/mspaint/winproc.cpp

index 598064d..5ee34cd 100644 (file)
@@ -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);
index 1702c8d..c027fca 100644 (file)
@@ -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)
index be90c10..e7b4cc6 100644 (file)
@@ -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);
 };
index 5cb8ccc..ac96bb2 100644 (file)
@@ -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);