Dylan Smith : wordpad: Properly save window rect on closing Min/ Maximized windows.
Alexandre Julliard
julliard at winehq.org
Fri Jul 4 13:59:21 CDT 2008
Module: wine
Branch: master
Commit: fcaa59918189dd5f6ee872823479f80ab542561d
URL: http://source.winehq.org/git/wine.git/?a=commit;h=fcaa59918189dd5f6ee872823479f80ab542561d
Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date: Thu Jul 3 12:51:17 2008 -0400
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.
---
programs/wordpad/registry.c | 26 +++++++++++++++++++++++---
programs/wordpad/wordpad.c | 9 +++++++--
programs/wordpad/wordpad.h | 1 +
3 files changed, 31 insertions(+), 5 deletions(-)
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 key_text[] = {'T','e','x','t',0};
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 @@ void registry_set_options(HWND hMainWnd)
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 @@ void registry_read_winrect(RECT* rc)
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};
diff --git a/programs/wordpad/wordpad.c b/programs/wordpad/wordpad.c
index 0900ea3..80638c8 100644
--- a/programs/wordpad/wordpad.c
+++ b/programs/wordpad/wordpad.c
@@ -2490,7 +2490,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
return 0;
}
-int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdParagraph, int res)
+int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdParagraph, int nCmdShow)
{
INITCOMMONCONTROLSEX classes = {8, ICC_BAR_CLASSES|ICC_COOL_CLASSES|ICC_USEREX_CLASSES};
HACCEL hAccel;
@@ -2500,6 +2500,7 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdPar
UINT_PTR hPrevRulerProc;
HWND hRulerWnd;
POINTL EditPoint;
+ DWORD bMaximized;
static const WCHAR wszAccelTable[] = {'M','A','I','N','A','C','C','E','L',
'T','A','B','L','E','\0'};
@@ -2522,7 +2523,11 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdPar
registry_read_winrect(&rc);
hMainWnd = CreateWindowExW(0, wszMainWndClass, wszAppTitle, WS_CLIPCHILDREN|WS_OVERLAPPEDWINDOW,
rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, NULL, NULL, hInstance, NULL);
- ShowWindow(hMainWnd, SW_SHOWDEFAULT);
+ registry_read_maximized(&bMaximized);
+ if ((nCmdShow == SW_SHOWNORMAL || nCmdShow == SW_SHOWDEFAULT)
+ && bMaximized)
+ nCmdShow = SW_SHOWMAXIMIZED;
+ ShowWindow(hMainWnd, nCmdShow);
set_caption(NULL);
set_bar_states();
diff --git a/programs/wordpad/wordpad.h b/programs/wordpad/wordpad.h
index 42682dd..53a6c13 100644
--- a/programs/wordpad/wordpad.h
+++ b/programs/wordpad/wordpad.h
@@ -216,6 +216,7 @@ void registry_read_filelist(HWND);
void registry_read_options(void);
void registry_read_formatopts_all(DWORD[], DWORD[]);
void registry_read_winrect(RECT*);
+void registry_read_maximized(DWORD*);
void registry_set_filelist(LPCWSTR, HWND);
void registry_set_formatopts_all(DWORD[]);
void registry_set_options(HWND);
More information about the wine-cvs
mailing list