wordpad: Properly save window rect on closing Min/Maximized windows. Previously the window size and position was obtained in such a way that when the window is closed while minimized, it would be hidden when the program is started again. Closing a maximized window would save the size of the maximized window and use it as the normal/restored size when the program is started again.
diff --git a/programs/wordpad/registry.c b/programs/wordpad/registry.c index 28f13b9..7bf7c49 100644 --- a/programs/wordpad/registry.c +++ b/programs/wordpad/registry.c
@@ -33,6 +33,7 @@ static const WCHAR var_file[] = {'F','i','l','e','%','d',0}; static const WCHAR var_framerect[] = {'F','r','a','m','e','R','e','c','t',0}; static const WCHAR var_barstate0[] = {'B','a','r','S','t','a','t','e','0',0}; +static const WCHAR var_maximized[] = {'M','a','x','i','m','i','z','e','d',0}; static LRESULT registry_get_handle(HKEY *hKey, LPDWORD action, LPCWSTR subKey) { @@ -82,11 +83,15 @@ if(registry_get_handle(&hKey, &action, (LPWSTR)key_options) == ERROR_SUCCESS) { - RECT rc; + WINDOWPLACEMENT wp; + DWORD isMaximized; - GetWindowRect(hMainWnd, &rc); + wp.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(hMainWnd, &wp); + isMaximized = (wp.showCmd == SW_SHOWMAXIMIZED); - RegSetValueExW(hKey, var_framerect, 0, REG_BINARY, (LPBYTE)&rc, sizeof(RECT)); + RegSetValueExW(hKey, var_framerect, 0, REG_BINARY, (LPBYTE)&wp.rcNormalPosition, sizeof(RECT)); + RegSetValueExW(hKey, var_maximized, 0, REG_DWORD, (LPBYTE)&isMaximized, sizeof(DWORD)); registry_set_pagemargins(hKey); } @@ -112,6 +117,21 @@ RegCloseKey(hKey); } +void registry_read_maximized(DWORD *bMaximized) +{ + HKEY hKey; + DWORD size = sizeof(DWORD); + + if(registry_get_handle(&hKey, 0, (LPWSTR)key_options) != ERROR_SUCCESS || + RegQueryValueExW(hKey, var_maximized, 0, NULL, (LPBYTE)bMaximized, &size) != + ERROR_SUCCESS || size != sizeof(DWORD)) + { + *bMaximized = FALSE; + } + + RegCloseKey(hKey); +} + static void truncate_path(LPWSTR file, LPWSTR out, LPWSTR pos1, LPWSTR pos2) { static const WCHAR dots[] = {'.','.','.',0};