user32/msgbox.c: Fixes bug 4217 by centering MessageBox dialogs to desktop, as Windows does

Markus Gömmel m.goemmel at compulab.de
Fri Jun 22 06:55:18 CDT 2007


>From 0d5b02c8db1f30ee2b8a7e1cf720a2cff3e7a549 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Markus_G=C3=B6mmel?= <m.goemmel at compulab.de>
Date: Fri, 22 Jun 2007 13:53:30 +0200
Subject: [PATCH] user32/msgbox.c: Fixes bug 4217 by centering MessageBox
dialogs to desktop, as Windows does

---
 dlls/user32/msgbox.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/dlls/user32/msgbox.c b/dlls/user32/msgbox.c
index fc74314..1353d6b 100644
--- a/dlls/user32/msgbox.c
+++ b/dlls/user32/msgbox.c
@@ -70,9 +70,11 @@ static HFONT MSGBOX_OnInit(HWND hwnd, LP
     HWND hItem;
     HDC hdc;
     int i, buttons;
-    int bspace, bw, bh, theight, tleft, wwidth, wheight, bpos;
+    int bspace, bw, bh, theight, tleft, wwidth, wheight, wleft, wtop, bpos;
     int borheight, borwidth, iheight, ileft, iwidth, twidth, tiheight;
     NONCLIENTMETRICSW nclm;
+    HMONITOR monitor = 0;
+    MONITORINFO mon_info;
     LPCWSTR lpszText;
     WCHAR buf[256];
 
@@ -244,9 +246,15 @@ static HFONT MSGBOX_OnInit(HWND hwnd, LP
     wwidth  = tleft + twidth + ileft + borwidth;
     wheight = 8 + tiheight + bh + borheight;
 
-    /* Resize the window */
-    SetWindowPos(hwnd, 0, 0, 0, wwidth, wheight,
-		 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
+    /* Message boxes are always desktop centered, so query desktop size and
center window */
+    monitor = MonitorFromWindow(lpmb->hwndOwner ? lpmb->hwndOwner :
GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY);
+    GetMonitorInfoW(monitor, &mon_info);
+    wleft = (mon_info.rcWork.left + mon_info.rcWork.right - wwidth) / 2;
+    wtop = (mon_info.rcWork.top + mon_info.rcWork.bottom - wheight) / 2;
+
+    /* Resize and center the window */
+    SetWindowPos(hwnd, 0, wleft, wtop, wwidth, wheight,
+		 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
 
     /* Position the icon */
     SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDICON), 0, ileft, (tiheight -
iheight) / 2, 0, 0,
-- 
1.4.3.4
-------------- next part --------------
>From 0d5b02c8db1f30ee2b8a7e1cf720a2cff3e7a549 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Markus_G=C3=B6mmel?= <m.goemmel at compulab.de>
Date: Fri, 22 Jun 2007 13:53:30 +0200
Subject: [PATCH] user32/msgbox.c: Fixes bug 4217 by centering MessageBox dialogs to desktop, as Windows does

---
 dlls/user32/msgbox.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/dlls/user32/msgbox.c b/dlls/user32/msgbox.c
index fc74314..1353d6b 100644
--- a/dlls/user32/msgbox.c
+++ b/dlls/user32/msgbox.c
@@ -70,9 +70,11 @@ static HFONT MSGBOX_OnInit(HWND hwnd, LP
     HWND hItem;
     HDC hdc;
     int i, buttons;
-    int bspace, bw, bh, theight, tleft, wwidth, wheight, bpos;
+    int bspace, bw, bh, theight, tleft, wwidth, wheight, wleft, wtop, bpos;
     int borheight, borwidth, iheight, ileft, iwidth, twidth, tiheight;
     NONCLIENTMETRICSW nclm;
+    HMONITOR monitor = 0;
+    MONITORINFO mon_info;
     LPCWSTR lpszText;
     WCHAR buf[256];
 
@@ -244,9 +246,15 @@ static HFONT MSGBOX_OnInit(HWND hwnd, LP
     wwidth  = tleft + twidth + ileft + borwidth;
     wheight = 8 + tiheight + bh + borheight;
 
-    /* Resize the window */
-    SetWindowPos(hwnd, 0, 0, 0, wwidth, wheight,
-		 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
+    /* Message boxes are always desktop centered, so query desktop size and center window */
+    monitor = MonitorFromWindow(lpmb->hwndOwner ? lpmb->hwndOwner : GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY);
+    GetMonitorInfoW(monitor, &mon_info);
+    wleft = (mon_info.rcWork.left + mon_info.rcWork.right - wwidth) / 2;
+    wtop = (mon_info.rcWork.top + mon_info.rcWork.bottom - wheight) / 2;
+
+    /* Resize and center the window */
+    SetWindowPos(hwnd, 0, wleft, wtop, wwidth, wheight,
+		 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
 
     /* Position the icon */
     SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDICON), 0, ileft, (tiheight - iheight) / 2, 0, 0,
-- 
1.4.3.4



More information about the wine-patches mailing list