From f66dd91046fd631db0e93f37337b038ae57c3a4c Mon Sep 17 00:00:00 2001 From: xomx Date: Tue, 13 Feb 2024 23:45:27 +0100 Subject: [PATCH] Fix Notepad++ blocked when closed minimized or from systray When Notepad++ is minimized and there are 2 or more unsaved opened files, close Notepad++ directly from the taskbar (no periodic backup) will launch modal Save All dialog, which will not be on the foreground. Hence the blocage of Notepad++. This commit fixes the issue above. Fix #14718, close #14725 --- PowerEditor/src/Notepad_plus.cpp | 17 ++++++++++++----- .../WinControls/StaticDialog/StaticDialog.cpp | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index d4d01e2cc..5a93d6ad9 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2449,13 +2449,20 @@ int Notepad_plus::doSaveOrNot(const TCHAR* fn, bool isMulti) if ((NppParameters::getInstance()).isEndSessionCritical()) return IDCANCEL; // simulate Esc-key or Cancel-button as there should not be any big delay / code-flow block - // In case Notepad++ is iconized into notification zone - if (!::IsWindowVisible(_pPublicInterface->getHSelf())) + // In case Notepad++ is minimized into taskbar or iconized into notification zone + if (::IsIconic(_pPublicInterface->getHSelf())) { - ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_RESTORE); + } + else + { + if (!::IsWindowVisible(_pPublicInterface->getHSelf())) + { + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); - // Send sizing info to make window fit (specially to show tool bar.) - ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); + // Send sizing info to make window fit (specially to show tool bar.) + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); + } } if (!isMulti) diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp index 8d3088448..c110336e3 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp @@ -79,10 +79,15 @@ void StaticDialog::goToCenter(UINT swpFlags) { RECT rc{}; ::GetClientRect(_hParent, &rc); + if ((rc.left == rc.right) || (rc.top == rc.bottom)) + swpFlags |= SWP_NOSIZE; // sizing has no sense here + POINT center{}; center.x = rc.left + (rc.right - rc.left)/2; center.y = rc.top + (rc.bottom - rc.top)/2; ::ClientToScreen(_hParent, ¢er); + if ((center.x == -32000) && (center.y == -32000)) // https://devblogs.microsoft.com/oldnewthing/20041028-00/?p=37453 + swpFlags |= SWP_NOMOVE; // moving has no sense here (owner wnd is minimized) int x = center.x - (_rc.right - _rc.left)/2; int y = center.y - (_rc.bottom - _rc.top)/2;