From ebf64835e6e57d035ac8791c997bcb37a9aa68ee Mon Sep 17 00:00:00 2001 From: Maximus5 Date: Fri, 17 Nov 2017 00:04:52 +0300 Subject: [PATCH] gh-275: Fix dialog glitches moving between monitors. --- src/ConEmu/AboutDlg.cpp | 3 +-- src/ConEmu/Attach.cpp | 3 +-- src/ConEmu/DpiAware.cpp | 17 +++++++++++++++++ src/ConEmu/DpiAware.h | 3 ++- src/ConEmu/FindDlg.cpp | 3 +-- src/ConEmu/HotkeyDlg.cpp | 2 +- src/ConEmu/OptionsClass.cpp | 9 +-------- src/ConEmu/OptionsFast.cpp | 2 +- src/ConEmu/RealConsole.cpp | 4 ++-- src/ConEmu/Recreate.cpp | 3 +-- src/ConEmu/SetPgApps.cpp | 2 +- src/ConEmu/SetPgBase.cpp | 3 +-- 12 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/ConEmu/AboutDlg.cpp b/src/ConEmu/AboutDlg.cpp index 820cdf3a3d..10f683ae14 100644 --- a/src/ConEmu/AboutDlg.cpp +++ b/src/ConEmu/AboutDlg.cpp @@ -521,8 +521,7 @@ void ConEmuAbout::OnInfo_About(LPCWSTR asPageName /*= NULL*/) { DontEnable de; - if (!mp_DpiAware) - mp_DpiAware = new CDpiForDialog(); + CDpiForDialog::Create(mp_DpiAware); HWND hParent = (ghOpWnd && IsWindowVisible(ghOpWnd)) ? ghOpWnd : ghWnd; // Modal dialog (CreateDialog) INT_PTR iRc = CDynDialog::ExecuteDialog(IDD_ABOUT, hParent, aboutProc, (LPARAM)asPageName); diff --git a/src/ConEmu/Attach.cpp b/src/ConEmu/Attach.cpp index fe0f7850b9..943cdd57be 100644 --- a/src/ConEmu/Attach.cpp +++ b/src/ConEmu/Attach.cpp @@ -125,8 +125,7 @@ void CAttachDlg::AttachDlg() return; } - if (!mp_DpiAware) - mp_DpiAware = new CDpiForDialog(); + CDpiForDialog::Create(mp_DpiAware); bool bPrev = gpConEmu->SetSkipOnFocus(true); // (CreateDialog) diff --git a/src/ConEmu/DpiAware.cpp b/src/ConEmu/DpiAware.cpp index e595adb6ef..36c93444d3 100644 --- a/src/ConEmu/DpiAware.cpp +++ b/src/ConEmu/DpiAware.cpp @@ -406,6 +406,23 @@ class CDpiForDialog - handle per-monitor dpi for our resource-based dialogs MMap*> m_Items; */ +bool CDpiForDialog::Create(CDpiForDialog*& pHelper) +{ + if (pHelper) + return true; + + // In Win10 and newly implemented PerMonitor DPI support we don't need dialog handlers anymore + if (IsWin10()) + return false; + + // Only if required + if (!CDpiAware::IsPerMonitorDpi()) + return false; + + pHelper = new CDpiForDialog(); + return (pHelper != nullptr); +} + CDpiForDialog::CDpiForDialog() { mh_Dlg = NULL; diff --git a/src/ConEmu/DpiAware.h b/src/ConEmu/DpiAware.h index 17852f2cbb..25677e69a2 100644 --- a/src/ConEmu/DpiAware.h +++ b/src/ConEmu/DpiAware.h @@ -122,8 +122,9 @@ class CDpiForDialog }; MMap*> m_Items; -public: CDpiForDialog(); +public: + static bool Create(CDpiForDialog*& pHelper); ~CDpiForDialog(); diff --git a/src/ConEmu/FindDlg.cpp b/src/ConEmu/FindDlg.cpp index 544f78b355..bb7fc4a10f 100644 --- a/src/ConEmu/FindDlg.cpp +++ b/src/ConEmu/FindDlg.cpp @@ -85,8 +85,7 @@ void CEFindDlg::FindTextDialog() gpConEmu->SkipOneAppsRelease(true); - if (!mp_DpiAware) - mp_DpiAware = new CDpiForDialog(); + CDpiForDialog::Create(mp_DpiAware); // (CreateDialog) mp_Dlg = CDynDialog::ShowDialog(IDD_FIND, ghWnd, findTextProc, 0/*Param*/); diff --git a/src/ConEmu/HotkeyDlg.cpp b/src/ConEmu/HotkeyDlg.cpp index 4e3a83a25d..f1e3000804 100644 --- a/src/ConEmu/HotkeyDlg.cpp +++ b/src/ConEmu/HotkeyDlg.cpp @@ -59,7 +59,7 @@ CHotKeyDialog::CHotKeyDialog(HWND hParent, DWORD aVkMod) m_HK.HkType = chk_User; m_HK.SetVkMod(aVkMod); - mp_DpiAware = new CDpiForDialog(); + CDpiForDialog::Create(mp_DpiAware); } CHotKeyDialog::~CHotKeyDialog() diff --git a/src/ConEmu/OptionsClass.cpp b/src/ConEmu/OptionsClass.cpp index 0666045950..70754cc8d3 100644 --- a/src/ConEmu/OptionsClass.cpp +++ b/src/ConEmu/OptionsClass.cpp @@ -1761,14 +1761,7 @@ void CSettings::Dialog(int IdShowPage /*= 0*/) // Сначала обновить DC, чтобы некрасивостей не было gpConEmu->UpdateWindowChild(NULL); - if (!gpSetCls->mp_DpiAware - #ifndef _DEBUG - && CDpiAware::IsPerMonitorDpi() - #endif - ) - { - gpSetCls->mp_DpiAware = new CDpiForDialog(); - } + CDpiForDialog::Create(gpSetCls->mp_DpiAware); wchar_t szLog[80]; _wsprintf(szLog, SKIPCOUNT(szLog) L"Creating settings dialog, IdPage=%u", IdShowPage); LogString(szLog); diff --git a/src/ConEmu/OptionsFast.cpp b/src/ConEmu/OptionsFast.cpp index 63d11bd3a9..b081e4637a 100644 --- a/src/ConEmu/OptionsFast.cpp +++ b/src/ConEmu/OptionsFast.cpp @@ -850,7 +850,7 @@ void CheckOptionsFast(LPCWSTR asTitle, SettingsLoadedFlags slfFlags) TerminateProcess(GetCurrentProcess(), CERR_FASTCONFIG_QUIT); } - gp_DpiAware = new CDpiForDialog(); + CDpiForDialog::Create(gp_DpiAware); // Modal dialog (CreateDialog) diff --git a/src/ConEmu/RealConsole.cpp b/src/ConEmu/RealConsole.cpp index 314cbf8d24..66afebb910 100644 --- a/src/ConEmu/RealConsole.cpp +++ b/src/ConEmu/RealConsole.cpp @@ -861,7 +861,7 @@ bool CRealConsole::ChangeAffinityPriority(LPCWSTR asAffinity /*= NULL*/, LPCWSTR else { DontEnable de; - mp_PriorityDpiAware = new CDpiForDialog(); + CDpiForDialog::Create(mp_PriorityDpiAware); iRc = CDynDialog::ExecuteDialog(IDD_AFFINITY, ghWnd, priorityProc, (LPARAM)this); SafeDelete(mp_PriorityDpiAware); } @@ -11354,7 +11354,7 @@ void CRealConsole::DoRenameTab() return; DontEnable de; - mp_RenameDpiAware = new CDpiForDialog(); + CDpiForDialog::Create(mp_RenameDpiAware); // Modal dialog (CreateDialog) INT_PTR iRc = CDynDialog::ExecuteDialog(IDD_RENAMETAB, ghWnd, renameProc, (LPARAM)this); if (iRc == IDOK) diff --git a/src/ConEmu/Recreate.cpp b/src/ConEmu/Recreate.cpp index 242cb8f2e1..16c7f31f20 100644 --- a/src/ConEmu/Recreate.cpp +++ b/src/ConEmu/Recreate.cpp @@ -117,8 +117,7 @@ int CRecreateDlg::RecreateDlg(RConStartArgsEx* apArgs, bool abDontAutoSelCmd /*= InitVars(); bool bPrev = gpConEmu->SetSkipOnFocus(true); - if (!mp_DpiAware) - mp_DpiAware = new CDpiForDialog(); + CDpiForDialog::Create(mp_DpiAware); // Modal dialog (CreateDialog) int nRc = CDynDialog::ExecuteDialog(IDD_RESTART, mh_Parent, RecreateDlgProc, (LPARAM)this); UNREFERENCED_PARAMETER(nRc); diff --git a/src/ConEmu/SetPgApps.cpp b/src/ConEmu/SetPgApps.cpp index 7e12ecf672..9c9413d196 100644 --- a/src/ConEmu/SetPgApps.cpp +++ b/src/ConEmu/SetPgApps.cpp @@ -680,7 +680,7 @@ bool CSetPgApps::CreateChildDlg() if (!mp_DpiDistinct2 && mp_ParentDpi) { - mp_DpiDistinct2 = new CDpiForDialog(); + CDpiForDialog::Create(mp_DpiDistinct2); mp_DpiDistinct2->Attach(mh_Child, mh_Dlg, mp_DlgDistinct2); } diff --git a/src/ConEmu/SetPgBase.cpp b/src/ConEmu/SetPgBase.cpp index adc2691666..33df521dee 100644 --- a/src/ConEmu/SetPgBase.cpp +++ b/src/ConEmu/SetPgBase.cpp @@ -100,8 +100,7 @@ void CSetPgBase::InitObject(HWND ahParent, UINT anActivateTabMsg, const CDpiForD if (apParentDpi) { - if (!mp_DpiAware) - mp_DpiAware = new CDpiForDialog(); + CDpiForDialog::Create(mp_DpiAware); mb_DpiChanged = false; } else