From 327068a3b453b4ea5a23b82ef8cc7f9e7f4efde6 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 19 Oct 2018 12:34:20 +0200 Subject: [PATCH 1/2] + fix: save positions: initial/default/standard --- src/Notepad3.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index 78ef06b14..6d08d9c2b 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2001,9 +2001,6 @@ LRESULT MsgEndSession(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) // Terminate file watching InstallFileWatching(NULL); - // remember window position - s_WinInfo = GetMyWindowPlacement(hwnd, NULL); - DragAcceptFiles(hwnd, true); #ifdef _EXTRA_DRAG_N_DROP_HANDLER_ RevokeDragAndDrop(pDropTarget); @@ -7095,10 +7092,12 @@ void SaveSettings(bool bSaveSettingsNow) CreateIniFile(); - if (!s_bSaveSettings && !bSaveSettingsNow) { + if (!(s_bSaveSettings || bSaveSettingsNow)) { IniSetBool(L"Settings", L"SaveSettings", s_bSaveSettings); return; } + // update window placement + s_WinInfo = GetMyWindowPlacement(Globals.hwndMain, NULL); WCHAR tchMsg[80]; GetLngString(IDS_MUI_SAVINGSETTINGS, tchMsg, COUNTOF(tchMsg)); @@ -7261,7 +7260,6 @@ void SaveSettings(bool bSaveSettingsNow) SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosX); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosY); - SaveIniSection(L"Settings", pIniSection); FreeMem(pIniSection); @@ -7270,11 +7268,6 @@ void SaveSettings(bool bSaveSettingsNow) // Scintilla Styles Style_Save(); - // update window placement - if (bSaveSettingsNow) { - s_WinInfo = GetMyWindowPlacement(Globals.hwndMain, NULL); - } - int ResX = GetSystemMetrics(SM_CXSCREEN); int ResY = GetSystemMetrics(SM_CYSCREEN); From 01120529aca16bd88d6bf142ba3cffce4959f034 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 19 Oct 2018 14:05:32 +0200 Subject: [PATCH 2/2] + fix: window restoration in case of aero snap position --- src/Dialogs.c | 16 ++++++++++++++++ src/Notepad3.c | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Dialogs.c b/src/Dialogs.c index f5a099cf2..3ee32ece5 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -2599,6 +2599,21 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) wndpl.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(hwnd, &wndpl); + // corrections in case of aero snapped position + if (SW_NORMAL == wndpl.showCmd) { + RECT rc; + GetWindowRect(hwnd, &rc); + MONITORINFO mi; + GetMonitorInfoFromRect(&rc, &mi); + LONG const width = rc.right - rc.left; + LONG const height = rc.bottom - rc.top; + rc.left -= (mi.rcWork.left - mi.rcMonitor.left); + rc.right = rc.left + width; + rc.top -= (mi.rcWork.top - mi.rcMonitor.top); + rc.bottom = rc.top + height; + wndpl.rcNormalPosition = rc; + } + WININFO wi; wi.x = wndpl.rcNormalPosition.left; wi.y = wndpl.rcNormalPosition.top; @@ -2607,6 +2622,7 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) wi.max = IsZoomed(hwnd) || (wndpl.flags & WPF_RESTORETOMAXIMIZED); wi.zoom = SciCall_GetZoom(); + // set monitor info too GetMonitorInfoFromRect(&(wndpl.rcNormalPosition), hMonitorInfo); return wi; diff --git a/src/Notepad3.c b/src/Notepad3.c index 6d08d9c2b..ae34ce51c 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -871,7 +871,7 @@ void EndWaitCursor() // _InitWindowPosition() // // -static WININFO _InitDefaultWndPos(const int flagsPos) +static WININFO _InitDefaultWndPos(const int flagsPos) { RECT rc; GetWindowRect(GetDesktopWindow(), &rc);