From 986f4e84d70cd94c523c6fbf2a1ed962e310ef3a Mon Sep 17 00:00:00 2001 From: wj32 Date: Sat, 21 May 2011 22:28:58 +0000 Subject: [PATCH] fixed incorrect handling of window positions (GetWindowPlacement and SetWindowPos don't go together well - e.g. when the taskbar is at the top of the screen) git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4202 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- 2.x/trunk/CHANGELOG.txt | 1 + 2.x/trunk/ProcessHacker/appsup.c | 8 ++++++++ 2.x/trunk/ProcessHacker/mainwnd.c | 9 +-------- 2.x/trunk/ProcessHacker/procprp.c | 10 ++-------- 2.x/trunk/ProcessHacker/thrdstk.c | 11 ++--------- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/2.x/trunk/CHANGELOG.txt b/2.x/trunk/CHANGELOG.txt index de20a0e4a..1829de0a2 100644 --- a/2.x/trunk/CHANGELOG.txt +++ b/2.x/trunk/CHANGELOG.txt @@ -5,6 +5,7 @@ Process Hacker * Added version string to peview CLR tab * FIXED: * Fixed the IPv6-related workaround causing crashes + * Incorrect handling of window positions 2.15 * NEW/IMPROVED: diff --git a/2.x/trunk/ProcessHacker/appsup.c b/2.x/trunk/ProcessHacker/appsup.c index 1311981ca..a38ca7393 100644 --- a/2.x/trunk/ProcessHacker/appsup.c +++ b/2.x/trunk/ProcessHacker/appsup.c @@ -760,10 +760,18 @@ VOID PhSaveWindowPlacementToSetting( { WINDOWPLACEMENT placement = { sizeof(placement) }; PH_RECTANGLE windowRectangle; + MONITORINFO monitorInfo = { sizeof(MONITORINFO) }; GetWindowPlacement(WindowHandle, &placement); windowRectangle = PhRectToRectangle(placement.rcNormalPosition); + // The rectangle is in workspace coordinates. Convert the values back to screen coordinates. + if (GetMonitorInfo(MonitorFromRect(&placement.rcNormalPosition, MONITOR_DEFAULTTOPRIMARY), &monitorInfo)) + { + windowRectangle.Left += monitorInfo.rcWork.left; + windowRectangle.Top += monitorInfo.rcWork.top; + } + if (PositionSettingName) PhSetIntegerPairSetting(PositionSettingName, windowRectangle.Position); if (SizeSettingName) diff --git a/2.x/trunk/ProcessHacker/mainwnd.c b/2.x/trunk/ProcessHacker/mainwnd.c index 3b192140e..33c7d99ab 100644 --- a/2.x/trunk/ProcessHacker/mainwnd.c +++ b/2.x/trunk/ProcessHacker/mainwnd.c @@ -2296,9 +2296,6 @@ VOID PhpSaveWindowState() VOID PhpSaveAllSettings() { - WINDOWPLACEMENT placement = { sizeof(placement) }; - PH_RECTANGLE windowRectangle; - PhSaveSettingsProcessTreeList(); if (ServiceTreeListLoaded) PhSaveSettingsServiceTreeList(); @@ -2307,11 +2304,7 @@ VOID PhpSaveAllSettings() PhSetIntegerSetting(L"IconMask", NotifyIconMask); PhSetIntegerSetting(L"IconNotifyMask", NotifyIconNotifyMask); - GetWindowPlacement(PhMainWndHandle, &placement); - windowRectangle = PhRectToRectangle(placement.rcNormalPosition); - - PhSetIntegerPairSetting(L"MainWindowPosition", windowRectangle.Position); - PhSetIntegerPairSetting(L"MainWindowSize", windowRectangle.Size); + PhSaveWindowPlacementToSetting(L"MainWindowPosition", L"MainWindowSize", PhMainWndHandle); PhpSaveWindowState(); diff --git a/2.x/trunk/ProcessHacker/procprp.c b/2.x/trunk/ProcessHacker/procprp.c index dc0bf84e5..a98e74a0f 100644 --- a/2.x/trunk/ProcessHacker/procprp.c +++ b/2.x/trunk/ProcessHacker/procprp.c @@ -230,19 +230,13 @@ LRESULT CALLBACK PhpPropSheetWndProc( RemoveProp(hwnd, L"LayoutManager"); { - WINDOWPLACEMENT placement = { sizeof(placement) }; - PH_RECTANGLE windowRectangle; HWND tabControl; TCITEM tabItem; - WCHAR text[32]; + WCHAR text[128]; // Save the window position and size. - GetWindowPlacement(hwnd, &placement); - windowRectangle = PhRectToRectangle(placement.rcNormalPosition); - - PhSetIntegerPairSetting(L"ProcPropPosition", windowRectangle.Position); - PhSetIntegerPairSetting(L"ProcPropSize", windowRectangle.Size); + PhSaveWindowPlacementToSetting(L"ProcPropPosition", L"ProcPropSize", hwnd); // Save the selected tab. diff --git a/2.x/trunk/ProcessHacker/thrdstk.c b/2.x/trunk/ProcessHacker/thrdstk.c index f1f6352c8..45147cad6 100644 --- a/2.x/trunk/ProcessHacker/thrdstk.c +++ b/2.x/trunk/ProcessHacker/thrdstk.c @@ -139,7 +139,6 @@ static INT_PTR CALLBACK PhpThreadStackDlgProc( PPH_STRING title; HWND lvHandle; PPH_LAYOUT_MANAGER layoutManager; - PH_INTEGER_PAIR size; threadStackContext = (PTHREAD_STACK_CONTEXT)lParam; SetProp(hwndDlg, PhMakeContextAtom(), (HANDLE)threadStackContext); @@ -183,8 +182,7 @@ static INT_PTR CALLBACK PhpThreadStackDlgProc( MinimumSize.left = 0; } - size = PhGetIntegerPairSetting(L"ThreadStackWindowSize"); - SetWindowPos(hwndDlg, NULL, 0, 0, size.X, size.Y, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER); + PhLoadWindowPlacementFromSetting(NULL, L"ThreadStackWindowSize", hwndDlg); PhCenterWindow(hwndDlg, GetParent(hwndDlg)); PhpRefreshThreadStack(threadStackContext); @@ -194,8 +192,6 @@ static INT_PTR CALLBACK PhpThreadStackDlgProc( { PPH_LAYOUT_MANAGER layoutManager; PTHREAD_STACK_CONTEXT threadStackContext; - WINDOWPLACEMENT windowPlacement = { sizeof(windowPlacement) }; - PH_RECTANGLE windowRectangle; ULONG i; layoutManager = (PPH_LAYOUT_MANAGER)GetProp(hwndDlg, L"LayoutManager"); @@ -208,10 +204,7 @@ static INT_PTR CALLBACK PhpThreadStackDlgProc( PhFree(threadStackContext->List->Items[i]); PhSaveListViewColumnsToSetting(L"ThreadStackListViewColumns", GetDlgItem(hwndDlg, IDC_LIST)); - - GetWindowPlacement(hwndDlg, &windowPlacement); - windowRectangle = PhRectToRectangle(windowPlacement.rcNormalPosition); - PhSetIntegerPairSetting(L"ThreadStackWindowSize", windowRectangle.Size); + PhSaveWindowPlacementToSetting(NULL, L"ThreadStackWindowSize", hwndDlg); RemoveProp(hwndDlg, PhMakeContextAtom()); RemoveProp(hwndDlg, L"LayoutManager");