Alexandre Julliard : notepad: Fallback to default position if saved position if off-screen.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Oct 24 13:39:47 CDT 2006


Module: wine
Branch: master
Commit: cd5a04fd95f08282f93cfcbe4a4ceacc27f92d4c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=cd5a04fd95f08282f93cfcbe4a4ceacc27f92d4c

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Oct 24 12:27:28 2006 +0200

notepad: Fallback to default position if saved position if off-screen.

---

 programs/notepad/main.c |   60 ++++++++++++++++++++++++++++------------------
 programs/notepad/main.h |    5 ----
 2 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/programs/notepad/main.c b/programs/notepad/main.c
index 3ffa14b..4012c84 100644
--- a/programs/notepad/main.c
+++ b/programs/notepad/main.c
@@ -34,6 +34,7 @@ #include "notepad_res.h"
 
 NOTEPAD_GLOBALS Globals;
 static ATOM aFINDMSGSTRING;
+static RECT main_rect;
 
 static const WCHAR notepad_reg_key[] = {'S','o','f','t','w','a','r','e','\\',
                                         'M','i','c','r','o','s','o','f','t','\\','N','o','t','e','p','a','d','\0'};
@@ -111,20 +112,15 @@ static VOID NOTEPAD_SaveSettingToRegistr
                 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &disp) == ERROR_SUCCESS)
     {
         DWORD data;
-        RECT rect;
-        
-        GetWindowRect(Globals.hMainWnd, &rect);
-        Globals.iWindowPosX  = rect.left;
-        Globals.iWindowPosY  = rect.top;
-        Globals.iWindowPosDX = rect.right - rect.left;
-        Globals.iWindowPosDY = rect.bottom - rect.top;
 
-#define SET_NOTEPAD_REG(hkey, value_name, value_data) do { DWORD data = (DWORD)value_data; RegSetValueEx(hkey, value_name, 0, REG_DWORD, (LPBYTE)&data, sizeof(DWORD)); }while(0)
+        GetWindowRect(Globals.hMainWnd, &main_rect);
+
+#define SET_NOTEPAD_REG(hkey, value_name, value_data) do { DWORD data = (DWORD)(value_data); RegSetValueEx(hkey, value_name, 0, REG_DWORD, (LPBYTE)&data, sizeof(DWORD)); }while(0)
         SET_NOTEPAD_REG(hkey, value_fWrap,            Globals.bWrapLongLines);
-        SET_NOTEPAD_REG(hkey, value_iWindowPosX,      Globals.iWindowPosX);
-        SET_NOTEPAD_REG(hkey, value_iWindowPosY,      Globals.iWindowPosY);
-        SET_NOTEPAD_REG(hkey, value_iWindowPosDX,     Globals.iWindowPosDX);
-        SET_NOTEPAD_REG(hkey, value_iWindowPosDY,     Globals.iWindowPosDY);
+        SET_NOTEPAD_REG(hkey, value_iWindowPosX,      main_rect.left);
+        SET_NOTEPAD_REG(hkey, value_iWindowPosY,      main_rect.top);
+        SET_NOTEPAD_REG(hkey, value_iWindowPosDX,     main_rect.right - main_rect.left);
+        SET_NOTEPAD_REG(hkey, value_iWindowPosDY,     main_rect.bottom - main_rect.top);
         SET_NOTEPAD_REG(hkey, value_lfCharSet,        Globals.lfFont.lfCharSet);
         SET_NOTEPAD_REG(hkey, value_lfClipPrecision,  Globals.lfFont.lfClipPrecision);
         SET_NOTEPAD_REG(hkey, value_lfEscapement,     Globals.lfFont.lfEscapement);
@@ -158,15 +154,14 @@ static VOID NOTEPAD_LoadSettingFromRegis
 {
     static const WCHAR systemW[] = { 'S','y','s','t','e','m','\0' };
     HKEY hkey;
-    INT base_length;
+    INT base_length, dx, dy;
 
     base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN))?
         GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN);
 
-    Globals.iWindowPosX  = 0;
-    Globals.iWindowPosY  = 0;
-    Globals.iWindowPosDX = base_length * .95;
-    Globals.iWindowPosDY = Globals.iWindowPosDX * 3 / 4;
+    dx = base_length * .95;
+    dy = dx * 3 / 4;
+    SetRect( &main_rect, 0, 0, dx, dy );
 
     Globals.bWrapLongLines  = TRUE;
     
@@ -192,10 +187,10 @@ static VOID NOTEPAD_LoadSettingFromRegis
 
 #define QUERY_NOTEPAD_REG(hkey, value_name, ret) do { DWORD type, data; DWORD size = sizeof(DWORD); if(RegQueryValueEx(hkey, value_name, 0, &type, (LPBYTE)&data, &size) == ERROR_SUCCESS) if(type == REG_DWORD) ret = (typeof(ret))data; } while(0)
         QUERY_NOTEPAD_REG(hkey, value_fWrap,            Globals.bWrapLongLines);
-        QUERY_NOTEPAD_REG(hkey, value_iWindowPosX,      Globals.iWindowPosX);
-        QUERY_NOTEPAD_REG(hkey, value_iWindowPosY,      Globals.iWindowPosY);
-        QUERY_NOTEPAD_REG(hkey, value_iWindowPosDX,     Globals.iWindowPosDX);
-        QUERY_NOTEPAD_REG(hkey, value_iWindowPosDY,     Globals.iWindowPosDY);
+        QUERY_NOTEPAD_REG(hkey, value_iWindowPosX,      main_rect.left);
+        QUERY_NOTEPAD_REG(hkey, value_iWindowPosY,      main_rect.top);
+        QUERY_NOTEPAD_REG(hkey, value_iWindowPosDX,     dx);
+        QUERY_NOTEPAD_REG(hkey, value_iWindowPosDY,     dy);
         QUERY_NOTEPAD_REG(hkey, value_lfCharSet,        Globals.lfFont.lfCharSet);
         QUERY_NOTEPAD_REG(hkey, value_lfClipPrecision,  Globals.lfFont.lfClipPrecision);
         QUERY_NOTEPAD_REG(hkey, value_lfEscapement,     Globals.lfFont.lfEscapement);
@@ -209,6 +204,9 @@ #define QUERY_NOTEPAD_REG(hkey, value_na
         QUERY_NOTEPAD_REG(hkey, value_lfWeight,         Globals.lfFont.lfWeight);
 #undef QUERY_NOTEPAD_REG
 
+        main_rect.right = main_rect.left + dx;
+        main_rect.bottom = main_rect.top + dy;
+
         size = sizeof(DWORD);
         if(RegQueryValueEx(hkey, value_iPointSize, 0, &type, (LPBYTE)&data, &size) == ERROR_SUCCESS)
             if(type == REG_DWORD)
@@ -593,6 +591,9 @@ int PASCAL WinMain(HINSTANCE hInstance, 
     MSG        msg;
     HACCEL      hAccel;
     WNDCLASSEX class;
+    HMONITOR monitor;
+    MONITORINFO info;
+    INT x, y;
     static const WCHAR className[] = {'N','o','t','e','p','a','d',0};
     static const WCHAR winName[]   = {'N','o','t','e','p','a','d',0};
 
@@ -616,10 +617,21 @@ int PASCAL WinMain(HINSTANCE hInstance, 
 
     /* Setup windows */
 
+    monitor = MonitorFromRect( &main_rect, MONITOR_DEFAULTTOPRIMARY );
+    info.cbSize = sizeof(info);
+    GetMonitorInfoW( monitor, &info );
+
+    x = main_rect.left;
+    y = main_rect.top;
+    if (main_rect.left >= info.rcWork.right ||
+        main_rect.top >= info.rcWork.bottom ||
+        main_rect.right < info.rcWork.left ||
+        main_rect.bottom < info.rcWork.top)
+        x = y = CW_USEDEFAULT;
+
     Globals.hMainWnd =
-        CreateWindow(className, winName, WS_OVERLAPPEDWINDOW,
-                     Globals.iWindowPosX, Globals.iWindowPosY,
-                     Globals.iWindowPosDX, Globals.iWindowPosDY,
+        CreateWindow(className, winName, WS_OVERLAPPEDWINDOW, x, y,
+                     main_rect.right - main_rect.left, main_rect.bottom - main_rect.top,
                      NULL, NULL, Globals.hInstance, NULL);
     if (!Globals.hMainWnd)
     {
diff --git a/programs/notepad/main.h b/programs/notepad/main.h
index 075a248..a0c5e5e 100644
--- a/programs/notepad/main.h
+++ b/programs/notepad/main.h
@@ -45,11 +45,6 @@ typedef struct
   WCHAR   szHeader[MAX_PATH];
   WCHAR   szFooter[MAX_PATH];
 
-  INT     iWindowPosX;
-  INT     iWindowPosY;
-  INT     iWindowPosDX;
-  INT     iWindowPosDY;
-
   FINDREPLACE find;
   FINDREPLACE lastFind;
   HGLOBAL hDevMode; /* printer mode */




More information about the wine-cvs mailing list