[MSPAINT] Restore the main window saved show state (#5158)

Our mspaint didn't remember the maximized status of the main window. CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-03-17 07:26:44 +09:00 committed by GitHub
parent 88733bca77
commit a81f229065
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 12 deletions

View file

@ -137,7 +137,7 @@ OFNHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
/* entry point */ /* entry point */
int WINAPI 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 */ HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */ 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)); LoadString(hThisInstance, IDS_MINIATURETITLE, miniaturetitle, _countof(miniaturetitle));
/* load settings from registry */ /* load settings from registry */
registrySettings.Load(); registrySettings.Load(nCmdShow);
showMiniature = registrySettings.ShowThumbnail; showMiniature = registrySettings.ShowThumbnail;
imageModel.Crop(registrySettings.BMPWidth, registrySettings.BMPHeight); imageModel.Crop(registrySettings.BMPWidth, registrySettings.BMPHeight);
/* create main window */ /* 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); hwnd = mainWindow.Create(HWND_DESKTOP, mainWindowPos, strTitle, WS_OVERLAPPEDWINDOW);
RECT fullscreenWindowPos = {0, 0, 100, 100}; RECT fullscreenWindowPos = {0, 0, 100, 100};
@ -323,11 +323,8 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
/* placing the size boxes around the image */ /* placing the size boxes around the image */
imageArea.SendMessage(WM_SIZE, 0, 0); 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 */ /* 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 */ /* inform the system, that the main window accepts dropped files */
DragAcceptFiles(hwnd, TRUE); DragAcceptFiles(hwnd, TRUE);

View file

@ -53,7 +53,7 @@ void RegistrySettings::SetWallpaper(LPCTSTR szFileName, RegistrySettings::Wallpa
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) szFileName, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) szFileName, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
} }
void RegistrySettings::LoadPresets() void RegistrySettings::LoadPresets(INT nCmdShow)
{ {
BMPHeight = GetSystemMetrics(SM_CYSCREEN) / 2; BMPHeight = GetSystemMetrics(SM_CYSCREEN) / 2;
BMPWidth = GetSystemMetrics(SM_CXSCREEN) / 2; BMPWidth = GetSystemMetrics(SM_CXSCREEN) / 2;
@ -81,11 +81,16 @@ void RegistrySettings::LoadPresets()
strFontName = lf.lfFaceName; strFontName = lf.lfFaceName;
ZeroMemory(&WindowPlacement, sizeof(WindowPlacement)); 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; CRegKey view;
if (view.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"), KEY_READ) == ERROR_SUCCESS) if (view.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"), KEY_READ) == ERROR_SUCCESS)

View file

@ -11,7 +11,7 @@
class RegistrySettings class RegistrySettings
{ {
private: private:
void LoadPresets(); void LoadPresets(INT nCmdShow);
public: public:
DWORD BMPHeight; DWORD BMPHeight;
@ -51,7 +51,7 @@ public:
static void SetWallpaper(LPCTSTR szFileName, WallpaperStyle style); static void SetWallpaper(LPCTSTR szFileName, WallpaperStyle style);
void Load(); void Load(INT nCmdShow);
void Store(); void Store();
void SetMostRecentFile(LPCTSTR szPathName); void SetMostRecentFile(LPCTSTR szPathName);
}; };

View 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) LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
registrySettings.WindowPlacement.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(&(registrySettings.WindowPlacement)); GetWindowPlacement(&(registrySettings.WindowPlacement));
DoHtmlHelpW(NULL, NULL, HH_CLOSE_ALL, 0); DoHtmlHelpW(NULL, NULL, HH_CLOSE_ALL, 0);