From 873e7da5c304de885fa5eeb3bfd522b5b5976cf9 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Mon, 31 Aug 2020 08:53:50 +0900 Subject: [PATCH 01/23] WIP: Add support for per-monitor DPI awareness (1) --- Src/MainFrm.cpp | 8 ++++++++ Src/MainFrm.h | 1 + Src/Merge.vs2017.vcxproj | 18 ++++++++++++++++++ Src/Merge.vs2019.vcxproj | 18 ++++++++++++++++++ Src/TrDialogs.cpp | 11 +++++++++++ Src/TrDialogs.h | 3 +++ 6 files changed, 59 insertions(+) diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index 959a7464835..1945796763b 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -222,6 +222,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) ON_UPDATE_COMMAND_UI(ID_MRU_FIRST, OnUpdateNoMRUs) ON_UPDATE_COMMAND_UI(ID_NO_MRU, OnUpdateNoMRUs) ON_COMMAND(ID_ACCEL_QUIT, &CMainFrame::OnAccelQuit) + ON_MESSAGE(0x02E0/*WM_DPICHANGED*/, OnDpiChanged) //}}AFX_MSG_MAP ON_MESSAGE(WMU_CHILDFRAMEADDED, &CMainFrame::OnChildFrameAdded) ON_MESSAGE(WMU_CHILDFRAMEREMOVED, &CMainFrame::OnChildFrameRemoved) @@ -2574,6 +2575,13 @@ void CMainFrame::OnAccelQuit() SendMessage(WM_CLOSE); } +LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) +{ + int dpi = HIWORD(wParam); + RECT* const prcNewWindow = (RECT*)lParam; + return 0; +} + LRESULT CMainFrame::OnChildFrameAdded(WPARAM wParam, LPARAM lParam) { for (int i = 0; i < m_arrChild.GetSize(); ++i) diff --git a/Src/MainFrm.h b/Src/MainFrm.h index 16abd90d33b..5d87452742c 100644 --- a/Src/MainFrm.h +++ b/Src/MainFrm.h @@ -293,6 +293,7 @@ class CMainFrame : public CMDIFrameWnd afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnDestroy(); afx_msg void OnAccelQuit(); + afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); //}}AFX_MSG afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam); diff --git a/Src/Merge.vs2017.vcxproj b/Src/Merge.vs2017.vcxproj index 63d3c265e37..c9b70c87a2e 100644 --- a/Src/Merge.vs2017.vcxproj +++ b/Src/Merge.vs2017.vcxproj @@ -174,6 +174,9 @@ true true + + PerMonitorHighDPIAware + @@ -225,6 +228,9 @@ true true + + PerMonitorHighDPIAware + @@ -274,6 +280,9 @@ true false + + PerMonitorHighDPIAware + @@ -322,6 +331,9 @@ true false + + PerMonitorHighDPIAware + @@ -369,6 +381,9 @@ false false + + PerMonitorHighDPIAware + @@ -415,6 +430,9 @@ false false + + PerMonitorHighDPIAware + diff --git a/Src/Merge.vs2019.vcxproj b/Src/Merge.vs2019.vcxproj index 0bfe594a21a..23e236b6c90 100644 --- a/Src/Merge.vs2019.vcxproj +++ b/Src/Merge.vs2019.vcxproj @@ -174,6 +174,9 @@ true 5.01 + + PerMonitorHighDPIAware + @@ -225,6 +228,9 @@ true true + + PerMonitorHighDPIAware + @@ -275,6 +281,9 @@ false 5.01 + + PerMonitorHighDPIAware + @@ -324,6 +333,9 @@ false 5.01 + + PerMonitorHighDPIAware + @@ -371,6 +383,9 @@ false false + + PerMonitorHighDPIAware + @@ -417,6 +432,9 @@ false false + + PerMonitorHighDPIAware + diff --git a/Src/TrDialogs.cpp b/Src/TrDialogs.cpp index f034f848f97..a631df3f70e 100644 --- a/Src/TrDialogs.cpp +++ b/Src/TrDialogs.cpp @@ -6,6 +6,10 @@ IMPLEMENT_DYNAMIC(CTrDialog, CDialog) IMPLEMENT_DYNAMIC(CTrPropertyPage, CPropertyPage) IMPLEMENT_DYNAMIC(CTrDialogBar, CDialogBar) +BEGIN_MESSAGE_MAP(CTrDialog, CDialog) + ON_MESSAGE(0x02E0/*WM_DPICHANGED*/, OnDpiChanged) +END_MESSAGE_MAP() + void StaticDlgUtils::WildcardRemoveDuplicatePatterns(String& patterns) { size_t i = 0, j = 0, k = 0; @@ -33,6 +37,13 @@ BOOL CTrDialog::OnInitDialog() return TRUE; } +LRESULT CTrDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) +{ + int dpi = HIWORD(wParam); + RECT* const prcNewWindow = (RECT*)lParam; + return 0; +} + BOOL CTrPropertyPage::OnInitDialog() { theApp.TranslateDialog(m_hWnd); diff --git a/Src/TrDialogs.h b/Src/TrDialogs.h index de158d24fec..30228119f17 100644 --- a/Src/TrDialogs.h +++ b/Src/TrDialogs.h @@ -50,6 +50,9 @@ class CTrDialog : public CDialog, public DlgUtils explicit CTrDialog(LPCTSTR lpszTemplateName, CWnd *pParentWnd = nullptr) : CDialog(lpszTemplateName, pParentWnd) {} virtual BOOL OnInitDialog(); + + DECLARE_MESSAGE_MAP() + afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); }; class CTrPropertyPage : public CPropertyPage, public DlgUtils From 246ea44ff4dff6a52b7e219dd443faf6ff0bf2c3 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Mon, 31 Aug 2020 23:00:32 +0900 Subject: [PATCH 02/23] WIP: Add support for per-monitor DPI awareness (2) --- Src/MainFrm.cpp | 5 ++++- Src/Merge.vs2017.vcxproj | 27 +++++++++++++++++++++------ Src/Merge.vs2017.vcxproj.filters | 3 +++ Src/Merge.vs2019.vcxproj | 27 +++++++++++++++++++++------ Src/Merge.vs2019.vcxproj.filters | 3 +++ Src/TrDialogs.cpp | 5 ++++- Src/WinMergeU.manifest | 10 ++++++++++ 7 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 Src/WinMergeU.manifest diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index 1945796763b..a2ccaac4ec0 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -2578,7 +2578,10 @@ void CMainFrame::OnAccelQuit() LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { int dpi = HIWORD(wParam); - RECT* const prcNewWindow = (RECT*)lParam; + RECT* const prcNew = (RECT*)lParam; + SetWindowPos(nullptr, + prcNew->left, prcNew->top, prcNew->right - prcNew->left, prcNew->bottom - prcNew->top, + SWP_NOZORDER | SWP_NOACTIVATE); return 0; } diff --git a/Src/Merge.vs2017.vcxproj b/Src/Merge.vs2017.vcxproj index c9b70c87a2e..17ab5875e06 100644 --- a/Src/Merge.vs2017.vcxproj +++ b/Src/Merge.vs2017.vcxproj @@ -175,7 +175,9 @@ true - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -229,7 +231,9 @@ true - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -281,7 +285,9 @@ false - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -332,7 +338,9 @@ false - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -382,7 +390,9 @@ false - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -431,7 +441,9 @@ false - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -1361,6 +1373,9 @@ true + + + diff --git a/Src/Merge.vs2017.vcxproj.filters b/Src/Merge.vs2017.vcxproj.filters index c4118c96f65..5732d97f64e 100644 --- a/Src/Merge.vs2017.vcxproj.filters +++ b/Src/Merge.vs2017.vcxproj.filters @@ -1757,4 +1757,7 @@ Resource Files + + + \ No newline at end of file diff --git a/Src/Merge.vs2019.vcxproj b/Src/Merge.vs2019.vcxproj index 23e236b6c90..21f83737b5d 100644 --- a/Src/Merge.vs2019.vcxproj +++ b/Src/Merge.vs2019.vcxproj @@ -175,7 +175,9 @@ 5.01 - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -229,7 +231,9 @@ true - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -282,7 +286,9 @@ 5.01 - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -334,7 +340,9 @@ 5.01 - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -384,7 +392,9 @@ false - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -433,7 +443,9 @@ false - PerMonitorHighDPIAware + + + $(TargetName).manifest @@ -1363,6 +1375,9 @@ true + + + diff --git a/Src/Merge.vs2019.vcxproj.filters b/Src/Merge.vs2019.vcxproj.filters index c4118c96f65..5732d97f64e 100644 --- a/Src/Merge.vs2019.vcxproj.filters +++ b/Src/Merge.vs2019.vcxproj.filters @@ -1757,4 +1757,7 @@ Resource Files + + + \ No newline at end of file diff --git a/Src/TrDialogs.cpp b/Src/TrDialogs.cpp index a631df3f70e..90852e94bca 100644 --- a/Src/TrDialogs.cpp +++ b/Src/TrDialogs.cpp @@ -40,7 +40,10 @@ BOOL CTrDialog::OnInitDialog() LRESULT CTrDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) { int dpi = HIWORD(wParam); - RECT* const prcNewWindow = (RECT*)lParam; + RECT* const prcNew = (RECT*)lParam; + SetWindowPos(nullptr, + prcNew->left, prcNew->top, prcNew->right - prcNew->left, prcNew->bottom - prcNew->top, + SWP_NOZORDER | SWP_NOACTIVATE); return 0; } diff --git a/Src/WinMergeU.manifest b/Src/WinMergeU.manifest new file mode 100644 index 00000000000..466356eb27c --- /dev/null +++ b/Src/WinMergeU.manifest @@ -0,0 +1,10 @@ + + + + + True + PerMonitorV2 + + + + From 5fa531a9d99416e7d7b53a02bbac28b3f7c5481d Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Tue, 1 Sep 2020 09:10:47 +0900 Subject: [PATCH 03/23] WIP: Add support for per-monitor DPI awareness (3) --- Src/Common/BCMenu.cpp | 25 +++++++++++++------ Src/DpiUtil.h | 42 ++++++++++++++++++++++++++++++++ Src/Merge.vs2017.vcxproj | 1 + Src/Merge.vs2017.vcxproj.filters | 3 +++ Src/Merge.vs2019.vcxproj | 1 + Src/Merge.vs2019.vcxproj.filters | 3 +++ 6 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 Src/DpiUtil.h diff --git a/Src/Common/BCMenu.cpp b/Src/Common/BCMenu.cpp index 0b3823f3552..80ac00d3a3f 100644 --- a/Src/Common/BCMenu.cpp +++ b/Src/Common/BCMenu.cpp @@ -25,6 +25,7 @@ #include "stdafx.h" // Standard windows header file #include "BCMenu.h" // BCMenu class declaration +#include "DpiUtil.h" #include //SK: makes A2W and other spiffy AFX macros work #pragma comment(lib, "uxtheme.lib") @@ -569,8 +570,8 @@ void BCMenu::DrawItem_Theme(LPDRAWITEMSTRUCT lpDIS) bitmap = &m_AllImages; } - int cxSMIcon = GetSystemMetrics(SM_CXSMICON); - int cySMIcon = GetSystemMetrics(SM_CYSMICON); + int cxSMIcon = DpiUtil::GetSystemMetricsForWindow(AfxGetMainWnd(), SM_CXSMICON); + int cySMIcon = DpiUtil::GetSystemMetricsForWindow(AfxGetMainWnd(), SM_CYSMICON); if(nIconNormal != -1 && bitmap != nullptr){ CImage bitmapstandard; @@ -744,10 +745,20 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) } else{ CFont fontMenu; - NONCLIENTMETRICS nm = { sizeof NONCLIENTMETRICS }; - VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, - nm.cbSize,&nm,0)); - fontMenu.CreateFontIndirect (&nm.lfMenuFont); + if (DpiUtil::SystemParametersInfoForDpi) + { + DpiUtil::NONCLIENTMETRICS6 nm = { sizeof DpiUtil::NONCLIENTMETRICS6 }; + VERIFY(DpiUtil::SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, + nm.cbSize, &nm, 0, DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd))); + fontMenu.CreateFontIndirect (&nm.lfMenuFont); + } + else + { + NONCLIENTMETRICS nm = { sizeof NONCLIENTMETRICS }; + VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, + nm.cbSize,&nm,0)); + fontMenu.CreateFontIndirect (&nm.lfMenuFont); + } // Obtain the width of the text: CClientDC dc(AfxGetMainWnd() ? AfxGetMainWnd() : CWnd::GetDesktopWindow()); // Get device context @@ -773,7 +784,7 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) lpMIS->itemWidth = m_iconX+BCMENU_PAD+8+t.cx; else lpMIS->itemWidth = m_gutterWidth+m_textBorder+t.cx+m_arrowWidth; - int temp = GetSystemMetrics(SM_CYMENU); + int temp = DpiUtil::GetSystemMetricsForWindow(AfxGetMainWnd(), SM_CYMENU); lpMIS->itemHeight = temp>m_iconY+BCMENU_PAD ? temp : m_iconY+BCMENU_PAD; } } diff --git a/Src/DpiUtil.h b/Src/DpiUtil.h new file mode 100644 index 00000000000..f5b7de9a9a6 --- /dev/null +++ b/Src/DpiUtil.h @@ -0,0 +1,42 @@ +#pragma once + +#include + +namespace DpiUtil +{ + struct NONCLIENTMETRICS6 + { + UINT cbSize; + int iBorderWidth; + int iScrollWidth; + int iScrollHeight; + int iCaptionWidth; + int iCaptionHeight; + LOGFONTW lfCaptionFont; + int iSmCaptionWidth; + int iSmCaptionHeight; + LOGFONTW lfSmCaptionFont; + int iMenuWidth; + int iMenuHeight; + LOGFONTW lfMenuFont; + LOGFONTW lfStatusFont; + LOGFONTW lfMessageFont; + int iPaddedBorderWidth; + }; + + using GetDpiForWindowType = UINT (__stdcall*)(HWND hwnd); + using SystemParametersInfoForDpiType = BOOL(__stdcall*)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi); + using GetSystemMetricsForDpiType = int(__stdcall*)(int nIndex, UINT dpi); + + inline auto GetDpiForWindow = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"user32.dll"), "GetDpiForWindow")); + inline auto SystemParametersInfoForDpi = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"user32.dll"), "SystemParametersInfoForDpi")); + inline auto GetSystemMetricsForDpi = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"user32.dll"), "GetSystemMetricsForDpi")); + + int GetSystemMetricsForWindow(CWnd *pWnd, int nIndex) + { + if (GetSystemMetricsForDpi) + return GetSystemMetricsForDpi(nIndex, GetDpiForWindow(pWnd->m_hWnd)); + return GetSystemMetrics(nIndex); + } +} + diff --git a/Src/Merge.vs2017.vcxproj b/Src/Merge.vs2017.vcxproj index 17ab5875e06..4938736ae58 100644 --- a/Src/Merge.vs2017.vcxproj +++ b/Src/Merge.vs2017.vcxproj @@ -1144,6 +1144,7 @@ + diff --git a/Src/Merge.vs2017.vcxproj.filters b/Src/Merge.vs2017.vcxproj.filters index 5732d97f64e..7c1e9b6aa82 100644 --- a/Src/Merge.vs2017.vcxproj.filters +++ b/Src/Merge.vs2017.vcxproj.filters @@ -1647,6 +1647,9 @@ MFCGui\PropertyPages\Header Files + + Common\Header Files + diff --git a/Src/Merge.vs2019.vcxproj b/Src/Merge.vs2019.vcxproj index 21f83737b5d..8c681cd20e7 100644 --- a/Src/Merge.vs2019.vcxproj +++ b/Src/Merge.vs2019.vcxproj @@ -1146,6 +1146,7 @@ + diff --git a/Src/Merge.vs2019.vcxproj.filters b/Src/Merge.vs2019.vcxproj.filters index 5732d97f64e..7c1e9b6aa82 100644 --- a/Src/Merge.vs2019.vcxproj.filters +++ b/Src/Merge.vs2019.vcxproj.filters @@ -1647,6 +1647,9 @@ MFCGui\PropertyPages\Header Files + + Common\Header Files + From 0af5dec8917d6ed630d188b76c9fbfd62c9a6b1b Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Wed, 2 Sep 2020 10:42:43 +0900 Subject: [PATCH 04/23] WIP: Add support for per-monitor DPI awareness (4) --- Src/Common/BCMenu.cpp | 44 ++++++++++++++++++++++-------------- Src/Common/BCMenu.h | 1 + Src/Common/MDITabBar.cpp | 33 ++++++++++++++++----------- Src/Common/MDITabBar.h | 5 ++++- Src/Common/scbarcf.cpp | 4 ++-- Src/Common/scbarg.cpp | 4 ++-- Src/DirColsDlg.cpp | 3 +-- Src/DirFrame.cpp | 3 +-- Src/DpiUtil.h | 48 ++++++++++++++++++++++++++++++++++++---- Src/FileFiltersDlg.cpp | 3 +-- Src/HexMergeFrm.cpp | 4 ++-- Src/LineFiltersDlg.cpp | 3 +-- Src/MainFrm.cpp | 10 ++++++--- Src/Merge.cpp | 45 ++++++++++++++++++++++++------------- Src/Merge.h | 5 ++++- Src/MergeFrameCommon.cpp | 6 +++++ Src/MergeFrameCommon.h | 1 + Src/MergeStatusBar.cpp | 4 ++-- Src/PluginsListDlg.cpp | 4 ++-- Src/TrDialogs.cpp | 1 + Src/TrDialogs.h | 6 +++++ 21 files changed, 165 insertions(+), 72 deletions(-) diff --git a/Src/Common/BCMenu.cpp b/Src/Common/BCMenu.cpp index 80ac00d3a3f..9f25ff86200 100644 --- a/Src/Common/BCMenu.cpp +++ b/Src/Common/BCMenu.cpp @@ -170,23 +170,7 @@ BCMenu::BCMenu() m_bitmapBackgroundFlag=false; m_loadmenu=false; if (m_hTheme==nullptr && IsThemeActive()) - { - m_hTheme = OpenThemeData(nullptr, _T("MENU")); - if (m_hTheme != nullptr) - { - MARGINS marginCheckBg, marginArrow; - GetThemePartSize(m_hTheme, nullptr, MENU_POPUPCHECK, 0, nullptr, TS_TRUE, &m_sizeCheck); - GetThemeMargins(m_hTheme, nullptr, MENU_POPUPCHECK, 0, TMT_CONTENTMARGINS, nullptr, &m_marginCheck); - GetThemePartSize(m_hTheme, nullptr, MENU_POPUPSEPARATOR, 0, nullptr, TS_TRUE, &m_sizeSeparator); - GetThemeMargins(m_hTheme, nullptr, MENU_POPUPSEPARATOR, 0, TMT_SIZINGMARGINS, nullptr, &m_marginSeparator); - GetThemeMargins(m_hTheme, nullptr, MENU_POPUPCHECKBACKGROUND, 0, TMT_CONTENTMARGINS, nullptr, &marginCheckBg); - GetThemeMargins(m_hTheme, nullptr, MENU_POPUPSUBMENU, 0, TMT_CONTENTMARGINS, nullptr, &marginArrow); - GetThemeInt(m_hTheme, MENU_POPUPBACKGROUND, 0, TMT_BORDERSIZE, &m_textBorder); - m_checkBgWidth = m_marginCheck.cxLeftWidth + m_sizeCheck.cx + m_marginCheck.cxRightWidth; - m_gutterWidth = marginCheckBg.cxLeftWidth + m_checkBgWidth + marginCheckBg.cxRightWidth; - m_arrowWidth = marginArrow.cxRightWidth; - } - } + ReopenTheme(DpiUtil::GetDpiForCWnd(AfxGetMainWnd())); } @@ -219,6 +203,32 @@ void BCMenuData::SetWideString(const wchar_t *szWideString) m_szMenuText=nullptr;//set to nullptr so we need not bother about dangling non-nullptr Ptrs } +bool BCMenu::ReopenTheme(int dpi) +{ + if (!IsThemeActive()) + return false; + if (m_hTheme != nullptr) + CloseThemeData(m_hTheme); + if (DpiUtil::OpenThemeDataForDpi) + m_hTheme = DpiUtil::OpenThemeDataForDpi(nullptr, _T("MENU"), dpi); + else + m_hTheme = OpenThemeData(nullptr, _T("MENU")); + if (m_hTheme == nullptr) + return false; + MARGINS marginCheckBg, marginArrow; + GetThemePartSize(m_hTheme, nullptr, MENU_POPUPCHECK, 0, nullptr, TS_TRUE, &m_sizeCheck); + GetThemeMargins(m_hTheme, nullptr, MENU_POPUPCHECK, 0, TMT_CONTENTMARGINS, nullptr, &m_marginCheck); + GetThemePartSize(m_hTheme, nullptr, MENU_POPUPSEPARATOR, 0, nullptr, TS_TRUE, &m_sizeSeparator); + GetThemeMargins(m_hTheme, nullptr, MENU_POPUPSEPARATOR, 0, TMT_SIZINGMARGINS, nullptr, &m_marginSeparator); + GetThemeMargins(m_hTheme, nullptr, MENU_POPUPCHECKBACKGROUND, 0, TMT_CONTENTMARGINS, nullptr, &marginCheckBg); + GetThemeMargins(m_hTheme, nullptr, MENU_POPUPSUBMENU, 0, TMT_CONTENTMARGINS, nullptr, &marginArrow); + GetThemeInt(m_hTheme, MENU_POPUPBACKGROUND, 0, TMT_BORDERSIZE, &m_textBorder); + m_checkBgWidth = m_marginCheck.cxLeftWidth + m_sizeCheck.cx + m_marginCheck.cxRightWidth; + m_gutterWidth = marginCheckBg.cxLeftWidth + m_checkBgWidth + marginCheckBg.cxRightWidth; + m_arrowWidth = marginArrow.cxRightWidth; + return true; +} + bool BCMenu::IsMenu(CMenu *submenu) { return IsMenu(submenu->m_hMenu); diff --git a/Src/Common/BCMenu.h b/Src/Common/BCMenu.h index 914529ceefe..1aa7d14790c 100644 --- a/Src/Common/BCMenu.h +++ b/Src/Common/BCMenu.h @@ -129,6 +129,7 @@ class BCMenu : public CMenu virtual void MeasureItem( LPMEASUREITEMSTRUCT ); // Measure an item // Static functions used for handling menu's in the mainframe + static bool ReopenTheme(int dpi); static void UpdateMenu(CMenu *pmenu); static bool IsMenu(CMenu *submenu); static bool IsMenu(HMENU submenu); diff --git a/Src/Common/MDITabBar.cpp b/Src/Common/MDITabBar.cpp index 226bedaba03..7b85d32ba5f 100644 --- a/Src/Common/MDITabBar.cpp +++ b/Src/Common/MDITabBar.cpp @@ -6,6 +6,7 @@ #include "StdAfx.h" #include "MDITabBar.h" +#include "DpiUtil.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -31,11 +32,6 @@ BEGIN_MESSAGE_MAP(CMDITabBar, CControlBar) //}}AFX_MSG_MAP END_MESSAGE_MAP() -static int determineIconSize() -{ - return GetSystemMetrics(SM_CXSMICON); -} - /** * @brief Create tab bar. * @param pParentWnd [in] main frame window pointer @@ -48,12 +44,7 @@ BOOL CMDITabBar::Create(CMDIFrameWnd* pMainFrame) if (!CWnd::Create(WC_TABCONTROL, nullptr, WS_CHILD | WS_VISIBLE | TCS_OWNERDRAWFIXED, CRect(0, 0, 0, 0), pMainFrame, AFX_IDW_CONTROLBAR_FIRST+30)) return FALSE; - TabCtrl_SetPadding(m_hWnd, determineIconSize(), 4); - - NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS }; - SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0); - m_font.CreateFontIndirect(&ncm.lfMenuFont); - SetFont(&m_font); + UpdateFont(DpiUtil::GetDpiForCWnd(this)); return TRUE; } @@ -292,6 +283,22 @@ void CMDITabBar::UpdateTabs() } } +void CMDITabBar::UpdateFont(int dpi) +{ + if (DpiUtil::GetSystemMetricsForDpi) + m_cxSMIcon = DpiUtil::GetSystemMetricsForDpi(SM_CXSMICON, dpi); + else + m_cxSMIcon = GetSystemMetrics(SM_CXSMICON); + + TabCtrl_SetPadding(m_hWnd, m_cxSMIcon, 4); + + LOGFONT lfMenuFont; + DpiUtil::GetMenuLogFont(dpi, lfMenuFont); + m_font.DeleteObject(); + m_font.CreateFontIndirect(&lfMenuFont); + SetFont(&m_font); +} + /** * @brief Called when middle mouse button is pressed. * This function closes the tab when the middle mouse button is pressed. @@ -342,7 +349,7 @@ void CMDITabBar::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) rc.top += 3; SetTextColor(lpDraw->hDC, GetSysColor(COLOR_BTNTEXT)); } - CSize iconsize(determineIconSize(), determineIconSize()); + CSize iconsize(m_cxSMIcon, m_cxSMIcon); rc.left += iconsize.cx; SetBkMode(lpDraw->hDC, TRANSPARENT); HWND hwndFrame = reinterpret_cast(item.lParam); @@ -450,7 +457,7 @@ void CMDITabBar::OnLButtonUp(UINT nFlags, CPoint point) CRect CMDITabBar::GetCloseButtonRect(int nItem) const { CRect rc; - CSize size(determineIconSize(), determineIconSize()); + CSize size(m_cxSMIcon, m_cxSMIcon); GetItemRect(nItem, &rc); rc.left = rc.right - size.cx - 4; rc.right = rc.left + size.cx; diff --git a/Src/Common/MDITabBar.h b/Src/Common/MDITabBar.h index 2335f2d989a..c931a1b6a0f 100644 --- a/Src/Common/MDITabBar.h +++ b/Src/Common/MDITabBar.h @@ -24,12 +24,14 @@ class CMDITabBar : public CControlBar bool m_bAutoMaxWidth; int m_nDraggingTabItemIndex; CFont m_font; + int m_cxSMIcon; public: - CMDITabBar() : m_bInSelchange(false), m_pMainFrame(nullptr), m_bMouseTracking(false), m_bCloseButtonDown(false), m_bAutoMaxWidth(true), m_nDraggingTabItemIndex(-1) {} + CMDITabBar() : m_bInSelchange(false), m_pMainFrame(nullptr), m_bMouseTracking(false), m_bCloseButtonDown(false), m_bAutoMaxWidth(true), m_nDraggingTabItemIndex(-1), m_cxSMIcon(0) {} virtual ~CMDITabBar() {} BOOL Create(CMDIFrameWnd* pParentWnd); void UpdateTabs(); + void UpdateFont(int dpi); bool GetAutoMaxWidth() const { return m_bAutoMaxWidth; } void SetAutoMaxWidth(bool bAutoMaxWidth) { m_bAutoMaxWidth = bAutoMaxWidth; } @@ -71,6 +73,7 @@ class CMDITabBar : public CControlBar DECLARE_MESSAGE_MAP() private: + int determineIconSize() const; CRect GetCloseButtonRect(int nItem) const; int GetItemIndexFromPoint(CPoint pt) const; void SwapTabs(int nIndexA, int nIndexB); diff --git a/Src/Common/scbarcf.cpp b/Src/Common/scbarcf.cpp index d75b7ad8003..a0abf3a0ed5 100644 --- a/Src/Common/scbarcf.cpp +++ b/Src/Common/scbarcf.cpp @@ -28,6 +28,7 @@ #include "StdAfx.h" #include "scbarcf.h" +#include "DpiUtil.h" ///////////////////////////////////////////////////////////////////////// // CSizingControlBarCF @@ -94,8 +95,7 @@ void CSizingControlBarCF::NcPaintGripper(CDC* pDC, CRect rcClient) // compute the caption rectangle bool bHorz = IsHorzDocked(); CRect rcGrip = rcClient; - const int lpx = pDC->GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](double point) { return static_cast(point * lpx / 72); }; + auto pointToPixel = [dpi = DpiUtil::GetDpiForCWnd(this)](double point) { return static_cast(point * dpi / 72); }; CRect rcBtn(m_biHide.ptOrg, CSize(pointToPixel(m_biHide.dblBoxSize), pointToPixel(m_biHide.dblBoxSize))); if (bHorz) { // right side gripper diff --git a/Src/Common/scbarg.cpp b/Src/Common/scbarg.cpp index d7d3bee4b51..6684c49d664 100644 --- a/Src/Common/scbarg.cpp +++ b/Src/Common/scbarg.cpp @@ -30,6 +30,7 @@ // #include "StdAfx.h" +#include "DpiUtil.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -85,8 +86,7 @@ void CSizingControlBarG::NcCalcClient(LPRECT pRc, UINT nDockBarID) bool bHorz = (nDockBarID == AFX_IDW_DOCKBAR_TOP) || (nDockBarID == AFX_IDW_DOCKBAR_BOTTOM); - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](double point) { return static_cast(point * lpx / 72); }; + auto pointToPixel = [dpi = DpiUtil::GetDpiForCWnd(this)](double point) { return static_cast(point * dpi / 72); }; if (bHorz) rc.DeflateRect(pointToPixel(m_dblGripper), 0, 0, 0); diff --git a/Src/DirColsDlg.cpp b/Src/DirColsDlg.cpp index 9adda032367..1519e1cd0b9 100644 --- a/Src/DirColsDlg.cpp +++ b/Src/DirColsDlg.cpp @@ -56,8 +56,7 @@ END_MESSAGE_MAP() */ void CDirColsDlg::InitList() { - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; + auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; // Show selection across entire row. // Also enable infotips. diff --git a/Src/DirFrame.cpp b/Src/DirFrame.cpp index 22aaf121339..e3949f4eccc 100644 --- a/Src/DirFrame.cpp +++ b/Src/DirFrame.cpp @@ -112,8 +112,7 @@ int CDirFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) } String sText = _("RO"); - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; + auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; m_wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH | SBPS_NOBORDERS, 0); m_wndStatusBar.SetPaneInfo(PANE_COMPMETHOD, ID_STATUS_FILTER, 0, pointToPixel(COMPMETHOD_PANEL_WIDTH)); m_wndStatusBar.SetPaneInfo(PANE_FILTER, ID_STATUS_FILTER, 0, pointToPixel(FILTER_PANEL_WIDTH)); diff --git a/Src/DpiUtil.h b/Src/DpiUtil.h index f5b7de9a9a6..571f8103c8b 100644 --- a/Src/DpiUtil.h +++ b/Src/DpiUtil.h @@ -27,16 +27,56 @@ namespace DpiUtil using GetDpiForWindowType = UINT (__stdcall*)(HWND hwnd); using SystemParametersInfoForDpiType = BOOL(__stdcall*)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi); using GetSystemMetricsForDpiType = int(__stdcall*)(int nIndex, UINT dpi); + using OpenThemeDataForDpiType = HTHEME(__stdcall*)(HWND hwnd, LPCWSTR pszClassList, UINT dpi); - inline auto GetDpiForWindow = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"user32.dll"), "GetDpiForWindow")); - inline auto SystemParametersInfoForDpi = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"user32.dll"), "SystemParametersInfoForDpi")); - inline auto GetSystemMetricsForDpi = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"user32.dll"), "GetSystemMetricsForDpi")); + inline GetDpiForWindowType GetDpiForWindow = nullptr; + inline SystemParametersInfoForDpiType SystemParametersInfoForDpi = nullptr; + inline GetSystemMetricsForDpiType GetSystemMetricsForDpi = nullptr; + inline OpenThemeDataForDpiType OpenThemeDataForDpi = nullptr; - int GetSystemMetricsForWindow(CWnd *pWnd, int nIndex) + inline bool succeeded = []() + { + HMODULE hLibraryUser32 = GetModuleHandleW(L"user32.dll"); + if (!hLibraryUser32) + return false; + HMODULE hLibraryUxTheme = GetModuleHandleW(L"uxtheme.dll"); + if (!hLibraryUxTheme) + return false; + GetDpiForWindow = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetDpiForWindow")); + SystemParametersInfoForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "SystemParametersInfoForDpi")); + GetSystemMetricsForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetSystemMetricsForDpi")); + OpenThemeDataForDpi = reinterpret_cast(GetProcAddress(hLibraryUxTheme, "OpenThemeDataForDpi")); + return true; + }(); + + inline int GetDpiForCWnd(CWnd *pWnd) + { + if (GetDpiForWindow) + return GetDpiForWindow(pWnd->m_hWnd); + return CClientDC(pWnd).GetDeviceCaps(LOGPIXELSX); + } + + inline int GetSystemMetricsForWindow(CWnd *pWnd, int nIndex) { if (GetSystemMetricsForDpi) return GetSystemMetricsForDpi(nIndex, GetDpiForWindow(pWnd->m_hWnd)); return GetSystemMetrics(nIndex); } + + inline void GetMenuLogFont(int dpi, LOGFONT& logFont) + { + if (DpiUtil::GetSystemMetricsForDpi) + { + DpiUtil::NONCLIENTMETRICS6 ncm = { sizeof DpiUtil::NONCLIENTMETRICS6 }; + if (DpiUtil::SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof DpiUtil::NONCLIENTMETRICS6, &ncm, 0, dpi)) + logFont = ncm.lfMenuFont; + } + else + { + NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS }; + if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0)) + logFont = ncm.lfMenuFont; + } + } } diff --git a/Src/FileFiltersDlg.cpp b/Src/FileFiltersDlg.cpp index 6c50321b641..8c34d135c6c 100644 --- a/Src/FileFiltersDlg.cpp +++ b/Src/FileFiltersDlg.cpp @@ -112,8 +112,7 @@ void FileFiltersDlg::InitList() // Also enable infotips. m_listFilters.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; + auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; String title = _("Name"); m_listFilters.InsertColumn(0, title.c_str(), LVCFMT_LEFT, pointToPixel(112)); diff --git a/Src/HexMergeFrm.cpp b/Src/HexMergeFrm.cpp index 633f2012fc1..e14873fc666 100644 --- a/Src/HexMergeFrm.cpp +++ b/Src/HexMergeFrm.cpp @@ -73,8 +73,8 @@ CHexMergeFrame::~CHexMergeFrame() */ void CHexMergeFrame::CreateHexWndStatusBar(CStatusBar &wndStatusBar, CWnd *pwndPane) { - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; + auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; + wndStatusBar.Create(pwndPane, WS_CHILD|WS_VISIBLE); wndStatusBar.SetIndicators(0, 3); wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH, 0); diff --git a/Src/LineFiltersDlg.cpp b/Src/LineFiltersDlg.cpp index 03bb21e4e92..3d80d7a48bd 100644 --- a/Src/LineFiltersDlg.cpp +++ b/Src/LineFiltersDlg.cpp @@ -87,8 +87,7 @@ void LineFiltersDlg::InitList() // Also enable infotips. m_filtersList.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; + auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; String title = _("Regular expression"); m_filtersList.InsertColumn(1, title.c_str(), LVCFMT_LEFT, pointToPixel(375)); diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index a2ccaac4ec0..5691bfa94ff 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -59,8 +59,8 @@ #include "VersionInfo.h" #include "Bitmap.h" #include "CCrystalTextMarkers.h" - #include "WindowsManagerDialog.h" +#include "DpiUtil.h" using std::vector; using boost::begin; @@ -337,8 +337,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) theApp.SetIndicators(m_wndStatusBar, StatusbarIndicators, static_cast(std::size(StatusbarIndicators))); - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; + auto pointToPixel = [dpi = DpiUtil::GetDpiForCWnd(this)](int point) { return MulDiv(point, dpi, 72); }; m_wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH | SBPS_NOBORDERS, 0); m_wndStatusBar.SetPaneInfo(1, ID_STATUS_PLUGIN, 0, pointToPixel(225)); m_wndStatusBar.SetPaneInfo(2, ID_STATUS_MERGINGMODE, 0, pointToPixel(75)); @@ -2579,6 +2578,11 @@ LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { int dpi = HIWORD(wParam); RECT* const prcNew = (RECT*)lParam; + + BCMenu::ReopenTheme(dpi); + + m_wndTabBar.UpdateFont(dpi); + SetWindowPos(nullptr, prcNew->left, prcNew->top, prcNew->right - prcNew->left, prcNew->bottom - prcNew->top, SWP_NOZORDER | SWP_NOACTIVATE); diff --git a/Src/Merge.cpp b/Src/Merge.cpp index c5130614ecd..1404613b27b 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -56,6 +56,7 @@ #include "CompareStats.h" #include "TestMain.h" #include "charsets.h" // For shutdown cleanup +#include "DpiUtil.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -276,17 +277,6 @@ BOOL CMergeApp::InitInstance() FileTransform::g_UnpackerMode = static_cast(GetOptionsMgr()->GetInt(OPT_PLUGINS_UNPACKER_MODE)); FileTransform::g_PredifferMode = static_cast(GetOptionsMgr()->GetInt(OPT_PLUGINS_PREDIFFER_MODE)); - NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS }; - if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0)) - { - const int lfHeight = -MulDiv(9, CClientDC(CWnd::GetDesktopWindow()).GetDeviceCaps(LOGPIXELSY), 72); - if (abs(ncm.lfMenuFont.lfHeight) > abs(lfHeight)) - ncm.lfMenuFont.lfHeight = lfHeight; - if (wcscmp(ncm.lfMenuFont.lfFaceName, L"Meiryo") == 0 || wcscmp(ncm.lfMenuFont.lfFaceName, L"\U000030e1\U000030a4\U000030ea\U000030aa"/* "Meiryo" in Japanese */) == 0) - wcscpy_s(ncm.lfMenuFont.lfFaceName, L"Meiryo UI"); - m_fontGUI.CreateFontIndirect(&ncm.lfMenuFont); - } - if (m_pSyntaxColors != nullptr) Options::SyntaxColors::Init(GetOptionsMgr(), m_pSyntaxColors.get()); @@ -1201,13 +1191,38 @@ void CMergeApp::TranslateMenu(HMENU h) const */ void CMergeApp::TranslateDialog(HWND h) const { - CWnd *pWnd = CWnd::FromHandle(h); - pWnd->SetFont(const_cast(&m_fontGUI)); - pWnd->SendMessageToDescendants(WM_SETFONT, (WPARAM)m_fontGUI.m_hObject, MAKELPARAM(FALSE, 0), TRUE); - + const int dpi = DpiUtil::GetDpiForCWnd(CWnd::FromHandle(h)); + ChangeDialogFont(h, dpi); m_pLangDlg->TranslateDialog(h); } +void CMergeApp::ChangeDialogFont(HWND hwnd, int dpi) const +{ + CWnd *pWnd = CWnd::FromHandle(hwnd); + CFont* pFont = GetGUIFont(dpi); + pWnd->SetFont(pFont); + pWnd->SendMessageToDescendants(WM_SETFONT, (WPARAM)pFont->m_hObject, MAKELPARAM(FALSE, 0), TRUE); +} + +CFont* CMergeApp::GetGUIFont(int dpi) const +{ + auto adjustFont = [](auto& ncm, int dpi) + { + }; + if (m_mapFontGUI.find(dpi) == m_mapFontGUI.end()) + { + LOGFONT lfMenuFont; + DpiUtil::GetMenuLogFont(dpi, lfMenuFont); + const int lfHeight = -MulDiv(9, dpi, 72); + if (abs(lfMenuFont.lfHeight) > abs(lfHeight)) + lfMenuFont.lfHeight = lfHeight; + if (wcscmp(lfMenuFont.lfFaceName, L"Meiryo") == 0 || wcscmp(lfMenuFont.lfFaceName, L"\U000030e1\U000030a4\U000030ea\U000030aa"/* "Meiryo" in Japanese */) == 0) + wcscpy_s(lfMenuFont.lfFaceName, L"Meiryo UI"); + m_mapFontGUI[dpi].CreateFontIndirect(&lfMenuFont); + } + return &m_mapFontGUI[dpi]; +} + /** * @brief Load string and translate to current WinMerge GUI language */ diff --git a/Src/Merge.h b/Src/Merge.h index b5d27c6e946..69a3a6f0e57 100644 --- a/Src/Merge.h +++ b/Src/Merge.h @@ -72,6 +72,7 @@ class CMergeApp : public CWinApp void SetIndicators(CStatusBar &, const UINT *, int) const; void TranslateMenu(HMENU) const; void TranslateDialog(HWND) const; + void ChangeDialogFont(HWND hwnd, int dpi) const; String LoadString(UINT) const; bool TranslateString(const std::string&, String&) const; std::wstring LoadDialogCaption(LPCTSTR) const; @@ -152,6 +153,8 @@ class CMergeApp : public CWinApp LONG GetActiveOperations() const { return m_nActiveOperations; } //@} + CFont *GetGUIFont(int dpi) const; + //{{AFX_MSG(CMergeApp) afx_msg BOOL OnOpenRecentFile(UINT nID); afx_msg void OnAppAbout(); @@ -168,7 +171,7 @@ class CMergeApp : public CWinApp bool m_bNonInteractive; LONG m_nActiveOperations; /**< Active operations count. */ bool m_bMergingMode; /**< Merging or Edit mode */ - CFont m_fontGUI; + mutable std::map m_mapFontGUI; }; extern CMergeApp theApp; diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index 4e9861396d0..f74893bfe4a 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -8,6 +8,7 @@ #include "MergeFrameCommon.h" #include "OptionsDef.h" #include "OptionsMgr.h" +#include "DpiUtil.h" #include "Merge.h" #include <../src/mfc/afximpl.h> @@ -99,6 +100,11 @@ void CMergeFrameCommon::SetLastCompareResult(int nResult) theApp.SetLastCompareResult(nResult); } +int CMergeFrameCommon::GetDpi() +{ + return DpiUtil::GetDpiForCWnd(this); +} + void CMergeFrameCommon::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { CMDIChildWnd::OnGetMinMaxInfo(lpMMI); diff --git a/Src/MergeFrameCommon.h b/Src/MergeFrameCommon.h index 271062a2776..e3fd21483e2 100644 --- a/Src/MergeFrameCommon.h +++ b/Src/MergeFrameCommon.h @@ -17,6 +17,7 @@ class CMergeFrameCommon: public CMDIChildWnd void SaveWindowState(); void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; } void RemoveBarBorder(); + int GetDpi(); virtual BOOL IsTabbedMDIChild() { return TRUE; // https://stackoverflow.com/questions/35553955/getting-rid-of-3d-look-of-mdi-frame-window diff --git a/Src/MergeStatusBar.cpp b/Src/MergeStatusBar.cpp index e9797453aa0..215ec3f3884 100644 --- a/Src/MergeStatusBar.cpp +++ b/Src/MergeStatusBar.cpp @@ -15,6 +15,7 @@ #include "charsets.h" #include "unicoder.h" #include "SyntaxColors.h" +#include "DpiUtil.h" #include "Merge.h" #ifdef _DEBUG @@ -168,8 +169,7 @@ void CMergeStatusBar::Resize(int widths[]) // Set bottom statusbar panel widths // Kimmo - I don't know why 4 seems to be right for me int borderWidth = 4; // GetSystemMetrics(SM_CXEDGE); - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; + auto pointToPixel = [dpi = DpiUtil::GetDpiForCWnd(this)](int point) { return MulDiv(point, dpi, 72); }; for (int pane = 0; pane < m_nPanes; pane++) { diff --git a/Src/PluginsListDlg.cpp b/Src/PluginsListDlg.cpp index 815dc24ff9e..c2cff86d9c3 100644 --- a/Src/PluginsListDlg.cpp +++ b/Src/PluginsListDlg.cpp @@ -11,6 +11,7 @@ #include "Plugins.h" #include "OptionsDef.h" #include "OptionsMgr.h" +#include "DpiUtil.h" #include "Merge.h" /** @brief Location for plugins specific help to open. */ @@ -79,8 +80,7 @@ void PluginsListDlg::InitList() // Also enable infotips. m_list.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; + auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; String title = _("Name"); m_list.InsertColumn(0, title.c_str(), LVCFMT_LEFT, pointToPixel(150)); diff --git a/Src/TrDialogs.cpp b/Src/TrDialogs.cpp index 90852e94bca..c3f26f1f2ac 100644 --- a/Src/TrDialogs.cpp +++ b/Src/TrDialogs.cpp @@ -40,6 +40,7 @@ BOOL CTrDialog::OnInitDialog() LRESULT CTrDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) { int dpi = HIWORD(wParam); + theApp.ChangeDialogFont(m_hWnd, dpi); RECT* const prcNew = (RECT*)lParam; SetWindowPos(nullptr, prcNew->left, prcNew->top, prcNew->right - prcNew->left, prcNew->bottom - prcNew->top, diff --git a/Src/TrDialogs.h b/Src/TrDialogs.h index 30228119f17..51499743239 100644 --- a/Src/TrDialogs.h +++ b/Src/TrDialogs.h @@ -1,6 +1,7 @@ #pragma once #include "DDXHelper.h" +#include "DpiUtil.h" #undef GetDlgItemText #undef SetDlgItemText @@ -39,6 +40,11 @@ class DlgUtils : public StaticDlgUtils { return dlg()->SetDlgItemTextW(id, text.c_str()); } + + int GetDpi() + { + return DpiUtil::GetDpiForCWnd(dlg()); + } }; class CTrDialog : public CDialog, public DlgUtils From c8bd781876f1b45548f31382bca67d595ccd0e6b Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Fri, 4 Sep 2020 00:49:52 +0900 Subject: [PATCH 05/23] WIP: Add support for per-monitor DPI awareness (5) --- Src/AboutDlg.cpp | 31 ++++++++++++--- Src/Common/BCMenu.cpp | 18 ++++----- Src/Common/MDITabBar.cpp | 12 +++--- Src/Common/MDITabBar.h | 6 ++- Src/Common/scbarcf.cpp | 3 +- Src/Common/scbarcf.h | 2 + Src/Common/scbarg.cpp | 12 ++---- Src/Common/scbarg.h | 4 +- Src/CompareStatisticsDlg.cpp | 2 +- Src/DpiUtil.h | 67 ++++++++++++++++++++++++-------- Src/MainFrm.cpp | 10 ++--- Src/MainFrm.h | 3 +- Src/Merge.cpp | 3 +- Src/Merge.vs2017.vcxproj.filters | 2 +- Src/Merge.vs2019.vcxproj.filters | 2 +- Src/MergeFrameCommon.cpp | 5 --- Src/MergeFrameCommon.h | 5 ++- Src/MergeStatusBar.cpp | 3 +- Src/MergeStatusBar.h | 3 +- Src/OpenView.h | 2 +- Src/PluginsListDlg.cpp | 1 - Src/TrDialogs.cpp | 10 ++--- Src/TrDialogs.h | 11 ++---- 23 files changed, 126 insertions(+), 91 deletions(-) diff --git a/Src/AboutDlg.cpp b/Src/AboutDlg.cpp index ccaa8a764a7..196dd19dd03 100644 --- a/Src/AboutDlg.cpp +++ b/Src/AboutDlg.cpp @@ -61,6 +61,8 @@ class CAboutDlg::Impl : public CTrDialog afx_msg void OnBnClickedWWW(NMHDR *pNMHDR, LRESULT *pResult); private: + virtual void UpdateDpi(int dpi) override; + CAboutDlg *const m_p; ATL::CImage m_image; CFont m_font; @@ -80,12 +82,6 @@ CAboutDlg::Impl::Impl(CAboutDlg *p, CWnd* pParent /*= nullptr*/) : CTrDialog(CAboutDlg::Impl::IDD) , m_p(p) { - m_font.CreatePointFont(10 * 10, _T("Tahoma")); - LOGFONT lf = { 0 }; - lf.lfHeight = 14 * 10; - lf.lfWeight = FW_BOLD; - _tcscpy_s(lf.lfFaceName, _T("Courier New")); - m_font_gnu_ascii.CreatePointFontIndirect(&lf); } void CAboutDlg::Impl::DoDataExchange(CDataExchange* pDX) @@ -109,6 +105,8 @@ BOOL CAboutDlg::Impl::OnInitDialog() // FIXME: LoadImageFromResource() seems to fail when running on Wine 5.0. } + UpdateDpi(GetDpi()); + GetDlgItem(IDC_VERSION)->SetFont(&m_font); GetDlgItem(IDC_GNU_ASCII)->SetFont(&m_font_gnu_ascii); ::SetDlgItemTextA(m_hWnd, IDC_GNU_ASCII, gnu_ascii); @@ -168,6 +166,27 @@ void CAboutDlg::Impl::OnBnClickedWWW(NMHDR *pNMHDR, LRESULT *pResult) ShellExecute(nullptr, _T("open"), pNMLink->item.szUrl, nullptr, nullptr, SW_SHOWNORMAL); } +void CAboutDlg::Impl::UpdateDpi(int dpi) +{ + m_dpi = dpi; + + auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; + + LOGFONT lfv = { 0 }; + lfv.lfHeight = -pointToPixel(10); + lfv.lfWeight = FW_NORMAL; + _tcscpy_s(lfv.lfFaceName, _T("Tahoma")); + m_font.DeleteObject(); + m_font.CreateFontIndirect(&lfv); + + LOGFONT lf = { 0 }; + lf.lfHeight = -pointToPixel(14); + lf.lfWeight = FW_BOLD; + _tcscpy_s(lf.lfFaceName, _T("Courier New")); + m_font_gnu_ascii.DeleteObject(); + m_font_gnu_ascii.CreateFontIndirect(&lf); +} + CAboutDlg::CAboutDlg() : m_pimpl(new CAboutDlg::Impl(this)) {} CAboutDlg::~CAboutDlg() {} int CAboutDlg::DoModal() { return static_cast(m_pimpl->DoModal()); } diff --git a/Src/Common/BCMenu.cpp b/Src/Common/BCMenu.cpp index 9f25ff86200..5dd1f9ab1ad 100644 --- a/Src/Common/BCMenu.cpp +++ b/Src/Common/BCMenu.cpp @@ -170,7 +170,7 @@ BCMenu::BCMenu() m_bitmapBackgroundFlag=false; m_loadmenu=false; if (m_hTheme==nullptr && IsThemeActive()) - ReopenTheme(DpiUtil::GetDpiForCWnd(AfxGetMainWnd())); + ReopenTheme(DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd)); } @@ -209,10 +209,7 @@ bool BCMenu::ReopenTheme(int dpi) return false; if (m_hTheme != nullptr) CloseThemeData(m_hTheme); - if (DpiUtil::OpenThemeDataForDpi) - m_hTheme = DpiUtil::OpenThemeDataForDpi(nullptr, _T("MENU"), dpi); - else - m_hTheme = OpenThemeData(nullptr, _T("MENU")); + m_hTheme = DpiUtil::OpenThemeDataForDpi(nullptr, _T("MENU"), dpi); if (m_hTheme == nullptr) return false; MARGINS marginCheckBg, marginArrow; @@ -580,8 +577,9 @@ void BCMenu::DrawItem_Theme(LPDRAWITEMSTRUCT lpDIS) bitmap = &m_AllImages; } - int cxSMIcon = DpiUtil::GetSystemMetricsForWindow(AfxGetMainWnd(), SM_CXSMICON); - int cySMIcon = DpiUtil::GetSystemMetricsForWindow(AfxGetMainWnd(), SM_CYSMICON); + const int dpi = DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd); + const int cxSMIcon = DpiUtil::GetSystemMetricsForDpi(SM_CXSMICON, dpi); + const int cySMIcon = DpiUtil::GetSystemMetricsForDpi(SM_CYSMICON, dpi); if(nIconNormal != -1 && bitmap != nullptr){ CImage bitmapstandard; @@ -755,10 +753,10 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) } else{ CFont fontMenu; - if (DpiUtil::SystemParametersInfoForDpi) + if (DpiUtil::UnsafeSystemParametersInfoForDpi) { DpiUtil::NONCLIENTMETRICS6 nm = { sizeof DpiUtil::NONCLIENTMETRICS6 }; - VERIFY(DpiUtil::SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, + VERIFY(DpiUtil::UnsafeSystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, nm.cbSize, &nm, 0, DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd))); fontMenu.CreateFontIndirect (&nm.lfMenuFont); } @@ -794,7 +792,7 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) lpMIS->itemWidth = m_iconX+BCMENU_PAD+8+t.cx; else lpMIS->itemWidth = m_gutterWidth+m_textBorder+t.cx+m_arrowWidth; - int temp = DpiUtil::GetSystemMetricsForWindow(AfxGetMainWnd(), SM_CYMENU); + int temp = DpiUtil::GetSystemMetricsForDpi(SM_CYMENU, DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd)); lpMIS->itemHeight = temp>m_iconY+BCMENU_PAD ? temp : m_iconY+BCMENU_PAD; } } diff --git a/Src/Common/MDITabBar.cpp b/Src/Common/MDITabBar.cpp index 7b85d32ba5f..129bcb84191 100644 --- a/Src/Common/MDITabBar.cpp +++ b/Src/Common/MDITabBar.cpp @@ -6,7 +6,6 @@ #include "StdAfx.h" #include "MDITabBar.h" -#include "DpiUtil.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -44,7 +43,7 @@ BOOL CMDITabBar::Create(CMDIFrameWnd* pMainFrame) if (!CWnd::Create(WC_TABCONTROL, nullptr, WS_CHILD | WS_VISIBLE | TCS_OWNERDRAWFIXED, CRect(0, 0, 0, 0), pMainFrame, AFX_IDW_CONTROLBAR_FIRST+30)) return FALSE; - UpdateFont(DpiUtil::GetDpiForCWnd(this)); + UpdateDpi(GetDpi()); return TRUE; } @@ -283,12 +282,11 @@ void CMDITabBar::UpdateTabs() } } -void CMDITabBar::UpdateFont(int dpi) +void CMDITabBar::UpdateDpi(int dpi) { - if (DpiUtil::GetSystemMetricsForDpi) - m_cxSMIcon = DpiUtil::GetSystemMetricsForDpi(SM_CXSMICON, dpi); - else - m_cxSMIcon = GetSystemMetrics(SM_CXSMICON); + m_dpi = dpi; + + m_cxSMIcon = GetSystemMetrics(SM_CXSMICON); TabCtrl_SetPadding(m_hWnd, m_cxSMIcon, 4); diff --git a/Src/Common/MDITabBar.h b/Src/Common/MDITabBar.h index c931a1b6a0f..ac4f9d6af1a 100644 --- a/Src/Common/MDITabBar.h +++ b/Src/Common/MDITabBar.h @@ -6,10 +6,12 @@ */ #pragma once +#include "DpiUtil.h" + /** * @brief Class for Tab bar. */ -class CMDITabBar : public CControlBar +class CMDITabBar : public CControlBar, public DpiUtil::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CMDITabBar) @@ -31,7 +33,7 @@ class CMDITabBar : public CControlBar virtual ~CMDITabBar() {} BOOL Create(CMDIFrameWnd* pParentWnd); void UpdateTabs(); - void UpdateFont(int dpi); + virtual void UpdateDpi(int dpi) override; bool GetAutoMaxWidth() const { return m_bAutoMaxWidth; } void SetAutoMaxWidth(bool bAutoMaxWidth) { m_bAutoMaxWidth = bAutoMaxWidth; } diff --git a/Src/Common/scbarcf.cpp b/Src/Common/scbarcf.cpp index a0abf3a0ed5..d2613fdaf51 100644 --- a/Src/Common/scbarcf.cpp +++ b/Src/Common/scbarcf.cpp @@ -28,7 +28,6 @@ #include "StdAfx.h" #include "scbarcf.h" -#include "DpiUtil.h" ///////////////////////////////////////////////////////////////////////// // CSizingControlBarCF @@ -95,7 +94,7 @@ void CSizingControlBarCF::NcPaintGripper(CDC* pDC, CRect rcClient) // compute the caption rectangle bool bHorz = IsHorzDocked(); CRect rcGrip = rcClient; - auto pointToPixel = [dpi = DpiUtil::GetDpiForCWnd(this)](double point) { return static_cast(point * dpi / 72); }; + auto pointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; CRect rcBtn(m_biHide.ptOrg, CSize(pointToPixel(m_biHide.dblBoxSize), pointToPixel(m_biHide.dblBoxSize))); if (bHorz) { // right side gripper diff --git a/Src/Common/scbarcf.h b/Src/Common/scbarcf.h index 26d6eafc66c..df194d8feb6 100644 --- a/Src/Common/scbarcf.h +++ b/Src/Common/scbarcf.h @@ -32,6 +32,8 @@ ///////////////////////////////////////////////////////////////////////// // CSizingControlBarCF +#include "DpiUtil.h" + #ifndef baseCSizingControlBarCF #define baseCSizingControlBarCF CSizingControlBarG #endif diff --git a/Src/Common/scbarg.cpp b/Src/Common/scbarg.cpp index 6684c49d664..c3fa948d9f1 100644 --- a/Src/Common/scbarg.cpp +++ b/Src/Common/scbarg.cpp @@ -30,7 +30,6 @@ // #include "StdAfx.h" -#include "DpiUtil.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -86,7 +85,7 @@ void CSizingControlBarG::NcCalcClient(LPRECT pRc, UINT nDockBarID) bool bHorz = (nDockBarID == AFX_IDW_DOCKBAR_TOP) || (nDockBarID == AFX_IDW_DOCKBAR_BOTTOM); - auto pointToPixel = [dpi = DpiUtil::GetDpiForCWnd(this)](double point) { return static_cast(point * dpi / 72); }; + auto pointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; if (bHorz) rc.DeflateRect(pointToPixel(m_dblGripper), 0, 0, 0); @@ -112,8 +111,7 @@ void CSizingControlBarG::NcPaintGripper(CDC* pDC, CRect rcClient) // paints a simple "two raised lines" gripper // override this if you want a more sophisticated gripper - const int lpx = pDC->GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](double point) { return static_cast(point * lpx / 72); }; + auto pointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; CRect gripper = rcClient; CRect rcbtn(m_biHide.ptOrg, CSize(pointToPixel(m_biHide.dblBoxSize), pointToPixel(m_biHide.dblBoxSize))); bool bHorz = IsHorzDocked(); @@ -152,8 +150,7 @@ NCHITTEST_RESULT CSizingControlBarG::OnNcHitTest(CPoint point) if (nRet != HTCLIENT) return nRet; - const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](double point) { return static_cast(point * lpx / 72); }; + auto pointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; CRect rc(m_biHide.ptOrg, CSize(pointToPixel(m_biHide.dblBoxSize), pointToPixel(m_biHide.dblBoxSize))); rc.OffsetRect(rcBar.TopLeft()); if (rc.PtInRect(point)) @@ -205,8 +202,7 @@ CSCBButton::CSCBButton() void CSCBButton::Paint(CDC* pDC) { - const int lpx = pDC->GetDeviceCaps(LOGPIXELSX); - auto pointToPixel = [lpx](double point) { return static_cast(point * lpx / 72); }; + auto pointToPixel = [dpi = DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd)](double point) { return static_cast(point * dpi / 72); }; CRect rc(ptOrg, CSize(pointToPixel(dblBoxSize), pointToPixel(dblBoxSize))); if (bPushed) diff --git a/Src/Common/scbarg.h b/Src/Common/scbarg.h index 699295a7fa9..154a2a16d42 100644 --- a/Src/Common/scbarg.h +++ b/Src/Common/scbarg.h @@ -27,6 +27,8 @@ ///////////////////////////////////////////////////////////////////////// #pragma once +#include "DpiUtil.h" + // MFC 8/VS.NET 2005 has breaking change in OnNcHitTest return value #ifndef NCHITTEST_RESULT #if _MFC_VER >= 0x0800 @@ -60,7 +62,7 @@ class CSCBButton #define baseCSizingControlBarG CSizingControlBar #endif -class CSizingControlBarG : public baseCSizingControlBarG +class CSizingControlBarG : public baseCSizingControlBarG, public DpiUtil::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CSizingControlBarG); diff --git a/Src/CompareStatisticsDlg.cpp b/Src/CompareStatisticsDlg.cpp index 1671c5c1b6b..64d3d8c868c 100644 --- a/Src/CompareStatisticsDlg.cpp +++ b/Src/CompareStatisticsDlg.cpp @@ -43,7 +43,7 @@ BOOL CompareStatisticsDlg::OnInitDialog() CTrDialog::OnInitDialog(); int totalFiles = 0; int totalFolders = 0; - const int iconCX = []() { + const int iconCX = [this]() { const int cx = GetSystemMetrics(SM_CXSMICON); if (cx < 24) return 16; diff --git a/Src/DpiUtil.h b/Src/DpiUtil.h index 571f8103c8b..b77e70e999a 100644 --- a/Src/DpiUtil.h +++ b/Src/DpiUtil.h @@ -29,10 +29,10 @@ namespace DpiUtil using GetSystemMetricsForDpiType = int(__stdcall*)(int nIndex, UINT dpi); using OpenThemeDataForDpiType = HTHEME(__stdcall*)(HWND hwnd, LPCWSTR pszClassList, UINT dpi); - inline GetDpiForWindowType GetDpiForWindow = nullptr; - inline SystemParametersInfoForDpiType SystemParametersInfoForDpi = nullptr; - inline GetSystemMetricsForDpiType GetSystemMetricsForDpi = nullptr; - inline OpenThemeDataForDpiType OpenThemeDataForDpi = nullptr; + inline GetDpiForWindowType UnsafeGetDpiForWindow = nullptr; + inline SystemParametersInfoForDpiType UnsafeSystemParametersInfoForDpi = nullptr; + inline GetSystemMetricsForDpiType UnsafeGetSystemMetricsForDpi = nullptr; + inline OpenThemeDataForDpiType UnsafeOpenThemeDataForDpi = nullptr; inline bool succeeded = []() { @@ -42,33 +42,40 @@ namespace DpiUtil HMODULE hLibraryUxTheme = GetModuleHandleW(L"uxtheme.dll"); if (!hLibraryUxTheme) return false; - GetDpiForWindow = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetDpiForWindow")); - SystemParametersInfoForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "SystemParametersInfoForDpi")); - GetSystemMetricsForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetSystemMetricsForDpi")); - OpenThemeDataForDpi = reinterpret_cast(GetProcAddress(hLibraryUxTheme, "OpenThemeDataForDpi")); + UnsafeGetDpiForWindow = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetDpiForWindow")); + UnsafeSystemParametersInfoForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "SystemParametersInfoForDpi")); + UnsafeGetSystemMetricsForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetSystemMetricsForDpi")); + UnsafeOpenThemeDataForDpi = reinterpret_cast(GetProcAddress(hLibraryUxTheme, "OpenThemeDataForDpi")); return true; }(); - inline int GetDpiForCWnd(CWnd *pWnd) + inline int GetDpiForWindow(HWND hwnd) { - if (GetDpiForWindow) - return GetDpiForWindow(pWnd->m_hWnd); - return CClientDC(pWnd).GetDeviceCaps(LOGPIXELSX); + if (UnsafeGetDpiForWindow) + return UnsafeGetDpiForWindow(hwnd); + return CClientDC(CWnd::FromHandle(hwnd)).GetDeviceCaps(LOGPIXELSX); } - inline int GetSystemMetricsForWindow(CWnd *pWnd, int nIndex) + inline int GetSystemMetricsForDpi(int nIndex, int dpi) { - if (GetSystemMetricsForDpi) - return GetSystemMetricsForDpi(nIndex, GetDpiForWindow(pWnd->m_hWnd)); + if (UnsafeGetSystemMetricsForDpi) + return UnsafeGetSystemMetricsForDpi(nIndex, dpi); return GetSystemMetrics(nIndex); } + inline HTHEME OpenThemeDataForDpi(HWND hwnd, LPCWSTR pszClassList, UINT dpi) + { + if (DpiUtil::UnsafeOpenThemeDataForDpi) + return UnsafeOpenThemeDataForDpi(hwnd, pszClassList, dpi); + return OpenThemeData(hwnd, pszClassList); + } + inline void GetMenuLogFont(int dpi, LOGFONT& logFont) { - if (DpiUtil::GetSystemMetricsForDpi) + if (DpiUtil::UnsafeGetSystemMetricsForDpi) { DpiUtil::NONCLIENTMETRICS6 ncm = { sizeof DpiUtil::NONCLIENTMETRICS6 }; - if (DpiUtil::SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof DpiUtil::NONCLIENTMETRICS6, &ncm, 0, dpi)) + if (DpiUtil::UnsafeSystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof DpiUtil::NONCLIENTMETRICS6, &ncm, 0, dpi)) logFont = ncm.lfMenuFont; } else @@ -78,5 +85,31 @@ namespace DpiUtil logFont = ncm.lfMenuFont; } } + + template + class PerMonitorDpiAwareWindow + { + T* wnd() { return static_cast(this); } + public: + int GetDpi() + { + if (m_dpi == -1) + m_dpi = GetDpiForWindow(wnd()->m_hWnd); + return m_dpi; + } + + virtual void UpdateDpi(int dpi) + { + m_dpi = dpi; + } + + int GetSystemMetrics(int nIndex) + { + return GetSystemMetricsForDpi(nIndex, GetDpi()); + } + + protected: + int m_dpi = -1; + }; } diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index 5691bfa94ff..fe079c37636 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -60,7 +60,6 @@ #include "Bitmap.h" #include "CCrystalTextMarkers.h" #include "WindowsManagerDialog.h" -#include "DpiUtil.h" using std::vector; using boost::begin; @@ -337,7 +336,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) theApp.SetIndicators(m_wndStatusBar, StatusbarIndicators, static_cast(std::size(StatusbarIndicators))); - auto pointToPixel = [dpi = DpiUtil::GetDpiForCWnd(this)](int point) { return MulDiv(point, dpi, 72); }; + auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; m_wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH | SBPS_NOBORDERS, 0); m_wndStatusBar.SetPaneInfo(1, ID_STATUS_PLUGIN, 0, pointToPixel(225)); m_wndStatusBar.SetPaneInfo(2, ID_STATUS_MERGINGMODE, 0, pointToPixel(75)); @@ -2576,16 +2575,15 @@ void CMainFrame::OnAccelQuit() LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { + DefWindowProc(0x2e0/*WM_DPICHANGED*/, wParam, lParam); + int dpi = HIWORD(wParam); RECT* const prcNew = (RECT*)lParam; BCMenu::ReopenTheme(dpi); - m_wndTabBar.UpdateFont(dpi); + m_wndTabBar.UpdateDpi(dpi); - SetWindowPos(nullptr, - prcNew->left, prcNew->top, prcNew->right - prcNew->left, prcNew->bottom - prcNew->top, - SWP_NOZORDER | SWP_NOACTIVATE); return 0; } diff --git a/Src/MainFrm.h b/Src/MainFrm.h index 5d87452742c..35e82e60835 100644 --- a/Src/MainFrm.h +++ b/Src/MainFrm.h @@ -17,6 +17,7 @@ #include "PathContext.h" #include "OptionsDef.h" #include "OptionsMgr.h" +#include "DpiUtil.h" class BCMenu; class CDirView; @@ -49,7 +50,7 @@ CMainFrame * GetMainFrame(); // access to the singleton main frame object /** * @brief Frame class containing save-routines etc */ -class CMainFrame : public CMDIFrameWnd +class CMainFrame : public CMDIFrameWnd, public DpiUtil::PerMonitorDpiAwareWindow { friend CLanguageSelect; DECLARE_DYNAMIC(CMainFrame) diff --git a/Src/Merge.cpp b/Src/Merge.cpp index 1404613b27b..5b5bd240c73 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -56,7 +56,6 @@ #include "CompareStats.h" #include "TestMain.h" #include "charsets.h" // For shutdown cleanup -#include "DpiUtil.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -1191,7 +1190,7 @@ void CMergeApp::TranslateMenu(HMENU h) const */ void CMergeApp::TranslateDialog(HWND h) const { - const int dpi = DpiUtil::GetDpiForCWnd(CWnd::FromHandle(h)); + const int dpi = DpiUtil::GetDpiForWindow(h); ChangeDialogFont(h, dpi); m_pLangDlg->TranslateDialog(h); } diff --git a/Src/Merge.vs2017.vcxproj.filters b/Src/Merge.vs2017.vcxproj.filters index 7c1e9b6aa82..e9d0eee0565 100644 --- a/Src/Merge.vs2017.vcxproj.filters +++ b/Src/Merge.vs2017.vcxproj.filters @@ -1648,7 +1648,7 @@ MFCGui\PropertyPages\Header Files - Common\Header Files + MFCGui\Header Files diff --git a/Src/Merge.vs2019.vcxproj.filters b/Src/Merge.vs2019.vcxproj.filters index 7c1e9b6aa82..e9d0eee0565 100644 --- a/Src/Merge.vs2019.vcxproj.filters +++ b/Src/Merge.vs2019.vcxproj.filters @@ -1648,7 +1648,7 @@ MFCGui\PropertyPages\Header Files - Common\Header Files + MFCGui\Header Files diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index f74893bfe4a..3b0a773348b 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -100,11 +100,6 @@ void CMergeFrameCommon::SetLastCompareResult(int nResult) theApp.SetLastCompareResult(nResult); } -int CMergeFrameCommon::GetDpi() -{ - return DpiUtil::GetDpiForCWnd(this); -} - void CMergeFrameCommon::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { CMDIChildWnd::OnGetMinMaxInfo(lpMMI); diff --git a/Src/MergeFrameCommon.h b/Src/MergeFrameCommon.h index e3fd21483e2..c9c14fa4373 100644 --- a/Src/MergeFrameCommon.h +++ b/Src/MergeFrameCommon.h @@ -6,7 +6,9 @@ */ #pragma once -class CMergeFrameCommon: public CMDIChildWnd +#include "DpiUtil.h" + +class CMergeFrameCommon: public CMDIChildWnd, public DpiUtil::PerMonitorDpiAwareWindow { DECLARE_DYNCREATE(CMergeFrameCommon) public: @@ -17,7 +19,6 @@ class CMergeFrameCommon: public CMDIChildWnd void SaveWindowState(); void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; } void RemoveBarBorder(); - int GetDpi(); virtual BOOL IsTabbedMDIChild() { return TRUE; // https://stackoverflow.com/questions/35553955/getting-rid-of-3d-look-of-mdi-frame-window diff --git a/Src/MergeStatusBar.cpp b/Src/MergeStatusBar.cpp index 215ec3f3884..5e44d892339 100644 --- a/Src/MergeStatusBar.cpp +++ b/Src/MergeStatusBar.cpp @@ -15,7 +15,6 @@ #include "charsets.h" #include "unicoder.h" #include "SyntaxColors.h" -#include "DpiUtil.h" #include "Merge.h" #ifdef _DEBUG @@ -169,7 +168,7 @@ void CMergeStatusBar::Resize(int widths[]) // Set bottom statusbar panel widths // Kimmo - I don't know why 4 seems to be right for me int borderWidth = 4; // GetSystemMetrics(SM_CXEDGE); - auto pointToPixel = [dpi = DpiUtil::GetDpiForCWnd(this)](int point) { return MulDiv(point, dpi, 72); }; + auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; for (int pane = 0; pane < m_nPanes; pane++) { diff --git a/Src/MergeStatusBar.h b/Src/MergeStatusBar.h index 5e376063c4b..9d75a0d5a32 100644 --- a/Src/MergeStatusBar.h +++ b/Src/MergeStatusBar.h @@ -14,8 +14,9 @@ #include "MergeEditStatus.h" #include "OptionsDiffColors.h" #include "UnicodeString.h" +#include "DpiUtil.h" -class CMergeStatusBar : public CStatusBar +class CMergeStatusBar : public CStatusBar, public DpiUtil::PerMonitorDpiAwareWindow { public : CMergeStatusBar(); diff --git a/Src/OpenView.h b/Src/OpenView.h index aa8f42e4956..bb2fe441161 100644 --- a/Src/OpenView.h +++ b/Src/OpenView.h @@ -34,7 +34,7 @@ class DropHandler; * The dialog shows also a status of the selected paths (found/not found), * if enabled in the options (enabled by default). */ -class COpenView : public CFormView, public DlgUtils +class COpenView : public CFormView, public DlgUtils, public DpiUtil::PerMonitorDpiAwareWindow { protected: // create from serialization only COpenView(); diff --git a/Src/PluginsListDlg.cpp b/Src/PluginsListDlg.cpp index c2cff86d9c3..a9cad8f0ca7 100644 --- a/Src/PluginsListDlg.cpp +++ b/Src/PluginsListDlg.cpp @@ -11,7 +11,6 @@ #include "Plugins.h" #include "OptionsDef.h" #include "OptionsMgr.h" -#include "DpiUtil.h" #include "Merge.h" /** @brief Location for plugins specific help to open. */ diff --git a/Src/TrDialogs.cpp b/Src/TrDialogs.cpp index c3f26f1f2ac..27a88a5eddf 100644 --- a/Src/TrDialogs.cpp +++ b/Src/TrDialogs.cpp @@ -39,12 +39,10 @@ BOOL CTrDialog::OnInitDialog() LRESULT CTrDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) { - int dpi = HIWORD(wParam); - theApp.ChangeDialogFont(m_hWnd, dpi); - RECT* const prcNew = (RECT*)lParam; - SetWindowPos(nullptr, - prcNew->left, prcNew->top, prcNew->right - prcNew->left, prcNew->bottom - prcNew->top, - SWP_NOZORDER | SWP_NOACTIVATE); + DefWindowProc(0x02e0/*WM_DPICHANGED*/, wParam, lParam); + + UpdateDpi(HIWORD(wParam)); + theApp.ChangeDialogFont(m_hWnd, GetDpi()); return 0; } diff --git a/Src/TrDialogs.h b/Src/TrDialogs.h index 51499743239..88a6abe0aac 100644 --- a/Src/TrDialogs.h +++ b/Src/TrDialogs.h @@ -40,14 +40,9 @@ class DlgUtils : public StaticDlgUtils { return dlg()->SetDlgItemTextW(id, text.c_str()); } - - int GetDpi() - { - return DpiUtil::GetDpiForCWnd(dlg()); - } }; -class CTrDialog : public CDialog, public DlgUtils +class CTrDialog : public CDialog, public DlgUtils, public DpiUtil::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CTrDialog) public: @@ -61,7 +56,7 @@ class CTrDialog : public CDialog, public DlgUtils afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); }; -class CTrPropertyPage : public CPropertyPage, public DlgUtils +class CTrPropertyPage : public CPropertyPage, public DlgUtils, public DpiUtil::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CTrPropertyPage) public: @@ -74,7 +69,7 @@ class CTrPropertyPage : public CPropertyPage, public DlgUtils virtual BOOL OnInitDialog(); }; -class CTrDialogBar : public CDialogBar, public DlgUtils +class CTrDialogBar : public CDialogBar, public DlgUtils, public DpiUtil::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CTrDialogBar) public: From 1dd085b0027ed501340d56e14df7b60354f39193 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Mon, 7 Sep 2020 09:08:21 +0900 Subject: [PATCH 06/23] WIP: Add support for per-monitor DPI awareness (6) --- Externals/crystaledit/Sample/ChildFrm.cpp | 28 ++++- Externals/crystaledit/Sample/ChildFrm.h | 14 ++- Externals/crystaledit/Sample/MainFrm.cpp | 9 ++ Externals/crystaledit/Sample/MainFrm.h | 8 +- .../crystaledit/Sample/SampleStatic.manifest | 10 ++ .../Sample/SampleStatic.vs2019.vcxproj | 54 ++++++++ .../SampleStatic.vs2019.vcxproj.filters | 6 + .../crystaledit/editlib/ccrystaltextview.cpp | 15 +++ .../crystaledit/editlib/ccrystaltextview.h | 8 +- .../crystaledit/editlib/dialogs/memcombo.cpp | 19 +-- .../crystaledit/editlib/utils/DpiAware.cpp | 94 ++++++++++++++ .../crystaledit/editlib/utils/DpiAware.h | 99 +++++++++++++++ Src/AboutDlg.cpp | 38 +++--- Src/Common/BCMenu.cpp | 39 +++--- Src/Common/CMoveConstraint.cpp | 6 + Src/Common/MDITabBar.cpp | 10 +- Src/Common/MDITabBar.h | 6 +- Src/Common/MessageBoxDialog.cpp | 59 ++++++--- Src/Common/MessageBoxDialog.h | 8 +- Src/Common/PreferencesDlg.cpp | 13 +- Src/Common/SuperComboBox.cpp | 4 +- Src/Common/SuperComboBox.h | 3 +- Src/Common/scbarcf.cpp | 25 ++-- Src/Common/scbarcf.h | 2 +- Src/Common/scbarg.cpp | 43 +++---- Src/Common/scbarg.h | 4 +- Src/Common/sizecbar.cpp | 7 ++ Src/Common/sizecbar.h | 4 +- Src/DirColsDlg.cpp | 4 +- Src/DirFrame.cpp | 11 +- Src/DirView.cpp | 2 +- Src/DirView.h | 3 +- Src/DpiUtil.h | 115 ------------------ Src/EditorFilepathBar.cpp | 22 +++- Src/EditorFilepathBar.h | 4 +- Src/FileFiltersDlg.cpp | 8 +- Src/HexMergeFrm.cpp | 6 +- Src/LineFiltersDlg.cpp | 4 +- Src/MainFrm.cpp | 15 ++- Src/MainFrm.h | 18 ++- Src/Merge.cpp | 4 +- Src/Merge.vs2017.vcxproj | 3 +- Src/Merge.vs2017.vcxproj.filters | 7 +- Src/Merge.vs2019.vcxproj | 3 +- Src/Merge.vs2019.vcxproj.filters | 7 +- Src/MergeFrameCommon.cpp | 20 ++- Src/MergeFrameCommon.h | 10 +- Src/MergeStatusBar.cpp | 9 +- Src/MergeStatusBar.h | 4 +- Src/OpenView.h | 2 +- Src/PluginsListDlg.cpp | 8 +- Src/TrDialogs.cpp | 7 +- Src/TrDialogs.h | 8 +- 53 files changed, 619 insertions(+), 320 deletions(-) create mode 100644 Externals/crystaledit/Sample/SampleStatic.manifest create mode 100644 Externals/crystaledit/editlib/utils/DpiAware.cpp create mode 100644 Externals/crystaledit/editlib/utils/DpiAware.h delete mode 100644 Src/DpiUtil.h diff --git a/Externals/crystaledit/Sample/ChildFrm.cpp b/Externals/crystaledit/Sample/ChildFrm.cpp index 93a9600c23f..39b51d37e4a 100755 --- a/Externals/crystaledit/Sample/ChildFrm.cpp +++ b/Externals/crystaledit/Sample/ChildFrm.cpp @@ -18,10 +18,8 @@ static char THIS_FILE[] = __FILE__; IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd) BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd) - //{{AFX_MSG_MAP(CChildFrame) - // NOTE - the ClassWizard will add and remove mapping macros here. - // DO NOT EDIT what you see in these blocks of generated code ! - //}}AFX_MSG_MAP + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) + ON_WM_GETMINMAXINFO() END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// @@ -68,3 +66,25 @@ BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { return m_wndSplitter.Create(this, 2, 2, CSize(30, 30), pContext); } + +void CChildFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) +{ + __super::OnGetMinMaxInfo(lpMMI); + if (IsDpiChanged()) + { + CRect rc; + CFrameWnd* pFrameWnd = GetParentFrame(); + pFrameWnd->GetClientRect(rc); + AdjustWindowRectEx(&rc, GetStyle(), FALSE, GetExStyle()); + lpMMI->ptMaxPosition.x = rc.left; + lpMMI->ptMaxPosition.y = rc.top; + lpMMI->ptMaxSize.x = rc.right - rc.left; + lpMMI->ptMaxSize.y = rc.bottom - rc.top; + } +} + +LRESULT CChildFrame::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) +{ + UpdateDpi(); + return 0; +} diff --git a/Externals/crystaledit/Sample/ChildFrm.h b/Externals/crystaledit/Sample/ChildFrm.h index 0c578b39dd0..462c763386e 100755 --- a/Externals/crystaledit/Sample/ChildFrm.h +++ b/Externals/crystaledit/Sample/ChildFrm.h @@ -4,7 +4,9 @@ #pragma once -class CChildFrame : public CMDIChildWnd +#include "utils/DpiAware.h" + +class CChildFrame : public CMDIChildWnd, DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNCREATE(CChildFrame) public: @@ -24,6 +26,9 @@ class CChildFrame : public CMDIChildWnd virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext); + virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) { + CalcWindowRectImpl(lpClientRect, nAdjustType); + } //}}AFX_VIRTUAL // Implementation @@ -36,11 +41,10 @@ class CChildFrame : public CMDIChildWnd // Generated message map functions protected: - //{{AFX_MSG(CChildFrame) - // NOTE - the ClassWizard will add and remove member functions here. - // DO NOT EDIT what you see in these blocks of generated code! - //}}AFX_MSG DECLARE_MESSAGE_MAP() +public: + afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam); }; ///////////////////////////////////////////////////////////////////////////// diff --git a/Externals/crystaledit/Sample/MainFrm.cpp b/Externals/crystaledit/Sample/MainFrm.cpp index f7a32b3ea59..9e50d5547f8 100755 --- a/Externals/crystaledit/Sample/MainFrm.cpp +++ b/Externals/crystaledit/Sample/MainFrm.cpp @@ -23,6 +23,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code ! ON_WM_CREATE() + ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -86,6 +87,14 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) return 0; } +LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) +{ + UpdateDpi(); + DpiAware::UpdateAfxDataSysMetrics(GetDpi()); + Default(); + return 0; +} + BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying diff --git a/Externals/crystaledit/Sample/MainFrm.h b/Externals/crystaledit/Sample/MainFrm.h index d61f75af127..90730d68995 100755 --- a/Externals/crystaledit/Sample/MainFrm.h +++ b/Externals/crystaledit/Sample/MainFrm.h @@ -4,7 +4,9 @@ #pragma once -class CMainFrame : public CMDIFrameWnd +#include "utils/DpiAware.h" + +class CMainFrame : public CMDIFrameWnd, DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CMainFrame) public: @@ -21,6 +23,9 @@ class CMainFrame : public CMDIFrameWnd //{{AFX_VIRTUAL(CMainFrame) virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_VIRTUAL + virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) { + CalcWindowRectImpl(lpClientRect, nAdjustType); + } // Implementation public: @@ -41,6 +46,7 @@ class CMainFrame : public CMDIFrameWnd // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG + afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() }; diff --git a/Externals/crystaledit/Sample/SampleStatic.manifest b/Externals/crystaledit/Sample/SampleStatic.manifest new file mode 100644 index 00000000000..466356eb27c --- /dev/null +++ b/Externals/crystaledit/Sample/SampleStatic.manifest @@ -0,0 +1,10 @@ + + + + + True + PerMonitorV2 + + + + diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj index 89522b6f6b3..bbf82dacea7 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj +++ b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj @@ -186,10 +186,17 @@ false MachineX86 + 5.01 true + + SampleStatic.manifest + + + + @@ -230,6 +237,12 @@ true + + SampleStatic.manifest + + + + @@ -267,10 +280,17 @@ false MachineX86 + 5.01 true + + SampleStatic.manifest + + + + @@ -312,6 +332,12 @@ true + + SampleStatic.manifest + + + + @@ -349,10 +375,17 @@ false MachineX86 + 5.01 true + + SampleStatic.manifest + + + + @@ -394,6 +427,12 @@ true + + SampleStatic.manifest + + + + @@ -432,10 +471,17 @@ false MachineX86 + 5.01 true + + SampleStatic.manifest + + + + @@ -478,6 +524,12 @@ true + + SampleStatic.manifest + + + + @@ -507,6 +559,7 @@ + @@ -585,6 +638,7 @@ + diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters index 719da67fde7..9d9f9036571 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters +++ b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters @@ -252,6 +252,9 @@ editlib\dialogs + + editlib\utils + @@ -379,6 +382,9 @@ editlib\dialogs + + editlib\utils + diff --git a/Externals/crystaledit/editlib/ccrystaltextview.cpp b/Externals/crystaledit/editlib/ccrystaltextview.cpp index 76405b17892..516bdbac67c 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview.cpp @@ -269,6 +269,7 @@ ON_COMMAND (ID_FORCE_REDRAW, OnForceRedraw) ON_UPDATE_COMMAND_UI(ID_EDIT_FIND_INCREMENTAL_BACKWARD, OnUpdateEditFindIncrementalBackward) //END SW ON_COMMAND (ID_EDIT_TOGGLE_COLUMNSELECTION, OnToggleColumnSelection) + ON_MESSAGE (WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP () #define EXPAND_PRIMITIVE(impl, func) \ @@ -3224,6 +3225,7 @@ void CCrystalTextView:: OnInitialUpdate () { CView::OnInitialUpdate (); + UpdateDpi (); CString sDoc = GetDocument ()->GetPathName (), sExt = GetExt (sDoc); if (!sExt.IsEmpty()) SetTextType (sExt); @@ -6742,6 +6744,19 @@ OnToggleColumnSelection () Invalidate (); } +LRESULT CCrystalTextView:: +OnDpiChangedBeforeParent (WPARAM wParam, LPARAM lParam) +{ + const int oldDpi = m_dpi; + UpdateDpi (); + if (m_dpi != oldDpi) + { + m_lfBaseFont.lfHeight = MulDiv(m_lfBaseFont.lfHeight, m_dpi, oldDpi); + SetFont (m_lfBaseFont); + } + return 0; +} + void CCrystalTextView::SetRenderingMode(RENDERING_MODE nRenderingMode) { #ifdef _WIN64 diff --git a/Externals/crystaledit/editlib/ccrystaltextview.h b/Externals/crystaledit/editlib/ccrystaltextview.h index 8027d54bb8c..38dafd96daf 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.h +++ b/Externals/crystaledit/editlib/ccrystaltextview.h @@ -37,6 +37,7 @@ #include "renderers/ccrystalrenderer.h" #include "utils/cregexp.h" #include "utils/icu.hpp" +#include "utils/DpiAware.h" //////////////////////////////////////////////////////////////////////////// // Forward class declarations @@ -82,7 +83,7 @@ enum : unsigned * not implement text editing. There are classes inherited from this * class which implement text editing. */ -class EDITPADC_CLASS CCrystalTextView : public CView +class EDITPADC_CLASS CCrystalTextView : public CView, public DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNCREATE (CCrystalTextView) @@ -813,6 +814,10 @@ protected : virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo); virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo); virtual void OnPrint (CDC * pDC, CPrintInfo * pInfo); + virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) { + CalcWindowRectImpl(lpClientRect, nAdjustType); + } + //}}AFX_VIRTUAL // Implementation @@ -930,6 +935,7 @@ protected : //END SW afx_msg void OnToggleColumnSelection (); + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP () }; diff --git a/Externals/crystaledit/editlib/dialogs/memcombo.cpp b/Externals/crystaledit/editlib/dialogs/memcombo.cpp index 1e967e19bad..6211e8bc8ea 100644 --- a/Externals/crystaledit/editlib/dialogs/memcombo.cpp +++ b/Externals/crystaledit/editlib/dialogs/memcombo.cpp @@ -70,26 +70,13 @@ void SetComboBoxWidth(CComboBox &Control, LPCTSTR lpszText = nullptr) if(!cnt) return; CClientDC dc(&Control); - NONCLIENTMETRICS info = { 0 }; - CFont oFont, *oldFont; + CFont *oldFont; int width = 0, nMax = ::GetSystemMetrics(SM_CXSCREEN) - 48; CRect rc; CSize size; - SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0); - info.lfMenuFont.lfHeight = -MulDiv(9, dc.GetDeviceCaps(LOGPIXELSY), 72); - info.lfMenuFont.lfWidth = 0; - info.lfMenuFont.lfWeight = FW_THIN; - info.lfMenuFont.lfItalic = false; - info.lfMenuFont.lfUnderline = false; - info.lfMenuFont.lfCharSet = DEFAULT_CHARSET; - info.lfMenuFont.lfOutPrecision = OUT_DEFAULT_PRECIS; - info.lfMenuFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; - info.lfMenuFont.lfQuality = DEFAULT_QUALITY; - info.lfMenuFont.lfPitchAndFamily = FF_SWISS; - _tcscpy_s(info.lfMenuFont.lfFaceName, _T("MS Sans Serif")); - oFont.CreateFontIndirect(&info.lfMenuFont); - oldFont = dc.SelectObject(&oFont); + CFont *pFont = Control.GetFont(); + oldFont = dc.SelectObject(pFont); if(lpszText != nullptr && *lpszText != 0) { size = dc.GetTextExtent(lpszText); width = size.cx; diff --git a/Externals/crystaledit/editlib/utils/DpiAware.cpp b/Externals/crystaledit/editlib/utils/DpiAware.cpp new file mode 100644 index 00000000000..9e4809051db --- /dev/null +++ b/Externals/crystaledit/editlib/utils/DpiAware.cpp @@ -0,0 +1,94 @@ +#include "StdAfx.h" +#include "DpiAware.h" +#include <../src/mfc/afximpl.h> + +namespace DpiAware +{ + GetDpiForWindowType GetDpiForWindow = nullptr; + SystemParametersInfoForDpiType SystemParametersInfoForDpi = nullptr; + GetSystemMetricsForDpiType GetSystemMetricsForDpi = nullptr; + OpenThemeDataForDpiType OpenThemeDataForDpi = nullptr; + AdjustWindowRectExForDpiType AdjustWindowRectExForDpi = nullptr; + LoadIconWithScaleDownType LoadIconWithScaleDown = nullptr; + + short SMIconOnInit = 0; + + bool DpiAwareSupport = []() + { + SMIconOnInit = static_cast(::GetSystemMetrics(SM_CXSMICON)); + HMODULE hLibraryUser32 = GetModuleHandleW(L"user32.dll"); + if (hLibraryUser32) + { + AdjustWindowRectExForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "AdjustWindowRectExForDpi")); + GetDpiForWindow = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetDpiForWindow")); + SystemParametersInfoForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "SystemParametersInfoForDpi")); + GetSystemMetricsForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetSystemMetricsForDpi")); + } + HMODULE hLibraryComctl32 = GetModuleHandleW(L"comctl32.dll"); + if (hLibraryComctl32) + { + LoadIconWithScaleDown = reinterpret_cast(GetProcAddress(hLibraryComctl32, "LoadIconWithScaleDown")); + } + HMODULE hLibraryUxTheme = GetModuleHandleW(L"uxtheme.dll"); + if (hLibraryUxTheme) + { + OpenThemeDataForDpi = reinterpret_cast(GetProcAddress(hLibraryUxTheme, "OpenThemeDataForDpi")); + } + if (!AdjustWindowRectExForDpi) + AdjustWindowRectExForDpi = [](LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi) -> BOOL + { return AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle); }; + if (!GetDpiForWindow) + GetDpiForWindow = [](HWND hwnd) -> UINT { return CClientDC(CWnd::FromHandle(hwnd)).GetDeviceCaps(LOGPIXELSX); }; + if (!GetSystemMetricsForDpi) + GetSystemMetricsForDpi = [](int nIndex, UINT dpi) -> int { return GetSystemMetrics(nIndex); }; + if (!LoadIconWithScaleDown) + LoadIconWithScaleDown = [](HINSTANCE hinst, PCWSTR pszName, int cx, int cy, HICON *phico) -> HRESULT + { *phico = LoadIcon(hinst, pszName); return *phico != nullptr ? S_OK : E_FAIL; }; + if (!OpenThemeDataForDpi) + { + OpenThemeDataForDpi = [](HWND hwnd, LPCWSTR pszClassList, UINT dpi) -> HTHEME { return OpenThemeData(hwnd, pszClassList); }; + return false; + } + return true; + }(); + + void GetPointLogFont(LOGFONT& logFont, float point, const TCHAR* lfFaceName, int dpi) + { + LOGFONT lfv{}; + lfv.lfHeight = static_cast(-point * dpi / 72.0f); + lfv.lfCharSet = DEFAULT_CHARSET; + _tcscpy_s(lfv.lfFaceName, lfFaceName); + logFont = lfv; + } + + bool GetNonClientLogFont(LOGFONT& logFont, size_t memberOffset, int dpi) + { + if (DpiAware::DpiAwareSupport) + { + DpiAware::NONCLIENTMETRICS6 ncm = { sizeof DpiAware::NONCLIENTMETRICS6 }; + if (!SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof DpiAware::NONCLIENTMETRICS6, &ncm, 0, dpi)) + return false; + memcpy(&logFont, (char*)&ncm + memberOffset, sizeof(LOGFONT)); + } + else + { + NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS }; + if (!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0)) + return false; + memcpy(&logFont, (char*)&ncm + memberOffset, sizeof(LOGFONT)); + } + return true; + } + + void UpdateAfxDataSysMetrics(int dpi) + { + afxData.cxIcon = GetSystemMetricsForDpi(SM_CXICON, dpi); + afxData.cyIcon = GetSystemMetricsForDpi(SM_CYICON, dpi); + afxData.cxVScroll = GetSystemMetricsForDpi(SM_CXVSCROLL, dpi) + AFX_CX_BORDER; + afxData.cyHScroll = GetSystemMetricsForDpi(SM_CYHSCROLL, dpi) + AFX_CY_BORDER; + afxData.cxPixelsPerInch = dpi; + afxData.cyPixelsPerInch = dpi; + } + +} + diff --git a/Externals/crystaledit/editlib/utils/DpiAware.h b/Externals/crystaledit/editlib/utils/DpiAware.h new file mode 100644 index 00000000000..66d01ba2ef2 --- /dev/null +++ b/Externals/crystaledit/editlib/utils/DpiAware.h @@ -0,0 +1,99 @@ +#pragma once + +#include + +#ifndef WM_DPICHANGED +#define WM_DPICHANGED 0x02E0 +#define WM_DPICHANGED_BEFOREPARENT 0x02E2 +#define WM_DPICHANGED_AFTERPARENT 0x02E3 +#endif + +namespace DpiAware +{ + struct NONCLIENTMETRICS6 + { + UINT cbSize; + int iBorderWidth; + int iScrollWidth; + int iScrollHeight; + int iCaptionWidth; + int iCaptionHeight; + LOGFONTW lfCaptionFont; + int iSmCaptionWidth; + int iSmCaptionHeight; + LOGFONTW lfSmCaptionFont; + int iMenuWidth; + int iMenuHeight; + LOGFONTW lfMenuFont; + LOGFONTW lfStatusFont; + LOGFONTW lfMessageFont; + int iPaddedBorderWidth; + }; + + using AdjustWindowRectExForDpiType = BOOL (__stdcall*)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi); + using GetDpiForWindowType = UINT (__stdcall*)(HWND hwnd); + using SystemParametersInfoForDpiType = BOOL(__stdcall*)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi); + using GetSystemMetricsForDpiType = int(__stdcall*)(int nIndex, UINT dpi); + using OpenThemeDataForDpiType = HTHEME(__stdcall*)(HWND hwnd, LPCWSTR pszClassList, UINT dpi); + using LoadIconWithScaleDownType = HRESULT(__stdcall*)(HINSTANCE hinst, PCWSTR pszName, int cx, int cy, HICON *phico); + + extern bool DpiAwareSupport; + extern short SMIconOnInit; + extern AdjustWindowRectExForDpiType AdjustWindowRectExForDpi; + extern GetDpiForWindowType GetDpiForWindow; + extern SystemParametersInfoForDpiType SystemParametersInfoForDpi; + extern GetSystemMetricsForDpiType GetSystemMetricsForDpi; + extern OpenThemeDataForDpiType OpenThemeDataForDpi; + extern LoadIconWithScaleDownType LoadIconWithScaleDown; + + void GetPointLogFont(LOGFONT& logFont, float point, const TCHAR* lfFaceName, int dpi); + bool GetNonClientLogFont(LOGFONT& logFont, size_t memberOffset, int dpi); + void UpdateAfxDataSysMetrics(int dpi); + + template + class PerMonitorDpiAwareWindow + { + T* wnd() { return static_cast(this); } + public: + int GetDpi() + { + if (m_dpi == -1) + UpdateDpi(); + return m_dpi; + } + + int PointToPixel(int point) { return MulDiv(point, GetDpi(), 72); } + template + int PointToPixel(T point) { return static_cast((point * GetDpi()) / 72); } + void UpdateDpi() + { + m_dpi = GetDpiForWindow(wnd()->m_hWnd); + m_cxSMIcon = static_cast(GetSystemMetricsForDpi(SM_CXSMICON, m_dpi)); + } + int GetSystemMetrics(int nIndex) { return GetSystemMetricsForDpi(nIndex, GetDpi()); } + BOOL AdjustWindowRectEx(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle) + { + return DpiAware::AdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, GetDpi()); + } + + void CalcWindowRectImpl(LPRECT lpClientRect, UINT nAdjustType = CWnd::adjustBorder) + { + DWORD dwExStyle = GetWindowLong(wnd()->m_hWnd, GWL_EXSTYLE); + if (nAdjustType == 0) + dwExStyle &= ~WS_EX_CLIENTEDGE; + DWORD dwStyle = (DWORD)GetWindowLong(wnd()->m_hWnd, GWL_STYLE); + DpiAware::AdjustWindowRectExForDpi(lpClientRect, dwStyle, FALSE, dwExStyle, GetDpi()); + } + + bool IsDpiChanged() const + { + return SMIconOnInit != m_cxSMIcon; + } + + protected: + short m_cxSMIcon = SMIconOnInit; + int m_dpi = -1; + }; + +} + diff --git a/Src/AboutDlg.cpp b/Src/AboutDlg.cpp index 196dd19dd03..983eeaee9c2 100644 --- a/Src/AboutDlg.cpp +++ b/Src/AboutDlg.cpp @@ -59,9 +59,10 @@ class CAboutDlg::Impl : public CTrDialog afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); afx_msg void OnBnClickedWWW(NMHDR *pNMHDR, LRESULT *pResult); + afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); private: - virtual void UpdateDpi(int dpi) override; + void RecreateResources(); CAboutDlg *const m_p; ATL::CImage m_image; @@ -76,6 +77,7 @@ BEGIN_MESSAGE_MAP(CAboutDlg::Impl, CTrDialog) ON_WM_ERASEBKGND() ON_WM_CTLCOLOR() ON_NOTIFY(NM_CLICK, IDC_WWW, OnBnClickedWWW) + ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) END_MESSAGE_MAP() CAboutDlg::Impl::Impl(CAboutDlg *p, CWnd* pParent /*= nullptr*/) @@ -105,10 +107,8 @@ BOOL CAboutDlg::Impl::OnInitDialog() // FIXME: LoadImageFromResource() seems to fail when running on Wine 5.0. } - UpdateDpi(GetDpi()); - - GetDlgItem(IDC_VERSION)->SetFont(&m_font); - GetDlgItem(IDC_GNU_ASCII)->SetFont(&m_font_gnu_ascii); + RecreateResources(); + ::SetDlgItemTextA(m_hWnd, IDC_GNU_ASCII, gnu_ascii); String link; @@ -166,25 +166,35 @@ void CAboutDlg::Impl::OnBnClickedWWW(NMHDR *pNMHDR, LRESULT *pResult) ShellExecute(nullptr, _T("open"), pNMLink->item.szUrl, nullptr, nullptr, SW_SHOWNORMAL); } -void CAboutDlg::Impl::UpdateDpi(int dpi) +LRESULT CAboutDlg::Impl::OnDpiChanged(WPARAM wParam, LPARAM lParam) { - m_dpi = dpi; + CTrDialog::OnDpiChanged(wParam, lParam); + RecreateResources(); + Invalidate(); + return 0; +} - auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; +void CAboutDlg::Impl::RecreateResources() +{ + if (!GetDlgItem(IDC_VERSION)) + return; + + const int dpi = GetDpi(); - LOGFONT lfv = { 0 }; - lfv.lfHeight = -pointToPixel(10); + LOGFONT lfv{}; + DpiAware::GetPointLogFont(lfv, 10, _T("Tahoma"), dpi); lfv.lfWeight = FW_NORMAL; - _tcscpy_s(lfv.lfFaceName, _T("Tahoma")); m_font.DeleteObject(); m_font.CreateFontIndirect(&lfv); - LOGFONT lf = { 0 }; - lf.lfHeight = -pointToPixel(14); + LOGFONT lf{}; + DpiAware::GetPointLogFont(lf, 14, _T("Courier New"), dpi); lf.lfWeight = FW_BOLD; - _tcscpy_s(lf.lfFaceName, _T("Courier New")); m_font_gnu_ascii.DeleteObject(); m_font_gnu_ascii.CreateFontIndirect(&lf); + + GetDlgItem(IDC_VERSION)->SetFont(&m_font); + GetDlgItem(IDC_GNU_ASCII)->SetFont(&m_font_gnu_ascii); } CAboutDlg::CAboutDlg() : m_pimpl(new CAboutDlg::Impl(this)) {} diff --git a/Src/Common/BCMenu.cpp b/Src/Common/BCMenu.cpp index 5dd1f9ab1ad..330d09bef56 100644 --- a/Src/Common/BCMenu.cpp +++ b/Src/Common/BCMenu.cpp @@ -25,7 +25,7 @@ #include "stdafx.h" // Standard windows header file #include "BCMenu.h" // BCMenu class declaration -#include "DpiUtil.h" +#include "utils/DpiAware.h" #include //SK: makes A2W and other spiffy AFX macros work #pragma comment(lib, "uxtheme.lib") @@ -170,7 +170,7 @@ BCMenu::BCMenu() m_bitmapBackgroundFlag=false; m_loadmenu=false; if (m_hTheme==nullptr && IsThemeActive()) - ReopenTheme(DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd)); + ReopenTheme(DpiAware::GetDpiForWindow(AfxGetMainWnd()->m_hWnd)); } @@ -209,7 +209,7 @@ bool BCMenu::ReopenTheme(int dpi) return false; if (m_hTheme != nullptr) CloseThemeData(m_hTheme); - m_hTheme = DpiUtil::OpenThemeDataForDpi(nullptr, _T("MENU"), dpi); + m_hTheme = DpiAware::OpenThemeDataForDpi(nullptr, _T("MENU"), dpi); if (m_hTheme == nullptr) return false; MARGINS marginCheckBg, marginArrow; @@ -577,9 +577,9 @@ void BCMenu::DrawItem_Theme(LPDRAWITEMSTRUCT lpDIS) bitmap = &m_AllImages; } - const int dpi = DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd); - const int cxSMIcon = DpiUtil::GetSystemMetricsForDpi(SM_CXSMICON, dpi); - const int cySMIcon = DpiUtil::GetSystemMetricsForDpi(SM_CYSMICON, dpi); + const int dpi = DpiAware::GetDpiForWindow(AfxGetMainWnd()->m_hWnd); + const int cxSMIcon = DpiAware::GetSystemMetricsForDpi(SM_CXSMICON, dpi); + const int cySMIcon = DpiAware::GetSystemMetricsForDpi(SM_CYSMICON, dpi); if(nIconNormal != -1 && bitmap != nullptr){ CImage bitmapstandard; @@ -753,20 +753,10 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) } else{ CFont fontMenu; - if (DpiUtil::UnsafeSystemParametersInfoForDpi) - { - DpiUtil::NONCLIENTMETRICS6 nm = { sizeof DpiUtil::NONCLIENTMETRICS6 }; - VERIFY(DpiUtil::UnsafeSystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, - nm.cbSize, &nm, 0, DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd))); - fontMenu.CreateFontIndirect (&nm.lfMenuFont); - } - else - { - NONCLIENTMETRICS nm = { sizeof NONCLIENTMETRICS }; - VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, - nm.cbSize,&nm,0)); - fontMenu.CreateFontIndirect (&nm.lfMenuFont); - } + LOGFONT lfMenuFont; + const int dpi = DpiAware::GetDpiForWindow(AfxGetMainWnd()->m_hWnd); + DpiAware::GetNonClientLogFont(lfMenuFont, offsetof(NONCLIENTMETRICS, lfMenuFont), dpi); + fontMenu.CreateFontIndirect (&lfMenuFont); // Obtain the width of the text: CClientDC dc(AfxGetMainWnd() ? AfxGetMainWnd() : CWnd::GetDesktopWindow()); // Get device context @@ -782,18 +772,19 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) VERIFY(::GetTextExtentPoint32W(dc.m_hDC,lpstrText, lstrlenW(lpstrText),&size)); //SK should also work on 95 - CSize t = CSize(size); + CSize t = size; dc.SelectObject (pFont); // Select old font in // Set width and height: const int BCMENU_PAD=4; if (m_hTheme == nullptr) - lpMIS->itemWidth = m_iconX+BCMENU_PAD+8+t.cx; + lpMIS->itemWidth = MulDiv(m_iconX+BCMENU_PAD+8, dpi, 96) +t.cx; else lpMIS->itemWidth = m_gutterWidth+m_textBorder+t.cx+m_arrowWidth; - int temp = DpiUtil::GetSystemMetricsForDpi(SM_CYMENU, DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd)); - lpMIS->itemHeight = temp>m_iconY+BCMENU_PAD ? temp : m_iconY+BCMENU_PAD; + int temp = DpiAware::GetSystemMetricsForDpi(SM_CYMENU, dpi); + int temp2 = MulDiv(m_iconY + BCMENU_PAD, dpi, 96); + lpMIS->itemHeight = temp>temp2 ? temp : temp2; } } diff --git a/Src/Common/CMoveConstraint.cpp b/Src/Common/CMoveConstraint.cpp index e549cfabb72..18f59914615 100644 --- a/Src/Common/CMoveConstraint.cpp +++ b/Src/Common/CMoveConstraint.cpp @@ -651,6 +651,12 @@ CMoveConstraint::WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, L } else if (msg==WM_NOTIFY && TTN_NEEDTEXT==((NMHDR*)lParam)->code) { if (OnTtnNeedText((TOOLTIPTEXT*)lParam, plresult)) return true; +/* } else if (WM_DPICHANGED == msg) { + const int dpi = HIWORD(wParam); + const RECT *prcNew = reinterpret_cast(lParam); + m_nMaxX = prcNew->right - prcNew->left; + m_nMaxY = prcNew->bottom - prcNew->top; + return true;*/ } return false; diff --git a/Src/Common/MDITabBar.cpp b/Src/Common/MDITabBar.cpp index 129bcb84191..ace4c5a2332 100644 --- a/Src/Common/MDITabBar.cpp +++ b/Src/Common/MDITabBar.cpp @@ -28,6 +28,7 @@ BEGIN_MESSAGE_MAP(CMDITabBar, CControlBar) ON_WM_MOUSELEAVE() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() + ON_MESSAGE(WM_DPICHANGED_AFTERPARENT, OnDpiChangedBeforeParent) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -43,7 +44,7 @@ BOOL CMDITabBar::Create(CMDIFrameWnd* pMainFrame) if (!CWnd::Create(WC_TABCONTROL, nullptr, WS_CHILD | WS_VISIBLE | TCS_OWNERDRAWFIXED, CRect(0, 0, 0, 0), pMainFrame, AFX_IDW_CONTROLBAR_FIRST+30)) return FALSE; - UpdateDpi(GetDpi()); + OnDpiChangedBeforeParent(0, 0); return TRUE; } @@ -282,19 +283,20 @@ void CMDITabBar::UpdateTabs() } } -void CMDITabBar::UpdateDpi(int dpi) +LRESULT CMDITabBar::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) { - m_dpi = dpi; + UpdateDpi(); m_cxSMIcon = GetSystemMetrics(SM_CXSMICON); TabCtrl_SetPadding(m_hWnd, m_cxSMIcon, 4); LOGFONT lfMenuFont; - DpiUtil::GetMenuLogFont(dpi, lfMenuFont); + DpiAware::GetNonClientLogFont(lfMenuFont, offsetof(NONCLIENTMETRICS, lfMenuFont), m_dpi); m_font.DeleteObject(); m_font.CreateFontIndirect(&lfMenuFont); SetFont(&m_font); + return 0; } /** diff --git a/Src/Common/MDITabBar.h b/Src/Common/MDITabBar.h index ac4f9d6af1a..f691d2dd464 100644 --- a/Src/Common/MDITabBar.h +++ b/Src/Common/MDITabBar.h @@ -6,12 +6,12 @@ */ #pragma once -#include "DpiUtil.h" +#include "utils/DpiAware.h" /** * @brief Class for Tab bar. */ -class CMDITabBar : public CControlBar, public DpiUtil::PerMonitorDpiAwareWindow +class CMDITabBar : public CControlBar, public DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CMDITabBar) @@ -33,7 +33,6 @@ class CMDITabBar : public CControlBar, public DpiUtil::PerMonitorDpiAwareWindow< virtual ~CMDITabBar() {} BOOL Create(CMDIFrameWnd* pParentWnd); void UpdateTabs(); - virtual void UpdateDpi(int dpi) override; bool GetAutoMaxWidth() const { return m_bAutoMaxWidth; } void SetAutoMaxWidth(bool bAutoMaxWidth) { m_bAutoMaxWidth = bAutoMaxWidth; } @@ -71,6 +70,7 @@ class CMDITabBar : public CControlBar, public DpiUtil::PerMonitorDpiAwareWindow< afx_msg void OnMouseLeave(); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM, LPARAM); //}}AFX_MSG DECLARE_MESSAGE_MAP() diff --git a/Src/Common/MessageBoxDialog.cpp b/Src/Common/MessageBoxDialog.cpp index edf494825d0..42aabbf0ffe 100644 --- a/Src/Common/MessageBoxDialog.cpp +++ b/Src/Common/MessageBoxDialog.cpp @@ -108,23 +108,8 @@ IMPLEMENT_DYNAMIC(CMessageBoxDialog, CDialog) m_aButtons.clear(); - NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS }; - SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0); - m_font.CreateFontIndirect(&ncm.lfMessageFont); - - LOGFONT lf = { 0 }; - HTHEME hTheme = OpenThemeData(nullptr, _T("TEXTSTYLE")); - if (hTheme != nullptr && SUCCEEDED(GetThemeFont(hTheme, nullptr, TEXT_MAININSTRUCTION, 0, TMT_FONT, &lf))) - { - m_fontMainInstruction.CreateFontIndirect(&lf); - GetThemeColor(hTheme, TEXT_MAININSTRUCTION, 0, TMT_TEXTCOLOR, &m_clrMainInstructionFont); - CloseThemeData(hTheme); - } - else - { - m_fontMainInstruction.CreateFontIndirect(&ncm.lfMessageFont); - m_clrMainInstructionFont = GetSysColor(COLOR_WINDOWTEXT); - } + const int dpi = DpiAware::GetDpiForWindow((pParent ? pParent : AfxGetMainWnd())->m_hWnd); + UpdateResources(dpi); } /* @@ -814,6 +799,22 @@ HBRUSH CMessageBoxDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) return CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } +LRESULT CMessageBoxDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) +{ + const int dpi = HIWORD(wParam); + UpdateDpi(); + UpdateResources(dpi); + Default(); + if (!GetDlgItem(IDCHECKBOX)) + return 0; + for (vector::iterator iter = m_aButtons.begin(); iter != m_aButtons.end(); ++iter) + GetDlgItem(iter->nID)->SetFont(&m_font); + GetDlgItem(IDCHECKBOX)->SetFont(&m_font); + m_stcMessage.SetFont(&m_fontMainInstruction); + Invalidate(); + return 0; +} + ////////////////////////////////////////////////////////////////////////////// // Other dialog handling methods. @@ -852,6 +853,7 @@ BEGIN_MESSAGE_MAP(CMessageBoxDialog, CDialog) ON_WM_TIMER() ON_WM_ERASEBKGND() ON_WM_CTLCOLOR() + ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) END_MESSAGE_MAP() ////////////////////////////////////////////////////////////////////////////// @@ -1598,3 +1600,26 @@ void CMessageBoxDialog::DefineLayout ( ) // Center the window. CenterWindow(); } + +void CMessageBoxDialog::UpdateResources(int dpi) +{ + LOGFONT lfMessageFont; + DpiAware::GetNonClientLogFont(lfMessageFont, offsetof(NONCLIENTMETRICS, lfMessageFont), dpi); + m_font.DeleteObject(); + m_font.CreateFontIndirect(&lfMessageFont); + + m_fontMainInstruction.DeleteObject(); + LOGFONT lf = { 0 }; + HTHEME hTheme = DpiAware::OpenThemeDataForDpi(nullptr, _T("TEXTSTYLE"), dpi); + if (hTheme != nullptr && SUCCEEDED(GetThemeFont(hTheme, nullptr, TEXT_MAININSTRUCTION, 0, TMT_FONT, &lf))) + { + m_fontMainInstruction.CreateFontIndirect(&lf); + GetThemeColor(hTheme, TEXT_MAININSTRUCTION, 0, TMT_TEXTCOLOR, &m_clrMainInstructionFont); + CloseThemeData(hTheme); + } + else + { + m_fontMainInstruction.CreateFontIndirect(&lfMessageFont); + m_clrMainInstructionFont = GetSysColor(COLOR_WINDOWTEXT); + } +} diff --git a/Src/Common/MessageBoxDialog.h b/Src/Common/MessageBoxDialog.h index 4419de7dda9..7f2dfcfd55c 100644 --- a/Src/Common/MessageBoxDialog.h +++ b/Src/Common/MessageBoxDialog.h @@ -32,6 +32,7 @@ #include "resource.h" #include "UnicodeString.h" +#include "utils/DpiAware.h" #include ////////////////////////////////////////////////////////////////////////////// @@ -85,7 +86,7 @@ ////////////////////////////////////////////////////////////////////////////// // Class definition. -class CMessageBoxDialog : public CDialog +class CMessageBoxDialog : public CDialog, public DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CMessageBoxDialog) @@ -183,10 +184,13 @@ class CMessageBoxDialog : public CDialog // Method for handling messages before dispatching them. virtual BOOL PreTranslateMessage ( MSG* pMsg ); + virtual void CallWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) { CalcWindowRectImpl(lpClientRect, nAdjustType); } + // Method for handling a timer event. afx_msg void OnTimer ( UINT_PTR nIDEvent ); afx_msg BOOL OnEraseBkgnd( CDC* pDC ); afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor ); + afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); protected: @@ -288,4 +292,6 @@ class CMessageBoxDialog : public CDialog // Method for defining the layout of the dialog. void DefineLayout ( ); + void UpdateResources (int dpi); + }; diff --git a/Src/Common/PreferencesDlg.cpp b/Src/Common/PreferencesDlg.cpp index 9f1950e5727..0d110fcd89c 100644 --- a/Src/Common/PreferencesDlg.cpp +++ b/Src/Common/PreferencesDlg.cpp @@ -73,7 +73,7 @@ void CPreferencesDlg::DoDataExchange(CDataExchange* pDX) //}}AFX_DATA_MAP } -BEGIN_MESSAGE_MAP(CPreferencesDlg, CDialog) +BEGIN_MESSAGE_MAP(CPreferencesDlg, CTrDialog) //{{AFX_MSG_MAP(CPreferencesDlg) ON_WM_SIZE() ON_COMMAND(ID_HELP, OnHelpButton) @@ -88,7 +88,7 @@ END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPreferencesDlg message handlers -BOOL CPreferencesDlg::OnInitDialog() +BOOL CPreferencesDlg::OnInitDialog() { CTrDialog::OnInitDialog(); @@ -118,19 +118,21 @@ BOOL CPreferencesDlg::OnInitDialog() AddPage(&m_pageShell, IDS_OPTIONSPG_SHELL); ReadOptions(); - + CRect rPPHost; GetDlgItem(IDC_TREEOPT_HOSTFRAME)->GetWindowRect(rPPHost); ScreenToClient(rPPHost); if (m_pphost.Create(rPPHost, this)) SetActivePage(AfxGetApp()->GetProfileInt(_T("Settings"), _T("OptStartPage"), 0)); - + // setup handler for resizing this dialog + /* m_constraint.InitializeCurrentSize(this); m_constraint.DisallowHeightGrowth(); m_constraint.SubclassWnd(); // install subclassing m_constraint.LoadPosition(_T("ResizeableDialogs"), _T("OptionsDlg"), false); // persist size via registry +*/ return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } @@ -154,7 +156,8 @@ void CPreferencesDlg::OnSize(UINT nType, int cx, int cy) CRect rPPHost; pPPHostWnd->GetWindowRect(rPPHost); ScreenToClient(rPPHost); - m_pphost.MoveWindow(&rPPHost); + if (m_pphost.m_hWnd) + m_pphost.MoveWindow(&rPPHost); } } diff --git a/Src/Common/SuperComboBox.cpp b/Src/Common/SuperComboBox.cpp index 2719240bd08..1143ee372ca 100644 --- a/Src/Common/SuperComboBox.cpp +++ b/Src/Common/SuperComboBox.cpp @@ -567,9 +567,11 @@ void CSuperComboBox::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) if (!pEdit->GetModify() || GetFocus() != pEdit) GetWindowText(sText); int iIcon = GetFileTypeIconIndex(pvText); + const int cxsmicon = GetSystemMetrics(SM_CXSMICON); + const int cysmicon = GetSystemMetrics(SM_CYSMICON); ImageList_DrawEx(m_himlSystem, iIcon, lpDrawItemStruct->hDC, lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top, - 0, 0, GetSysColor(COLOR_WINDOW), CLR_NONE, ILD_NORMAL); + cxsmicon, cysmicon, GetSysColor(COLOR_WINDOW), CLR_NONE, ILD_NORMAL); return; } CComboBoxEx::OnDrawItem(nIDCtl, lpDrawItemStruct); diff --git a/Src/Common/SuperComboBox.h b/Src/Common/SuperComboBox.h index ddec4f3ff0c..cd6afd5bb39 100644 --- a/Src/Common/SuperComboBox.h +++ b/Src/Common/SuperComboBox.h @@ -5,13 +5,14 @@ #include #include "UnicodeString.h" +#include "utils/DpiAware.h" class DropHandler; ///////////////////////////////////////////////////////////////////////////// // CSuperComboBox window -class CSuperComboBox : public CComboBoxEx +class CSuperComboBox : public CComboBoxEx, DpiAware::PerMonitorDpiAwareWindow { // Construction public: diff --git a/Src/Common/scbarcf.cpp b/Src/Common/scbarcf.cpp index d2613fdaf51..b5257a5761b 100644 --- a/Src/Common/scbarcf.cpp +++ b/Src/Common/scbarcf.cpp @@ -94,21 +94,20 @@ void CSizingControlBarCF::NcPaintGripper(CDC* pDC, CRect rcClient) // compute the caption rectangle bool bHorz = IsHorzDocked(); CRect rcGrip = rcClient; - auto pointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; - CRect rcBtn(m_biHide.ptOrg, CSize(pointToPixel(m_biHide.dblBoxSize), pointToPixel(m_biHide.dblBoxSize))); + CRect rcBtn(m_biHide.ptOrg, CSize(PointToPixel(m_biHide.dblBoxSize), PointToPixel(m_biHide.dblBoxSize))); if (bHorz) { // right side gripper - rcGrip.left -= pointToPixel(m_dblGripper + 0.75); - rcGrip.right = rcGrip.left + pointToPixel(8.25); - rcGrip.top = rcBtn.bottom + pointToPixel(2.25); + rcGrip.left -= PointToPixel(m_dblGripper + 0.75); + rcGrip.right = rcGrip.left + PointToPixel(8.25); + rcGrip.top = rcBtn.bottom + PointToPixel(2.25); } else { // gripper at top - rcGrip.top -= pointToPixel(m_dblGripper + 0.75); - rcGrip.bottom = rcGrip.top + pointToPixel(8.25); - rcGrip.right = rcBtn.left - pointToPixel(2.25); + rcGrip.top -= PointToPixel(m_dblGripper + 0.75); + rcGrip.bottom = rcGrip.top + PointToPixel(8.25); + rcGrip.right = rcBtn.left - PointToPixel(2.25); } - rcGrip.InflateRect(bHorz ? pointToPixel(0.75) : 0, bHorz ? 0 : pointToPixel(0.75)); + rcGrip.InflateRect(bHorz ? PointToPixel(0.75) : 0, bHorz ? 0 : PointToPixel(0.75)); // draw the caption background //CBrush br; @@ -172,7 +171,8 @@ void CSizingControlBarCF::NcPaintGripper(CDC* pDC, CRect rcClient) // draw the caption text - first select a font CFont font; LOGFONT lf; - bool bFont = !!font.CreatePointFont(85/*8.5 points*/, m_sFontFace); + DpiAware::GetPointLogFont(lf, 8.5, m_sFontFace, GetDpi()); + bool bFont = !!font.CreateFontIndirect(&lf); if (bFont) { // get the text color @@ -197,8 +197,8 @@ void CSizingControlBarCF::NcPaintGripper(CDC* pDC, CRect rcClient) GetWindowText(sTitle); CPoint ptOrg = bHorz ? - CPoint(rcGrip.left - pointToPixel(0.75), rcGrip.bottom - pointToPixel(2.25)) : - CPoint(rcGrip.left + pointToPixel(2.25), rcGrip.top - pointToPixel(0.75)); + CPoint(rcGrip.left - PointToPixel(0.75), rcGrip.bottom - PointToPixel(2.25)) : + CPoint(rcGrip.left + PointToPixel(2.25), rcGrip.top - PointToPixel(0.75)); pDC->ExtTextOut(ptOrg.x, ptOrg.y, ETO_CLIPPED, rcGrip, sTitle, nullptr); @@ -220,3 +220,4 @@ LRESULT CSizingControlBarCF::OnSetText(WPARAM wParam, LPARAM lParam) return lResult; } + diff --git a/Src/Common/scbarcf.h b/Src/Common/scbarcf.h index df194d8feb6..1473b595c5b 100644 --- a/Src/Common/scbarcf.h +++ b/Src/Common/scbarcf.h @@ -32,7 +32,7 @@ ///////////////////////////////////////////////////////////////////////// // CSizingControlBarCF -#include "DpiUtil.h" +#include "utils/DpiAware.h" #ifndef baseCSizingControlBarCF #define baseCSizingControlBarCF CSizingControlBarG diff --git a/Src/Common/scbarg.cpp b/Src/Common/scbarg.cpp index c3fa948d9f1..5ebbbe8af58 100644 --- a/Src/Common/scbarg.cpp +++ b/Src/Common/scbarg.cpp @@ -85,19 +85,17 @@ void CSizingControlBarG::NcCalcClient(LPRECT pRc, UINT nDockBarID) bool bHorz = (nDockBarID == AFX_IDW_DOCKBAR_TOP) || (nDockBarID == AFX_IDW_DOCKBAR_BOTTOM); - auto pointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; - if (bHorz) - rc.DeflateRect(pointToPixel(m_dblGripper), 0, 0, 0); + rc.DeflateRect(PointToPixel(m_dblGripper), 0, 0, 0); else - rc.DeflateRect(0, pointToPixel(m_dblGripper), 0, 0); + rc.DeflateRect(0, PointToPixel(m_dblGripper), 0, 0); // set position for the "x" (hide bar) button CPoint ptOrgBtn; if (bHorz) - ptOrgBtn = CPoint(rc.left - pointToPixel(9.75), rc.top); + ptOrgBtn = CPoint(rc.left - PointToPixel(9.75), rc.top); else - ptOrgBtn = CPoint(rc.right - pointToPixel(9.0), rc.top - pointToPixel(9.75)); + ptOrgBtn = CPoint(rc.right - PointToPixel(9.0), rc.top - PointToPixel(9.75)); m_biHide.Move(ptOrgBtn - rcBar.TopLeft()); @@ -111,29 +109,29 @@ void CSizingControlBarG::NcPaintGripper(CDC* pDC, CRect rcClient) // paints a simple "two raised lines" gripper // override this if you want a more sophisticated gripper - auto pointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; + auto PointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; CRect gripper = rcClient; - CRect rcbtn(m_biHide.ptOrg, CSize(pointToPixel(m_biHide.dblBoxSize), pointToPixel(m_biHide.dblBoxSize))); + CRect rcbtn(m_biHide.ptOrg, CSize(PointToPixel(m_biHide.dblBoxSize), PointToPixel(m_biHide.dblBoxSize))); bool bHorz = IsHorzDocked(); gripper.DeflateRect(1, 1); if (bHorz) { // gripper at left - gripper.left -= pointToPixel(m_dblGripper); - gripper.right = gripper.left + pointToPixel(2.25); - gripper.top = rcbtn.bottom + pointToPixel(2.25); + gripper.left -= PointToPixel(m_dblGripper); + gripper.right = gripper.left + PointToPixel(2.25); + gripper.top = rcbtn.bottom + PointToPixel(2.25); } else { // gripper at top - gripper.top -= pointToPixel(m_dblGripper); - gripper.bottom = gripper.top + pointToPixel(2.25); - gripper.right = rcbtn.left - pointToPixel(2.25); + gripper.top -= PointToPixel(m_dblGripper); + gripper.bottom = gripper.top + PointToPixel(2.25); + gripper.right = rcbtn.left - PointToPixel(2.25); } pDC->Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT), ::GetSysColor(COLOR_BTNSHADOW)); - gripper.OffsetRect(bHorz ? pointToPixel(2.25) : 0, bHorz ? 0 : pointToPixel(2.25)); + gripper.OffsetRect(bHorz ? PointToPixel(2.25) : 0, bHorz ? 0 : PointToPixel(2.25)); pDC->Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT), ::GetSysColor(COLOR_BTNSHADOW)); @@ -150,8 +148,8 @@ NCHITTEST_RESULT CSizingControlBarG::OnNcHitTest(CPoint point) if (nRet != HTCLIENT) return nRet; - auto pointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; - CRect rc(m_biHide.ptOrg, CSize(pointToPixel(m_biHide.dblBoxSize), pointToPixel(m_biHide.dblBoxSize))); + auto PointToPixel = [dpi = GetDpi()](double point) { return static_cast(point * dpi / 72); }; + CRect rc(m_biHide.ptOrg, CSize(PointToPixel(m_biHide.dblBoxSize), PointToPixel(m_biHide.dblBoxSize))); rc.OffsetRect(rcBar.TopLeft()); if (rc.PtInRect(point)) return HTCLOSE; @@ -202,8 +200,9 @@ CSCBButton::CSCBButton() void CSCBButton::Paint(CDC* pDC) { - auto pointToPixel = [dpi = DpiUtil::GetDpiForWindow(AfxGetMainWnd()->m_hWnd)](double point) { return static_cast(point * dpi / 72); }; - CRect rc(ptOrg, CSize(pointToPixel(dblBoxSize), pointToPixel(dblBoxSize))); + const int dpi = DpiAware::GetDpiForWindow(AfxGetMainWnd()->m_hWnd); + auto PointToPixel = [dpi](double point) { return static_cast(point * dpi / 72); }; + CRect rc(ptOrg, CSize(PointToPixel(dblBoxSize), PointToPixel(dblBoxSize))); if (bPushed) pDC->Draw3dRect(rc, ::GetSysColor(COLOR_BTNSHADOW), @@ -217,10 +216,12 @@ void CSCBButton::Paint(CDC* pDC) pDC->SetTextColor(::GetSysColor(COLOR_BTNTEXT)); int nPrevBkMode = pDC->SetBkMode(TRANSPARENT); CFont font; - font.CreatePointFont(60/*6 points*/, _T("Marlett")); + LOGFONT lf; + DpiAware::GetPointLogFont(lf, 6, _T("Marlett"), dpi); + font.CreateFontIndirect(&lf); CFont* oldfont = pDC->SelectObject(&font); - pDC->TextOut(ptOrg.x + pointToPixel(1.5), ptOrg.y + pointToPixel(1.5), CString(_T("r"))); // x-like + pDC->TextOut(ptOrg.x + PointToPixel(1.5), ptOrg.y + PointToPixel(1.5), CString(_T("r"))); // x-like pDC->SelectObject(oldfont); pDC->SetBkMode(nPrevBkMode); diff --git a/Src/Common/scbarg.h b/Src/Common/scbarg.h index 154a2a16d42..699295a7fa9 100644 --- a/Src/Common/scbarg.h +++ b/Src/Common/scbarg.h @@ -27,8 +27,6 @@ ///////////////////////////////////////////////////////////////////////// #pragma once -#include "DpiUtil.h" - // MFC 8/VS.NET 2005 has breaking change in OnNcHitTest return value #ifndef NCHITTEST_RESULT #if _MFC_VER >= 0x0800 @@ -62,7 +60,7 @@ class CSCBButton #define baseCSizingControlBarG CSizingControlBar #endif -class CSizingControlBarG : public baseCSizingControlBarG, public DpiUtil::PerMonitorDpiAwareWindow +class CSizingControlBarG : public baseCSizingControlBarG { DECLARE_DYNAMIC(CSizingControlBarG); diff --git a/Src/Common/sizecbar.cpp b/Src/Common/sizecbar.cpp index 41fd67e2ccd..7e94706010c 100644 --- a/Src/Common/sizecbar.cpp +++ b/Src/Common/sizecbar.cpp @@ -96,6 +96,7 @@ BEGIN_MESSAGE_MAP(CSizingControlBar, baseCSizingControlBar) ON_WM_SIZE() //}}AFX_MSG_MAP ON_MESSAGE(WM_SETTEXT, OnSetText) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP() BOOL CSizingControlBar::Create(LPCTSTR lpszWindowName, @@ -185,6 +186,12 @@ LRESULT CSizingControlBar::OnSetText(WPARAM wParam, LPARAM lParam) return lResult; } +LRESULT CSizingControlBar::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) +{ + UpdateDpi(); + return 0; +} + const bool CSizingControlBar::IsFloating() const { return !IsHorzDocked() && !IsVertDocked(); diff --git a/Src/Common/sizecbar.h b/Src/Common/sizecbar.h index aca78dfd480..02cb671a619 100644 --- a/Src/Common/sizecbar.h +++ b/Src/Common/sizecbar.h @@ -29,6 +29,7 @@ #include // for CDockContext #include // for CTypedPtrArray +#include "utils/DpiAware.h" // MFC 8/VS.NET 2005 has breaking change in OnNcHitTest return value #ifndef NCHITTEST_RESULT @@ -72,7 +73,7 @@ class CSCBDockBar : public CDockBar class CSizingControlBar; typedef CTypedPtrArray CSCBArray; -class CSizingControlBar : public baseCSizingControlBar +class CSizingControlBar : public baseCSizingControlBar, public DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CSizingControlBar); @@ -178,6 +179,7 @@ class CSizingControlBar : public baseCSizingControlBar afx_msg void OnSize(UINT nType, int cx, int cy); //}}AFX_MSG afx_msg LRESULT OnSetText(WPARAM wParam, LPARAM lParam); + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() diff --git a/Src/DirColsDlg.cpp b/Src/DirColsDlg.cpp index 1519e1cd0b9..2c5aefb316c 100644 --- a/Src/DirColsDlg.cpp +++ b/Src/DirColsDlg.cpp @@ -56,12 +56,10 @@ END_MESSAGE_MAP() */ void CDirColsDlg::InitList() { - auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; - // Show selection across entire row. // Also enable infotips. m_listColumns.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); - m_listColumns.InsertColumn(0, _T(""), LVCFMT_LEFT, pointToPixel(148)); + m_listColumns.InsertColumn(0, _T(""), LVCFMT_LEFT, PointToPixel(148)); } /** diff --git a/Src/DirFrame.cpp b/Src/DirFrame.cpp index e3949f4eccc..95f426fcc1e 100644 --- a/Src/DirFrame.cpp +++ b/Src/DirFrame.cpp @@ -112,13 +112,12 @@ int CDirFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) } String sText = _("RO"); - auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; m_wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH | SBPS_NOBORDERS, 0); - m_wndStatusBar.SetPaneInfo(PANE_COMPMETHOD, ID_STATUS_FILTER, 0, pointToPixel(COMPMETHOD_PANEL_WIDTH)); - m_wndStatusBar.SetPaneInfo(PANE_FILTER, ID_STATUS_FILTER, 0, pointToPixel(FILTER_PANEL_WIDTH)); - m_wndStatusBar.SetPaneInfo(PANE_LEFT_RO, ID_STATUS_LEFTDIR_RO, 0, pointToPixel(RO_PANEL_WIDTH)); - m_wndStatusBar.SetPaneInfo(PANE_MIDDLE_RO, ID_STATUS_MIDDLEDIR_RO, 0, pointToPixel(RO_PANEL_WIDTH)); - m_wndStatusBar.SetPaneInfo(PANE_RIGHT_RO, ID_STATUS_RIGHTDIR_RO, 0, pointToPixel(RO_PANEL_WIDTH)); + m_wndStatusBar.SetPaneInfo(PANE_COMPMETHOD, ID_STATUS_FILTER, 0, PointToPixel(COMPMETHOD_PANEL_WIDTH)); + m_wndStatusBar.SetPaneInfo(PANE_FILTER, ID_STATUS_FILTER, 0, PointToPixel(FILTER_PANEL_WIDTH)); + m_wndStatusBar.SetPaneInfo(PANE_LEFT_RO, ID_STATUS_LEFTDIR_RO, 0, PointToPixel(RO_PANEL_WIDTH)); + m_wndStatusBar.SetPaneInfo(PANE_MIDDLE_RO, ID_STATUS_MIDDLEDIR_RO, 0, PointToPixel(RO_PANEL_WIDTH)); + m_wndStatusBar.SetPaneInfo(PANE_RIGHT_RO, ID_STATUS_RIGHTDIR_RO, 0, PointToPixel(RO_PANEL_WIDTH)); m_wndStatusBar.SetPaneText(PANE_LEFT_RO, sText.c_str(), TRUE); m_wndStatusBar.SetPaneText(PANE_MIDDLE_RO, sText.c_str(), TRUE); m_wndStatusBar.SetPaneText(PANE_RIGHT_RO, sText.c_str(), TRUE); diff --git a/Src/DirView.cpp b/Src/DirView.cpp index a376a408337..2c569f2d473 100644 --- a/Src/DirView.cpp +++ b/Src/DirView.cpp @@ -353,7 +353,7 @@ CDirDoc* CDirView::GetDocument() // non-debug version is inline void CDirView::OnInitialUpdate() { - const int iconCX = []() { + const int iconCX = [this]() { const int cx = GetSystemMetrics(SM_CXSMICON); if (cx < 24) return 16; diff --git a/Src/DirView.h b/Src/DirView.h index 83cc0daaf0e..aaf98a3366e 100644 --- a/Src/DirView.h +++ b/Src/DirView.h @@ -20,6 +20,7 @@ #include "UnicodeString.h" #include "DirItemIterator.h" #include "DirActions.h" +#include "utils/DpiAware.h" class FileActionScript; @@ -59,7 +60,7 @@ const UINT DefColumnWidth = 150; * CDiffContext items are linked by storing POSITION of CDiffContext item * as CDirView listitem key. */ -class CDirView : public CListView +class CDirView : public CListView, public DpiAware::PerMonitorDpiAwareWindow { friend struct FileCmpReport; friend DirItemEnumerator; diff --git a/Src/DpiUtil.h b/Src/DpiUtil.h deleted file mode 100644 index b77e70e999a..00000000000 --- a/Src/DpiUtil.h +++ /dev/null @@ -1,115 +0,0 @@ -#pragma once - -#include - -namespace DpiUtil -{ - struct NONCLIENTMETRICS6 - { - UINT cbSize; - int iBorderWidth; - int iScrollWidth; - int iScrollHeight; - int iCaptionWidth; - int iCaptionHeight; - LOGFONTW lfCaptionFont; - int iSmCaptionWidth; - int iSmCaptionHeight; - LOGFONTW lfSmCaptionFont; - int iMenuWidth; - int iMenuHeight; - LOGFONTW lfMenuFont; - LOGFONTW lfStatusFont; - LOGFONTW lfMessageFont; - int iPaddedBorderWidth; - }; - - using GetDpiForWindowType = UINT (__stdcall*)(HWND hwnd); - using SystemParametersInfoForDpiType = BOOL(__stdcall*)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi); - using GetSystemMetricsForDpiType = int(__stdcall*)(int nIndex, UINT dpi); - using OpenThemeDataForDpiType = HTHEME(__stdcall*)(HWND hwnd, LPCWSTR pszClassList, UINT dpi); - - inline GetDpiForWindowType UnsafeGetDpiForWindow = nullptr; - inline SystemParametersInfoForDpiType UnsafeSystemParametersInfoForDpi = nullptr; - inline GetSystemMetricsForDpiType UnsafeGetSystemMetricsForDpi = nullptr; - inline OpenThemeDataForDpiType UnsafeOpenThemeDataForDpi = nullptr; - - inline bool succeeded = []() - { - HMODULE hLibraryUser32 = GetModuleHandleW(L"user32.dll"); - if (!hLibraryUser32) - return false; - HMODULE hLibraryUxTheme = GetModuleHandleW(L"uxtheme.dll"); - if (!hLibraryUxTheme) - return false; - UnsafeGetDpiForWindow = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetDpiForWindow")); - UnsafeSystemParametersInfoForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "SystemParametersInfoForDpi")); - UnsafeGetSystemMetricsForDpi = reinterpret_cast(GetProcAddress(hLibraryUser32, "GetSystemMetricsForDpi")); - UnsafeOpenThemeDataForDpi = reinterpret_cast(GetProcAddress(hLibraryUxTheme, "OpenThemeDataForDpi")); - return true; - }(); - - inline int GetDpiForWindow(HWND hwnd) - { - if (UnsafeGetDpiForWindow) - return UnsafeGetDpiForWindow(hwnd); - return CClientDC(CWnd::FromHandle(hwnd)).GetDeviceCaps(LOGPIXELSX); - } - - inline int GetSystemMetricsForDpi(int nIndex, int dpi) - { - if (UnsafeGetSystemMetricsForDpi) - return UnsafeGetSystemMetricsForDpi(nIndex, dpi); - return GetSystemMetrics(nIndex); - } - - inline HTHEME OpenThemeDataForDpi(HWND hwnd, LPCWSTR pszClassList, UINT dpi) - { - if (DpiUtil::UnsafeOpenThemeDataForDpi) - return UnsafeOpenThemeDataForDpi(hwnd, pszClassList, dpi); - return OpenThemeData(hwnd, pszClassList); - } - - inline void GetMenuLogFont(int dpi, LOGFONT& logFont) - { - if (DpiUtil::UnsafeGetSystemMetricsForDpi) - { - DpiUtil::NONCLIENTMETRICS6 ncm = { sizeof DpiUtil::NONCLIENTMETRICS6 }; - if (DpiUtil::UnsafeSystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof DpiUtil::NONCLIENTMETRICS6, &ncm, 0, dpi)) - logFont = ncm.lfMenuFont; - } - else - { - NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS }; - if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0)) - logFont = ncm.lfMenuFont; - } - } - - template - class PerMonitorDpiAwareWindow - { - T* wnd() { return static_cast(this); } - public: - int GetDpi() - { - if (m_dpi == -1) - m_dpi = GetDpiForWindow(wnd()->m_hWnd); - return m_dpi; - } - - virtual void UpdateDpi(int dpi) - { - m_dpi = dpi; - } - - int GetSystemMetrics(int nIndex) - { - return GetSystemMetricsForDpi(nIndex, GetDpi()); - } - - protected: - int m_dpi = -1; - }; -} - diff --git a/Src/EditorFilepathBar.cpp b/Src/EditorFilepathBar.cpp index 8633bef917e..9f18efbb349 100644 --- a/Src/EditorFilepathBar.cpp +++ b/Src/EditorFilepathBar.cpp @@ -21,6 +21,7 @@ BEGIN_MESSAGE_MAP(CEditorFilePathBar, CDialogBar) ON_NOTIFY_EX (TTN_NEEDTEXT, 0, OnToolTipNotify) ON_CONTROL_RANGE (EN_SETFOCUS, IDC_STATIC_TITLE_PANE0, IDC_STATIC_TITLE_PANE2, OnSetFocusEdit) + ON_MESSAGE(WM_DPICHANGED_AFTERPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP() @@ -51,9 +52,9 @@ BOOL CEditorFilePathBar::Create(CWnd* pParentWnd) CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, CEditorFilePathBar::IDD)) return FALSE; - NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS }; - if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0)) - m_font.CreateFontIndirect(&ncm.lfStatusFont); + LOGFONT lfStatusFont; + if (DpiAware::GetNonClientLogFont(lfStatusFont, offsetof(NONCLIENTMETRICS, lfStatusFont), GetDpi())) + m_font.CreateFontIndirect(&lfStatusFont); // subclass the two custom edit boxes for (int pane = 0; pane < static_cast(std::size(m_Edit)); pane++) @@ -177,6 +178,21 @@ void CEditorFilePathBar::OnSetFocusEdit(UINT id) m_callbackfunc(id - IDC_STATIC_TITLE_PANE0); } +LRESULT CEditorFilePathBar::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) +{ + UpdateDpi(); + + m_font.DeleteObject(); + + LOGFONT lfStatusFont; + if (DpiAware::GetNonClientLogFont(lfStatusFont, offsetof(NONCLIENTMETRICS, lfStatusFont), GetDpi())) + m_font.CreateFontIndirect(&lfStatusFont); + + for (int pane = 0; pane < static_cast(std::size(m_Edit)); pane++) + m_Edit[pane].SetFont(&m_font); + return 0; +} + /** * @brief Get the path for one side * diff --git a/Src/EditorFilepathBar.h b/Src/EditorFilepathBar.h index 117572116e7..7be947d7930 100644 --- a/Src/EditorFilepathBar.h +++ b/Src/EditorFilepathBar.h @@ -12,6 +12,7 @@ #pragma once #include "FilepathEdit.h" +#include "utils/DpiAware.h" #include /** @@ -35,7 +36,7 @@ class IHeaderBar * The bar looks like a statusBar (font, height). The control * displays a tip for each path (as a tooltip). */ -class CEditorFilePathBar : public CDialogBar, public IHeaderBar +class CEditorFilePathBar : public CDialogBar, public DpiAware::PerMonitorDpiAwareWindow, public IHeaderBar { public : CEditorFilePathBar(); @@ -61,6 +62,7 @@ public : //{{AFX_MSG(CEditorFilePathBar) afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pTTTStruct, LRESULT * pResult ); afx_msg void OnSetFocusEdit(UINT id); + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM, LPARAM); //}}AFX_MSG DECLARE_MESSAGE_MAP(); diff --git a/Src/FileFiltersDlg.cpp b/Src/FileFiltersDlg.cpp index 8c34d135c6c..7bedae0943a 100644 --- a/Src/FileFiltersDlg.cpp +++ b/Src/FileFiltersDlg.cpp @@ -112,14 +112,12 @@ void FileFiltersDlg::InitList() // Also enable infotips. m_listFilters.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); - auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; - String title = _("Name"); - m_listFilters.InsertColumn(0, title.c_str(), LVCFMT_LEFT, pointToPixel(112)); + m_listFilters.InsertColumn(0, title.c_str(), LVCFMT_LEFT, PointToPixel(112)); title = _("Description"); - m_listFilters.InsertColumn(1, title.c_str(), LVCFMT_LEFT, pointToPixel(262)); + m_listFilters.InsertColumn(1, title.c_str(), LVCFMT_LEFT, PointToPixel(262)); title = _("Location"); - m_listFilters.InsertColumn(2, title.c_str(), LVCFMT_LEFT, pointToPixel(262)); + m_listFilters.InsertColumn(2, title.c_str(), LVCFMT_LEFT, PointToPixel(262)); title = _(""); m_listFilters.InsertItem(1, title.c_str()); diff --git a/Src/HexMergeFrm.cpp b/Src/HexMergeFrm.cpp index e14873fc666..1b68ebd250b 100644 --- a/Src/HexMergeFrm.cpp +++ b/Src/HexMergeFrm.cpp @@ -73,13 +73,11 @@ CHexMergeFrame::~CHexMergeFrame() */ void CHexMergeFrame::CreateHexWndStatusBar(CStatusBar &wndStatusBar, CWnd *pwndPane) { - auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; - wndStatusBar.Create(pwndPane, WS_CHILD|WS_VISIBLE); wndStatusBar.SetIndicators(0, 3); wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH, 0); - wndStatusBar.SetPaneInfo(1, 0, 0, pointToPixel(60)); - wndStatusBar.SetPaneInfo(2, 0, 0, pointToPixel(60)); + wndStatusBar.SetPaneInfo(1, 0, 0, PointToPixel(60)); + wndStatusBar.SetPaneInfo(2, 0, 0, PointToPixel(60)); wndStatusBar.SetParent(this); wndStatusBar.SetWindowPos(&wndBottom, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } diff --git a/Src/LineFiltersDlg.cpp b/Src/LineFiltersDlg.cpp index 3d80d7a48bd..2be2023db38 100644 --- a/Src/LineFiltersDlg.cpp +++ b/Src/LineFiltersDlg.cpp @@ -87,10 +87,8 @@ void LineFiltersDlg::InitList() // Also enable infotips. m_filtersList.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); - auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; - String title = _("Regular expression"); - m_filtersList.InsertColumn(1, title.c_str(), LVCFMT_LEFT, pointToPixel(375)); + m_filtersList.InsertColumn(1, title.c_str(), LVCFMT_LEFT, PointToPixel(375)); size_t count = m_pList->GetCount(); for (size_t i = 0; i < count; i++) diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index fe079c37636..ad27e61a9c2 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -221,7 +221,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) ON_UPDATE_COMMAND_UI(ID_MRU_FIRST, OnUpdateNoMRUs) ON_UPDATE_COMMAND_UI(ID_NO_MRU, OnUpdateNoMRUs) ON_COMMAND(ID_ACCEL_QUIT, &CMainFrame::OnAccelQuit) - ON_MESSAGE(0x02E0/*WM_DPICHANGED*/, OnDpiChanged) + ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) //}}AFX_MSG_MAP ON_MESSAGE(WMU_CHILDFRAMEADDED, &CMainFrame::OnChildFrameAdded) ON_MESSAGE(WMU_CHILDFRAMEREMOVED, &CMainFrame::OnChildFrameRemoved) @@ -336,11 +336,10 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) theApp.SetIndicators(m_wndStatusBar, StatusbarIndicators, static_cast(std::size(StatusbarIndicators))); - auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; m_wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH | SBPS_NOBORDERS, 0); - m_wndStatusBar.SetPaneInfo(1, ID_STATUS_PLUGIN, 0, pointToPixel(225)); - m_wndStatusBar.SetPaneInfo(2, ID_STATUS_MERGINGMODE, 0, pointToPixel(75)); - m_wndStatusBar.SetPaneInfo(3, ID_STATUS_DIFFNUM, 0, pointToPixel(112)); + m_wndStatusBar.SetPaneInfo(1, ID_STATUS_PLUGIN, 0, PointToPixel(225)); + m_wndStatusBar.SetPaneInfo(2, ID_STATUS_MERGINGMODE, 0, PointToPixel(75)); + m_wndStatusBar.SetPaneInfo(3, ID_STATUS_DIFFNUM, 0, PointToPixel(112)); if (!GetOptionsMgr()->GetBool(OPT_SHOW_STATUSBAR)) CMDIFrameWnd::ShowControlBar(&m_wndStatusBar, false, 0); @@ -2575,15 +2574,15 @@ void CMainFrame::OnAccelQuit() LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { - DefWindowProc(0x2e0/*WM_DPICHANGED*/, wParam, lParam); + Default(); int dpi = HIWORD(wParam); RECT* const prcNew = (RECT*)lParam; + UpdateDpi(); + DpiAware::UpdateAfxDataSysMetrics(dpi); BCMenu::ReopenTheme(dpi); - m_wndTabBar.UpdateDpi(dpi); - return 0; } diff --git a/Src/MainFrm.h b/Src/MainFrm.h index 35e82e60835..9a8e1f1630d 100644 --- a/Src/MainFrm.h +++ b/Src/MainFrm.h @@ -17,7 +17,7 @@ #include "PathContext.h" #include "OptionsDef.h" #include "OptionsMgr.h" -#include "DpiUtil.h" +#include "utils/DpiAware.h" class BCMenu; class CDirView; @@ -50,7 +50,7 @@ CMainFrame * GetMainFrame(); // access to the singleton main frame object /** * @brief Frame class containing save-routines etc */ -class CMainFrame : public CMDIFrameWnd, public DpiUtil::PerMonitorDpiAwareWindow +class CMainFrame : public CMDIFrameWnd, public DpiAware::PerMonitorDpiAwareWindow { friend CLanguageSelect; DECLARE_DYNAMIC(CMainFrame) @@ -122,6 +122,11 @@ class CMainFrame : public CMDIFrameWnd, public DpiUtil::PerMonitorDpiAwareWindow virtual BOOL PreTranslateMessage(MSG* pMsg); virtual void OnUpdateFrameTitle(BOOL bAddToTitle); virtual BOOL PreCreateWindow(CREATESTRUCT& cs); + virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) + { + CalcWindowRectImpl(lpClientRect, nAdjustType); + } + //}}AFX_VIRTUAL // Implementation methods @@ -142,7 +147,7 @@ class CMainFrame : public CMDIFrameWnd, public DpiUtil::PerMonitorDpiAwareWindow CTypedPtrArray m_arrChild; // Tweak MDI client window behavior - class CMDIClient : public CWnd + class CMDIClient : public CWnd, public DpiAware::PerMonitorDpiAwareWindow { static UINT_PTR const m_nRedrawTimer = 1612; virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) @@ -173,9 +178,16 @@ class CMainFrame : public CMDIFrameWnd, public DpiUtil::PerMonitorDpiAwareWindow GetMainFrame()->SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, 0, TRUE, TRUE); } break; + case WM_DPICHANGED_BEFOREPARENT: + UpdateDpi(); + break; } return CWnd::WindowProc(message, wParam, lParam); } + virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) + { + CalcWindowRectImpl(lpClientRect, nAdjustType); + } } m_wndMDIClient; /** @brief Toolbar image table indexes. */ diff --git a/Src/Merge.cpp b/Src/Merge.cpp index 5b5bd240c73..43db194e0fa 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -1190,7 +1190,7 @@ void CMergeApp::TranslateMenu(HMENU h) const */ void CMergeApp::TranslateDialog(HWND h) const { - const int dpi = DpiUtil::GetDpiForWindow(h); + const int dpi = DpiAware::GetDpiForWindow(h); ChangeDialogFont(h, dpi); m_pLangDlg->TranslateDialog(h); } @@ -1211,7 +1211,7 @@ CFont* CMergeApp::GetGUIFont(int dpi) const if (m_mapFontGUI.find(dpi) == m_mapFontGUI.end()) { LOGFONT lfMenuFont; - DpiUtil::GetMenuLogFont(dpi, lfMenuFont); + DpiAware::GetNonClientLogFont(lfMenuFont, offsetof(NONCLIENTMETRICS, lfMenuFont), dpi); const int lfHeight = -MulDiv(9, dpi, 72); if (abs(lfMenuFont.lfHeight) > abs(lfHeight)) lfMenuFont.lfHeight = lfHeight; diff --git a/Src/Merge.vs2017.vcxproj b/Src/Merge.vs2017.vcxproj index 4938736ae58..c104d9523c4 100644 --- a/Src/Merge.vs2017.vcxproj +++ b/Src/Merge.vs2017.vcxproj @@ -473,6 +473,7 @@ + @@ -1104,6 +1105,7 @@ + @@ -1144,7 +1146,6 @@ - diff --git a/Src/Merge.vs2017.vcxproj.filters b/Src/Merge.vs2017.vcxproj.filters index e9d0eee0565..dc844b4ea49 100644 --- a/Src/Merge.vs2017.vcxproj.filters +++ b/Src/Merge.vs2017.vcxproj.filters @@ -916,6 +916,9 @@ MFCGui\PropertyPages\Source Files + + EditLib\Utils + @@ -1647,8 +1650,8 @@ MFCGui\PropertyPages\Header Files - - MFCGui\Header Files + + EditLib\Utils diff --git a/Src/Merge.vs2019.vcxproj b/Src/Merge.vs2019.vcxproj index 8c681cd20e7..33b53361d41 100644 --- a/Src/Merge.vs2019.vcxproj +++ b/Src/Merge.vs2019.vcxproj @@ -475,6 +475,7 @@ + @@ -1106,6 +1107,7 @@ + @@ -1146,7 +1148,6 @@ - diff --git a/Src/Merge.vs2019.vcxproj.filters b/Src/Merge.vs2019.vcxproj.filters index e9d0eee0565..dc844b4ea49 100644 --- a/Src/Merge.vs2019.vcxproj.filters +++ b/Src/Merge.vs2019.vcxproj.filters @@ -916,6 +916,9 @@ MFCGui\PropertyPages\Source Files + + EditLib\Utils + @@ -1647,8 +1650,8 @@ MFCGui\PropertyPages\Header Files - - MFCGui\Header Files + + EditLib\Utils diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index 3b0a773348b..66164f3b048 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -8,7 +8,7 @@ #include "MergeFrameCommon.h" #include "OptionsDef.h" #include "OptionsMgr.h" -#include "DpiUtil.h" +#include "utils/DpiAware.h" #include "Merge.h" #include <../src/mfc/afximpl.h> @@ -19,6 +19,7 @@ BEGIN_MESSAGE_MAP(CMergeFrameCommon, CMDIChildWnd) ON_WM_GETMINMAXINFO() ON_WM_DESTROY() ON_WM_MDIACTIVATE() + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -103,6 +104,17 @@ void CMergeFrameCommon::SetLastCompareResult(int nResult) void CMergeFrameCommon::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { CMDIChildWnd::OnGetMinMaxInfo(lpMMI); + if (IsDpiChanged()) + { + CRect rc; + CFrameWnd* pFrameWnd = GetParentFrame(); + pFrameWnd->GetClientRect(rc); + AdjustWindowRectEx(&rc, GetStyle(), FALSE, GetExStyle()); + lpMMI->ptMaxPosition.x = rc.left; + lpMMI->ptMaxPosition.y = rc.top; + lpMMI->ptMaxSize.x = rc.right - rc.left; + lpMMI->ptMaxSize.y = rc.bottom - rc.top; + } // [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista] // https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM #if _MFC_VER >= 0x0800 @@ -126,3 +138,9 @@ void CMergeFrameCommon::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* if (bActivate) ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEACTIVATED, 0, reinterpret_cast(this)); } + +LRESULT CMergeFrameCommon::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) +{ + UpdateDpi(); + return 0; +} diff --git a/Src/MergeFrameCommon.h b/Src/MergeFrameCommon.h index c9c14fa4373..b51bbebbf46 100644 --- a/Src/MergeFrameCommon.h +++ b/Src/MergeFrameCommon.h @@ -6,9 +6,9 @@ */ #pragma once -#include "DpiUtil.h" +#include "utils/DpiAware.h" -class CMergeFrameCommon: public CMDIChildWnd, public DpiUtil::PerMonitorDpiAwareWindow +class CMergeFrameCommon: public CMDIChildWnd, public DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNCREATE(CMergeFrameCommon) public: @@ -23,6 +23,10 @@ class CMergeFrameCommon: public CMDIChildWnd, public DpiUtil::PerMonitorDpiAware { return TRUE; // https://stackoverflow.com/questions/35553955/getting-rid-of-3d-look-of-mdi-frame-window } + virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) { + CalcWindowRectImpl(lpClientRect, nAdjustType); + } + protected: int m_nLastSplitPos[2]; private: @@ -38,6 +42,8 @@ class CMergeFrameCommon: public CMDIChildWnd, public DpiUtil::PerMonitorDpiAware afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); afx_msg void OnDestroy(); afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd); + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam); + //}}AFX_MSG DECLARE_MESSAGE_MAP() }; diff --git a/Src/MergeStatusBar.cpp b/Src/MergeStatusBar.cpp index 5e44d892339..66488983616 100644 --- a/Src/MergeStatusBar.cpp +++ b/Src/MergeStatusBar.cpp @@ -168,11 +168,10 @@ void CMergeStatusBar::Resize(int widths[]) // Set bottom statusbar panel widths // Kimmo - I don't know why 4 seems to be right for me int borderWidth = 4; // GetSystemMetrics(SM_CXEDGE); - auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; for (int pane = 0; pane < m_nPanes; pane++) { - int paneWidth = widths[pane] - (pointToPixel(RO_PANEL_WIDTH + ENCODING_PANEL_WIDTH + EOL_PANEL_WIDTH) + + int paneWidth = widths[pane] - (PointToPixel(RO_PANEL_WIDTH + ENCODING_PANEL_WIDTH + EOL_PANEL_WIDTH) + (3 * borderWidth)); if (paneWidth < borderWidth) paneWidth = borderWidth; @@ -180,11 +179,11 @@ void CMergeStatusBar::Resize(int widths[]) SetPaneInfo(PANE_PANE0_INFO + pane * nColumnsPerPane, ID_STATUS_PANE0FILE_INFO + pane, SBPS_NORMAL, paneWidth); SetPaneInfo(PANE_PANE0_ENCODING + pane * nColumnsPerPane, ID_STATUS_PANE0FILE_ENCODING + pane, - SBT_OWNERDRAW, pointToPixel(ENCODING_PANEL_WIDTH) - borderWidth); + SBT_OWNERDRAW, PointToPixel(ENCODING_PANEL_WIDTH) - borderWidth); SetPaneInfo(PANE_PANE0_RO + pane * nColumnsPerPane, ID_STATUS_PANE0FILE_RO + pane, - SBPS_NORMAL, pointToPixel(RO_PANEL_WIDTH) - borderWidth); + SBPS_NORMAL, PointToPixel(RO_PANEL_WIDTH) - borderWidth); SetPaneInfo(PANE_PANE0_EOL + pane * nColumnsPerPane, ID_STATUS_PANE0FILE_EOL + pane, - SBT_OWNERDRAW, pointToPixel(EOL_PANEL_WIDTH) - borderWidth); + SBT_OWNERDRAW, PointToPixel(EOL_PANEL_WIDTH) - borderWidth); } } diff --git a/Src/MergeStatusBar.h b/Src/MergeStatusBar.h index 9d75a0d5a32..d91630aa175 100644 --- a/Src/MergeStatusBar.h +++ b/Src/MergeStatusBar.h @@ -14,9 +14,9 @@ #include "MergeEditStatus.h" #include "OptionsDiffColors.h" #include "UnicodeString.h" -#include "DpiUtil.h" +#include "utils/DpiAware.h" -class CMergeStatusBar : public CStatusBar, public DpiUtil::PerMonitorDpiAwareWindow +class CMergeStatusBar : public CStatusBar, public DpiAware::PerMonitorDpiAwareWindow { public : CMergeStatusBar(); diff --git a/Src/OpenView.h b/Src/OpenView.h index bb2fe441161..97137be0a58 100644 --- a/Src/OpenView.h +++ b/Src/OpenView.h @@ -34,7 +34,7 @@ class DropHandler; * The dialog shows also a status of the selected paths (found/not found), * if enabled in the options (enabled by default). */ -class COpenView : public CFormView, public DlgUtils, public DpiUtil::PerMonitorDpiAwareWindow +class COpenView : public CFormView, public DlgUtils, public DpiAware::PerMonitorDpiAwareWindow { protected: // create from serialization only COpenView(); diff --git a/Src/PluginsListDlg.cpp b/Src/PluginsListDlg.cpp index a9cad8f0ca7..6f8747ac59f 100644 --- a/Src/PluginsListDlg.cpp +++ b/Src/PluginsListDlg.cpp @@ -79,14 +79,12 @@ void PluginsListDlg::InitList() // Also enable infotips. m_list.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP); - auto pointToPixel = [dpi = GetDpi()](int point) { return MulDiv(point, dpi, 72); }; - String title = _("Name"); - m_list.InsertColumn(0, title.c_str(), LVCFMT_LEFT, pointToPixel(150)); + m_list.InsertColumn(0, title.c_str(), LVCFMT_LEFT, PointToPixel(150)); title = _("Type"); - m_list.InsertColumn(1, title.c_str(), LVCFMT_LEFT, pointToPixel(75)); + m_list.InsertColumn(1, title.c_str(), LVCFMT_LEFT, PointToPixel(75)); title = _("Description"); - m_list.InsertColumn(2, title.c_str(), LVCFMT_LEFT, pointToPixel(225)); + m_list.InsertColumn(2, title.c_str(), LVCFMT_LEFT, PointToPixel(225)); } /** diff --git a/Src/TrDialogs.cpp b/Src/TrDialogs.cpp index 27a88a5eddf..c778bd37d01 100644 --- a/Src/TrDialogs.cpp +++ b/Src/TrDialogs.cpp @@ -7,7 +7,7 @@ IMPLEMENT_DYNAMIC(CTrPropertyPage, CPropertyPage) IMPLEMENT_DYNAMIC(CTrDialogBar, CDialogBar) BEGIN_MESSAGE_MAP(CTrDialog, CDialog) - ON_MESSAGE(0x02E0/*WM_DPICHANGED*/, OnDpiChanged) + ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) END_MESSAGE_MAP() void StaticDlgUtils::WildcardRemoveDuplicatePatterns(String& patterns) @@ -39,9 +39,8 @@ BOOL CTrDialog::OnInitDialog() LRESULT CTrDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) { - DefWindowProc(0x02e0/*WM_DPICHANGED*/, wParam, lParam); - - UpdateDpi(HIWORD(wParam)); + UpdateDpi(); + Default(); theApp.ChangeDialogFont(m_hWnd, GetDpi()); return 0; } diff --git a/Src/TrDialogs.h b/Src/TrDialogs.h index 88a6abe0aac..46893b2fb63 100644 --- a/Src/TrDialogs.h +++ b/Src/TrDialogs.h @@ -1,7 +1,7 @@ #pragma once #include "DDXHelper.h" -#include "DpiUtil.h" +#include "utils/DpiAware.h" #undef GetDlgItemText #undef SetDlgItemText @@ -42,7 +42,7 @@ class DlgUtils : public StaticDlgUtils } }; -class CTrDialog : public CDialog, public DlgUtils, public DpiUtil::PerMonitorDpiAwareWindow +class CTrDialog : public CDialog, public DlgUtils, public DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CTrDialog) public: @@ -56,7 +56,7 @@ class CTrDialog : public CDialog, public DlgUtils, public DpiUtil::Pe afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); }; -class CTrPropertyPage : public CPropertyPage, public DlgUtils, public DpiUtil::PerMonitorDpiAwareWindow +class CTrPropertyPage : public CPropertyPage, public DlgUtils, public DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CTrPropertyPage) public: @@ -69,7 +69,7 @@ class CTrPropertyPage : public CPropertyPage, public DlgUtils, virtual BOOL OnInitDialog(); }; -class CTrDialogBar : public CDialogBar, public DlgUtils, public DpiUtil::PerMonitorDpiAwareWindow +class CTrDialogBar : public CDialogBar, public DlgUtils, public DpiAware::PerMonitorDpiAwareWindow { DECLARE_DYNAMIC(CTrDialogBar) public: From 55bc2615e1e7da211b884f3e577eafe160e235c9 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Fri, 11 Sep 2020 00:36:42 +0900 Subject: [PATCH 07/23] WIP: Add support for per-monitor DPI awareness (7) --- Externals/crystaledit/Sample/ChildFrm.cpp | 20 +-- Externals/crystaledit/Sample/ChildFrm.h | 6 +- Externals/crystaledit/Sample/MainFrm.cpp | 32 +++- Externals/crystaledit/Sample/MainFrm.h | 6 +- .../Sample/SampleStatic.vs2017.vcxproj | 55 +++++++ .../SampleStatic.vs2017.vcxproj.filters | 9 ++ Externals/crystaledit/Sample/SampleView.cpp | 6 +- .../crystaledit/editlib/ccrystaltextview.cpp | 49 +++--- .../crystaledit/editlib/ccrystaltextview.h | 5 +- .../crystaledit/editlib/utils/DpiAware.cpp | 73 +++++++-- .../crystaledit/editlib/utils/DpiAware.h | 90 ++++++----- .../editlib/utils/mfc_templ_defines.h | 150 ++++++++++++++++++ Src/Common/MDITabBar.cpp | 2 +- Src/Common/MDITabBar.h | 2 +- Src/Common/MessageBoxDialog.cpp | 22 +-- Src/Common/MessageBoxDialog.h | 4 +- Src/Common/SuperComboBox.cpp | 59 ++++--- Src/Common/SuperComboBox.h | 5 +- Src/Common/sizecbar.cpp | 10 +- Src/Common/sizecbar.h | 3 +- Src/DirCompProgressBar.cpp | 2 +- Src/DirFrame.cpp | 2 +- Src/DirView.cpp | 36 +++-- Src/DirView.h | 3 +- Src/EditorFilepathBar.cpp | 9 +- Src/EditorFilepathBar.h | 2 +- Src/EncodingErrorBar.cpp | 2 +- Src/FileFiltersDlg.cpp | 4 +- Src/LineFiltersDlg.cpp | 2 +- Src/MainFrm.cpp | 53 ++++--- Src/MainFrm.h | 12 +- Src/Merge.vs2017.vcxproj | 4 + Src/Merge.vs2017.vcxproj.filters | 3 + Src/Merge.vs2019.vcxproj | 1 + Src/Merge.vs2019.vcxproj.filters | 3 + Src/MergeEditFrm.cpp | 2 +- Src/MergeFrameCommon.cpp | 25 ++- Src/MergeFrameCommon.h | 13 +- Src/MergeStatusBar.cpp | 6 +- Src/MergeStatusBar.h | 2 +- Src/OpenView.cpp | 24 +-- Src/OpenView.h | 2 +- Src/PropArchive.cpp | 2 +- Src/PropBackups.cpp | 2 +- Src/PropCodepage.cpp | 2 +- Src/PropColorSchemes.cpp | 2 +- Src/PropCompare.cpp | 2 +- Src/PropCompareBinary.cpp | 2 +- Src/PropCompareFolder.cpp | 2 +- Src/PropCompareImage.cpp | 2 +- Src/PropCompareTable.cpp | 2 +- Src/PropDirColors.cpp | 2 +- Src/PropEditor.cpp | 2 +- Src/PropGeneral.cpp | 2 +- Src/PropMarkerColors.cpp | 2 +- Src/PropMergeColors.cpp | 2 +- Src/PropRegistry.cpp | 2 +- Src/PropShell.cpp | 2 +- Src/PropSyntaxColors.cpp | 2 +- Src/PropTextColors.cpp | 2 +- Src/TrDialogs.cpp | 36 +++-- Src/TrDialogs.h | 59 +++++-- 62 files changed, 654 insertions(+), 297 deletions(-) create mode 100644 Externals/crystaledit/editlib/utils/mfc_templ_defines.h diff --git a/Externals/crystaledit/Sample/ChildFrm.cpp b/Externals/crystaledit/Sample/ChildFrm.cpp index 39b51d37e4a..f8a026d5f52 100755 --- a/Externals/crystaledit/Sample/ChildFrm.cpp +++ b/Externals/crystaledit/Sample/ChildFrm.cpp @@ -15,10 +15,9 @@ static char THIS_FILE[] = __FILE__; ///////////////////////////////////////////////////////////////////////////// // CChildFrame -IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd) +IMPLEMENT_DYNCREATE(CChildFrame, DpiAware::PerMonitorDpiAwareCWnd) -BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd) - ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) +BEGIN_MESSAGE_MAP(CChildFrame, DpiAware::PerMonitorDpiAwareCWnd) ON_WM_GETMINMAXINFO() END_MESSAGE_MAP() @@ -40,7 +39,7 @@ BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs - return CMDIChildWnd::PreCreateWindow(cs); + return __super::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// @@ -49,12 +48,12 @@ BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) #ifdef _DEBUG void CChildFrame::AssertValid() const { - CMDIChildWnd::AssertValid(); + __super::AssertValid(); } void CChildFrame::Dump(CDumpContext& dc) const { - CMDIChildWnd::Dump(dc); + __super::Dump(dc); } #endif //_DEBUG @@ -64,13 +63,14 @@ void CChildFrame::Dump(CDumpContext& dc) const BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { + UpdateDpi(); return m_wndSplitter.Create(this, 2, 2, CSize(30, 30), pContext); } void CChildFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { __super::OnGetMinMaxInfo(lpMMI); - if (IsDpiChanged()) + if (IsDifferentDpiFromSystemDpi()) { CRect rc; CFrameWnd* pFrameWnd = GetParentFrame(); @@ -82,9 +82,3 @@ void CChildFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) lpMMI->ptMaxSize.y = rc.bottom - rc.top; } } - -LRESULT CChildFrame::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) -{ - UpdateDpi(); - return 0; -} diff --git a/Externals/crystaledit/Sample/ChildFrm.h b/Externals/crystaledit/Sample/ChildFrm.h index 462c763386e..c1a8a447625 100755 --- a/Externals/crystaledit/Sample/ChildFrm.h +++ b/Externals/crystaledit/Sample/ChildFrm.h @@ -6,7 +6,7 @@ #include "utils/DpiAware.h" -class CChildFrame : public CMDIChildWnd, DpiAware::PerMonitorDpiAwareWindow +class CChildFrame : public DpiAware::PerMonitorDpiAwareCWnd { DECLARE_DYNCREATE(CChildFrame) public: @@ -26,9 +26,6 @@ class CChildFrame : public CMDIChildWnd, DpiAware::PerMonitorDpiAwareWindow) -BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) +BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::PerMonitorDpiAwareCWnd) //{{AFX_MSG_MAP(CMainFrame) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code ! ON_WM_CREATE() + ON_MESSAGE(WM_NCCALCSIZE, OnNcCalcSize) ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -56,8 +57,10 @@ CMainFrame::~CMainFrame() int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { - if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) + if (__super::OnCreate(lpCreateStruct) == -1) return -1; + + UpdateDpi(); if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) @@ -87,9 +90,24 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) return 0; } +LRESULT CMainFrame::OnNcCalcSize(WPARAM wParam, LPARAM lParam) +{ + BOOL bCalcValidRects = wParam; + NCCALCSIZE_PARAMS* lpncsp = (NCCALCSIZE_PARAMS*)lParam; + RECT *lprect = (RECT *)lParam; + + LRESULT ret = Default(); + if (bCalcValidRects) + { +// lpncsp->rgrc->top -= 10; + return ret; + } + return ret; +} + LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { - UpdateDpi(); + __super::OnDpiChanged(wParam, lParam); DpiAware::UpdateAfxDataSysMetrics(GetDpi()); Default(); return 0; @@ -100,7 +118,7 @@ BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs - return CMDIFrameWnd::PreCreateWindow(cs); + return __super::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// @@ -109,12 +127,12 @@ BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) #ifdef _DEBUG void CMainFrame::AssertValid() const { - CMDIFrameWnd::AssertValid(); + __super::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { - CMDIFrameWnd::Dump(dc); + __super::Dump(dc); } #endif //_DEBUG diff --git a/Externals/crystaledit/Sample/MainFrm.h b/Externals/crystaledit/Sample/MainFrm.h index 90730d68995..f414981240f 100755 --- a/Externals/crystaledit/Sample/MainFrm.h +++ b/Externals/crystaledit/Sample/MainFrm.h @@ -6,7 +6,7 @@ #include "utils/DpiAware.h" -class CMainFrame : public CMDIFrameWnd, DpiAware::PerMonitorDpiAwareWindow +class CMainFrame : public DpiAware::PerMonitorDpiAwareCWnd { DECLARE_DYNAMIC(CMainFrame) public: @@ -23,9 +23,6 @@ class CMainFrame : public CMDIFrameWnd, DpiAware::PerMonitorDpiAwareWindowfalse MachineX86 + 5.01 true + + SampleStatic.manifest + + + + @@ -231,6 +238,12 @@ true + + SampleStatic.manifest + + + + @@ -268,10 +281,17 @@ false MachineX86 + 5.01 true + + SampleStatic.manifest + + + + @@ -313,6 +333,12 @@ true + + SampleStatic.manifest + + + + @@ -350,10 +376,17 @@ false MachineX86 + 5.01 true + + SampleStatic.manifest + + + + @@ -395,6 +428,12 @@ true + + SampleStatic.manifest + + + + @@ -433,10 +472,17 @@ false MachineX86 + 5.01 true + + SampleStatic.manifest + + + + @@ -479,6 +525,12 @@ true + + SampleStatic.manifest + + + + @@ -508,6 +560,7 @@ + @@ -586,6 +639,7 @@ + @@ -593,6 +647,7 @@ + diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj.filters b/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj.filters index 1559d7e4177..0abd6c6394b 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj.filters +++ b/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj.filters @@ -252,6 +252,9 @@ editlib\dialogs + + editlib\utils + @@ -379,6 +382,12 @@ editlib\dialogs + + editlib\utils + + + editlib\utils + diff --git a/Externals/crystaledit/Sample/SampleView.cpp b/Externals/crystaledit/Sample/SampleView.cpp index 264bc175c74..129f782b8eb 100755 --- a/Externals/crystaledit/Sample/SampleView.cpp +++ b/Externals/crystaledit/Sample/SampleView.cpp @@ -85,11 +85,13 @@ CCrystalTextBuffer *CSampleView::LocateTextBuffer() return &GetDocument()->m_xTextBuffer; } -void CSampleView::OnInitialUpdate() +void CSampleView::OnInitialUpdate() { CCrystalEditViewEx::OnInitialUpdate(); - SetFont(GetDocument()->m_lf); + LOGFONT lf{ GetDocument()->m_lf }; + lf.lfHeight = MulDiv(lf.lfHeight, m_dpi, 96); + SetFont(lf); SetColorContext(GetDocument()->m_pSyntaxColors); SetMarkersContext(GetDocument()->m_pMarkers); if (GetDocument()->m_xTextBuffer.GetTableEditing()) diff --git a/Externals/crystaledit/editlib/ccrystaltextview.cpp b/Externals/crystaledit/editlib/ccrystaltextview.cpp index 516bdbac67c..c1cafcf0e75 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview.cpp @@ -171,7 +171,7 @@ CCrystalTextView::RENDERING_MODE CCrystalTextView::s_nRenderingModeDefault = REN static ptrdiff_t FindStringHelper(LPCTSTR pszLineBegin, size_t nLineLength, LPCTSTR pszFindWhere, LPCTSTR pszFindWhat, DWORD dwFlags, int &nLen, RxNode *&rxnode, RxMatchRes *rxmatch); -BEGIN_MESSAGE_MAP (CCrystalTextView, CView) +BEGIN_MESSAGE_MAP (CCrystalTextView, DpiAware::PerMonitorDpiAwareCWnd) //{{AFX_MSG_MAP(CCrystalTextView) ON_WM_DESTROY () ON_WM_ERASEBKGND () @@ -228,9 +228,9 @@ ON_COMMAND (ID_EDIT_TEXT_END, OnTextEnd) ON_COMMAND (ID_EDIT_EXT_TEXT_END, OnExtTextEnd) // Standard printing commands ON_COMMAND (ID_FILE_PAGE_SETUP, OnFilePageSetup) -ON_COMMAND (ID_FILE_PRINT, CView::OnFilePrint) -ON_COMMAND (ID_FILE_PRINT_DIRECT, CView::OnFilePrint) -ON_COMMAND (ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) +ON_COMMAND (ID_FILE_PRINT, __super::OnFilePrint) +ON_COMMAND (ID_FILE_PRINT_DIRECT, __super::OnFilePrint) +ON_COMMAND (ID_FILE_PRINT_PREVIEW, __super::OnFilePrintPreview) // Status ON_UPDATE_COMMAND_UI (ID_EDIT_INDICATOR_CRLF, OnUpdateIndicatorCRLF) ON_UPDATE_COMMAND_UI (ID_EDIT_INDICATOR_POSITION, OnUpdateIndicatorPosition) @@ -594,7 +594,7 @@ PreCreateWindow (CREATESTRUCT & cs) //END SW } cs.lpszClass = AfxRegisterWndClass (CS_DBLCLKS); - return CView::PreCreateWindow (cs); + return __super::PreCreateWindow (cs); } @@ -3224,7 +3224,7 @@ GoToLine (int nLine, bool bRelative) void CCrystalTextView:: OnInitialUpdate () { - CView::OnInitialUpdate (); + __super::OnInitialUpdate (); UpdateDpi (); CString sDoc = GetDocument ()->GetPathName (), sExt = GetExt (sDoc); if (!sExt.IsEmpty()) @@ -3293,7 +3293,7 @@ OnInitialUpdate () void CCrystalTextView:: OnPrepareDC (CDC * pDC, CPrintInfo * pInfo /*= nullptr*/) { - CView::OnPrepareDC (pDC, pInfo); + __super::OnPrepareDC (pDC, pInfo); if (pInfo != nullptr) { @@ -3833,7 +3833,7 @@ OnDestroy () DetachFromBuffer (); m_hAccel = nullptr; - CView::OnDestroy (); + __super::OnDestroy (); if (m_pCacheBitmap != nullptr) { @@ -3852,7 +3852,7 @@ OnEraseBkgnd (CDC * pdc) void CCrystalTextView:: OnSize (UINT nType, int cx, int cy) { - CView::OnSize (nType, cx, cy); + __super::OnSize (nType, cx, cy); //BEGIN SW // get char position of top left visible character with old cached word wrap @@ -3981,7 +3981,7 @@ RecalcVertScrollBar (bool bPositionOnly /*= false*/, bool bRedraw /*= true */) void CCrystalTextView:: OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar) { - CView::OnVScroll (nSBCode, nPos, pScrollBar); + __super::OnVScroll (nSBCode, nPos, pScrollBar); // Note we cannot use nPos because of its 16-bit nature SCROLLINFO si = {0}; @@ -4092,7 +4092,7 @@ void CCrystalTextView:: OnHScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar) { // Default handler not needed - //CView::OnHScroll (nSBCode, nPos, pScrollBar); + //__super::OnHScroll (nSBCode, nPos, pScrollBar); // Again, we cannot use nPos because it's 16-bit SCROLLINFO si = {0}; @@ -4187,7 +4187,7 @@ OnSetCursor (CWnd * pWnd, UINT nHitTest, UINT message) } return true; } - return CView::OnSetCursor (pWnd, nHitTest, message); + return __super::OnSetCursor (pWnd, nHitTest, message); } int CCrystalTextView:: @@ -4631,7 +4631,7 @@ AdjustTextPoint (CPoint & point) void CCrystalTextView:: OnSetFocus (CWnd * pOldWnd) { - CView::OnSetFocus (pOldWnd); + __super::OnSetFocus (pOldWnd); m_bFocused = true; if (m_ptSelStart != m_ptSelEnd) @@ -4830,7 +4830,7 @@ EnsureVisible (CPoint pt) void CCrystalTextView:: OnKillFocus (CWnd * pNewWnd) { - CView::OnKillFocus (pNewWnd); + __super::OnKillFocus (pNewWnd); m_bFocused = false; UpdateCaret (); @@ -4847,7 +4847,7 @@ OnKillFocus (CWnd * pNewWnd) void CCrystalTextView:: OnSysColorChange () { - CView::OnSysColorChange (); + __super::OnSysColorChange (); Invalidate (); } @@ -5040,6 +5040,7 @@ GetResourceHandle () int CCrystalTextView:: OnCreate (LPCREATESTRUCT lpCreateStruct) { + UpdateDpi (); m_lfBaseFont = {}; _tcscpy_s (m_lfBaseFont.lfFaceName, _T ("FixedSys")); m_lfBaseFont.lfHeight = 0; @@ -5051,7 +5052,7 @@ OnCreate (LPCREATESTRUCT lpCreateStruct) m_lfBaseFont.lfQuality = DEFAULT_QUALITY; m_lfBaseFont.lfPitchAndFamily = DEFAULT_PITCH; - if (CView::OnCreate (lpCreateStruct) == -1) + if (__super::OnCreate (lpCreateStruct) == -1) return -1; ASSERT (m_hAccel == nullptr); @@ -5094,7 +5095,7 @@ PreTranslateMessage (MSG * pMsg) OnLButtonTrippleClk(static_cast(pMsg->wParam), { GET_X_LPARAM(pMsg->lParam), GET_Y_LPARAM(pMsg->lParam) }); return true; } - return CView::PreTranslateMessage (pMsg); + return __super::PreTranslateMessage (pMsg); } CPoint CCrystalTextView:: @@ -6345,7 +6346,7 @@ OnMouseWheel (UINT nFlags, short zDelta, CPoint pt) ScrollToSubLine(nNewTopSubLine, true); UpdateSiblingScrollPos(false); - return CView::OnMouseWheel (nFlags, zDelta, pt); + return __super::OnMouseWheel (nFlags, zDelta, pt); } void CCrystalTextView:: @@ -6365,7 +6366,7 @@ OnMouseHWheel (UINT nFlags, short zDelta, CPoint pt) UpdateCaret (); UpdateSiblingScrollPos (true); - CView::OnMouseHWheel (nFlags, zDelta, pt); + __super::OnMouseHWheel (nFlags, zDelta, pt); } void CCrystalTextView:: @@ -6748,7 +6749,7 @@ LRESULT CCrystalTextView:: OnDpiChangedBeforeParent (WPARAM wParam, LPARAM lParam) { const int oldDpi = m_dpi; - UpdateDpi (); + __super::OnDpiChangedBeforeParent(wParam, lParam); if (m_dpi != oldDpi) { m_lfBaseFont.lfHeight = MulDiv(m_lfBaseFont.lfHeight, m_dpi, oldDpi); @@ -6823,7 +6824,7 @@ BOOL CCrystalTextView::OnCmdMsg( UINT nID, int nCode, void* pExtra, AFX_CMDHANDL { // just look for commands if( nCode != CN_COMMAND || pExtra != nullptr ) - return CView::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ); + return __super::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ); // handle code: // each command that is not related to incremental search @@ -6831,17 +6832,17 @@ BOOL CCrystalTextView::OnCmdMsg( UINT nID, int nCode, void* pExtra, AFX_CMDHANDL if( nID == ID_EDIT_FIND_INCREMENTAL_FORWARD || nID == ID_EDIT_FIND_INCREMENTAL_BACKWARD || nID == ID_EDIT_DELETE_BACK ) - return CView::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ); + return __super::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ); if( nID >= ID_EDIT_FIRST && nID <= ID_EDIT_LAST ) m_bIncrementalSearchForward = m_bIncrementalSearchBackward = false; - return CView::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ); + return __super::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ); } void CCrystalTextView::OnChar( wchar_t nChar, UINT nRepCnt, UINT nFlags ) { - CView::OnChar( nChar, nRepCnt, nFlags ); + __super::OnChar( nChar, nRepCnt, nFlags ); // we only have to handle character-input, if we are in incremental search mode if( !m_bIncrementalSearchForward && !m_bIncrementalSearchBackward ) diff --git a/Externals/crystaledit/editlib/ccrystaltextview.h b/Externals/crystaledit/editlib/ccrystaltextview.h index 38dafd96daf..e683b020648 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.h +++ b/Externals/crystaledit/editlib/ccrystaltextview.h @@ -83,7 +83,7 @@ enum : unsigned * not implement text editing. There are classes inherited from this * class which implement text editing. */ -class EDITPADC_CLASS CCrystalTextView : public CView, public DpiAware::PerMonitorDpiAwareWindow +class EDITPADC_CLASS CCrystalTextView : public DpiAware::PerMonitorDpiAwareCWnd { DECLARE_DYNCREATE (CCrystalTextView) @@ -814,9 +814,6 @@ protected : virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo); virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo); virtual void OnPrint (CDC * pDC, CPrintInfo * pInfo); - virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) { - CalcWindowRectImpl(lpClientRect, nAdjustType); - } //}}AFX_VIRTUAL diff --git a/Externals/crystaledit/editlib/utils/DpiAware.cpp b/Externals/crystaledit/editlib/utils/DpiAware.cpp index 9e4809051db..6baa7143543 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.cpp +++ b/Externals/crystaledit/editlib/utils/DpiAware.cpp @@ -1,5 +1,6 @@ #include "StdAfx.h" #include "DpiAware.h" +#include #include <../src/mfc/afximpl.h> namespace DpiAware @@ -11,11 +12,11 @@ namespace DpiAware AdjustWindowRectExForDpiType AdjustWindowRectExForDpi = nullptr; LoadIconWithScaleDownType LoadIconWithScaleDown = nullptr; - short SMIconOnInit = 0; + int DPIOnInit = 0; bool DpiAwareSupport = []() { - SMIconOnInit = static_cast(::GetSystemMetrics(SM_CXSMICON)); + DPIOnInit = MulDiv(96, ::GetSystemMetrics(SM_CXSMICON), 16); HMODULE hLibraryUser32 = GetModuleHandleW(L"user32.dll"); if (hLibraryUser32) { @@ -43,7 +44,7 @@ namespace DpiAware GetSystemMetricsForDpi = [](int nIndex, UINT dpi) -> int { return GetSystemMetrics(nIndex); }; if (!LoadIconWithScaleDown) LoadIconWithScaleDown = [](HINSTANCE hinst, PCWSTR pszName, int cx, int cy, HICON *phico) -> HRESULT - { *phico = LoadIcon(hinst, pszName); return *phico != nullptr ? S_OK : E_FAIL; }; + { *phico = LoadIconW(hinst, pszName); return *phico != nullptr ? S_OK : E_FAIL; }; if (!OpenThemeDataForDpi) { OpenThemeDataForDpi = [](HWND hwnd, LPCWSTR pszClassList, UINT dpi) -> HTHEME { return OpenThemeData(hwnd, pszClassList); }; @@ -63,20 +64,13 @@ namespace DpiAware bool GetNonClientLogFont(LOGFONT& logFont, size_t memberOffset, int dpi) { + DpiAware::NONCLIENTMETRICS6 ncm{}; + ncm.cbSize = sizeof(NONCLIENTMETRICS); if (DpiAware::DpiAwareSupport) - { - DpiAware::NONCLIENTMETRICS6 ncm = { sizeof DpiAware::NONCLIENTMETRICS6 }; - if (!SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof DpiAware::NONCLIENTMETRICS6, &ncm, 0, dpi)) - return false; - memcpy(&logFont, (char*)&ncm + memberOffset, sizeof(LOGFONT)); - } - else - { - NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS }; - if (!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0)) - return false; - memcpy(&logFont, (char*)&ncm + memberOffset, sizeof(LOGFONT)); - } + ncm.cbSize = sizeof DpiAware::NONCLIENTMETRICS6; + if (!SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, ncm.cbSize, static_cast(&ncm), 0, dpi)) + return false; + memcpy(&logFont, (char*)&ncm + memberOffset, sizeof(LOGFONT)); return true; } @@ -90,5 +84,52 @@ namespace DpiAware afxData.cyPixelsPerInch = dpi; } + void ListView_UpdateColumnWidths(HWND hwnd, int olddpi, int newdpi) + { + HWND hwndHeader = ListView_GetHeader(hwnd); + const int nColumns = Header_GetItemCount(hwndHeader); + for (int i = 0; i < nColumns; ++i) + { + const int nColumnWidth = MulDiv(ListView_GetColumnWidth(hwnd, i), newdpi, olddpi); + ListView_SetColumnWidth(hwnd, i, nColumnWidth); + } + } + + void Dialog_UpdateControlInnerWidths(HWND hwnd, int olddpi, int newdpi) + { + struct Dpis { int olddpi, newdpi; HWND hwndParent; } dpis{ olddpi, newdpi, hwnd }; + auto enumfunc = [](HWND hwnd, LPARAM lParam) -> BOOL + { + const Dpis *pdpis = (const Dpis *)lParam; + TCHAR name[256]; + GetClassName(hwnd, name, sizeof(name) / sizeof(TCHAR)); + if (_tcsicmp(name, _T("SysListView32")) == 0 && pdpis->hwndParent == GetParent(hwnd)) + ListView_UpdateColumnWidths(hwnd, pdpis->olddpi, pdpis->newdpi); + return TRUE; + }; + EnumChildWindows(hwnd, enumfunc, (LPARAM)&dpis); + } + + HIMAGELIST LoadShellImageList(int dpi) + { + SHFILEINFO sfi{}; + if (dpi == DpiAware::DPIOnInit) + { + return (HIMAGELIST)SHGetFileInfo(_T(""), 0, + &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); + } + else + { + int size = SHIL_EXTRALARGE; + if (dpi < 96 * 2) + size = SHIL_SMALL; + else if (dpi < 96 * 3) + size = SHIL_LARGE; + IImageList *pImageList = nullptr; + if (FAILED(SHGetImageList(size, IID_IImageList, (void**)&pImageList))) + return nullptr; + return IImageListToHIMAGELIST(pImageList); + } + } } diff --git a/Externals/crystaledit/editlib/utils/DpiAware.h b/Externals/crystaledit/editlib/utils/DpiAware.h index 66d01ba2ef2..dd41d595bf1 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.h +++ b/Externals/crystaledit/editlib/utils/DpiAware.h @@ -1,6 +1,7 @@ #pragma once #include +#include "mfc_templ_defines.h" #ifndef WM_DPICHANGED #define WM_DPICHANGED 0x02E0 @@ -10,35 +11,21 @@ namespace DpiAware { - struct NONCLIENTMETRICS6 + struct NONCLIENTMETRICS6 : public NONCLIENTMETRICS { - UINT cbSize; - int iBorderWidth; - int iScrollWidth; - int iScrollHeight; - int iCaptionWidth; - int iCaptionHeight; - LOGFONTW lfCaptionFont; - int iSmCaptionWidth; - int iSmCaptionHeight; - LOGFONTW lfSmCaptionFont; - int iMenuWidth; - int iMenuHeight; - LOGFONTW lfMenuFont; - LOGFONTW lfStatusFont; - LOGFONTW lfMessageFont; int iPaddedBorderWidth; }; - using AdjustWindowRectExForDpiType = BOOL (__stdcall*)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi); - using GetDpiForWindowType = UINT (__stdcall*)(HWND hwnd); + using AdjustWindowRectExForDpiType = BOOL(__stdcall*)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi); + using GetDpiForWindowType = UINT(__stdcall*)(HWND hwnd); using SystemParametersInfoForDpiType = BOOL(__stdcall*)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi); using GetSystemMetricsForDpiType = int(__stdcall*)(int nIndex, UINT dpi); using OpenThemeDataForDpiType = HTHEME(__stdcall*)(HWND hwnd, LPCWSTR pszClassList, UINT dpi); - using LoadIconWithScaleDownType = HRESULT(__stdcall*)(HINSTANCE hinst, PCWSTR pszName, int cx, int cy, HICON *phico); + using LoadIconWithScaleDownType = HRESULT(__stdcall*)(HINSTANCE hinst, PCWSTR pszName, int cx, int cy, HICON* phico); extern bool DpiAwareSupport; - extern short SMIconOnInit; + extern int DPIOnInit; + extern AdjustWindowRectExForDpiType AdjustWindowRectExForDpi; extern GetDpiForWindowType GetDpiForWindow; extern SystemParametersInfoForDpiType SystemParametersInfoForDpi; @@ -49,50 +36,65 @@ namespace DpiAware void GetPointLogFont(LOGFONT& logFont, float point, const TCHAR* lfFaceName, int dpi); bool GetNonClientLogFont(LOGFONT& logFont, size_t memberOffset, int dpi); void UpdateAfxDataSysMetrics(int dpi); + void ListView_UpdateColumnWidths(HWND hwnd, int olddpi, int newdpi); + void Dialog_UpdateControlInnerWidths(HWND hwnd, int olddpi, int newdpi); + HIMAGELIST LoadShellImageList(int dpi); - template - class PerMonitorDpiAwareWindow + template + class PerMonitorDpiAwareCWnd : public Base { - T* wnd() { return static_cast(this); } public: - int GetDpi() - { - if (m_dpi == -1) - UpdateDpi(); - return m_dpi; - } + using this_type = PerMonitorDpiAwareCWnd; + using base_type = Base; + using Base::Base; + + int GetDpi() const { return m_dpi; } - int PointToPixel(int point) { return MulDiv(point, GetDpi(), 72); } + int PointToPixel(int point) const { return MulDiv(point, m_dpi, 72); } template - int PointToPixel(T point) { return static_cast((point * GetDpi()) / 72); } + int PointToPixel(T point) const { return static_cast((point * m_dpi) / 72); } void UpdateDpi() { - m_dpi = GetDpiForWindow(wnd()->m_hWnd); - m_cxSMIcon = static_cast(GetSystemMetricsForDpi(SM_CXSMICON, m_dpi)); + m_dpi = GetDpiForWindow(m_hWnd); } - int GetSystemMetrics(int nIndex) { return GetSystemMetricsForDpi(nIndex, GetDpi()); } + int GetSystemMetrics(int nIndex) { return GetSystemMetricsForDpi(nIndex, m_dpi); } BOOL AdjustWindowRectEx(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle) { - return DpiAware::AdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, GetDpi()); + return DpiAware::AdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, m_dpi); } - void CalcWindowRectImpl(LPRECT lpClientRect, UINT nAdjustType = CWnd::adjustBorder) + virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = CWnd::adjustBorder) { - DWORD dwExStyle = GetWindowLong(wnd()->m_hWnd, GWL_EXSTYLE); + DWORD dwExStyle = GetWindowLong(m_hWnd, GWL_EXSTYLE); if (nAdjustType == 0) dwExStyle &= ~WS_EX_CLIENTEDGE; - DWORD dwStyle = (DWORD)GetWindowLong(wnd()->m_hWnd, GWL_STYLE); - DpiAware::AdjustWindowRectExForDpi(lpClientRect, dwStyle, FALSE, dwExStyle, GetDpi()); + DWORD dwStyle = (DWORD)GetWindowLong(m_hWnd, GWL_STYLE); + DpiAware::AdjustWindowRectExForDpi(lpClientRect, dwStyle, FALSE, dwExStyle, m_dpi); + } + + bool IsDifferentDpiFromSystemDpi() const + { + return DPIOnInit != m_dpi; } - bool IsDpiChanged() const + afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam) { - return SMIconOnInit != m_cxSMIcon; + UpdateDpi(); + return 0; } - protected: - short m_cxSMIcon = SMIconOnInit; - int m_dpi = -1; + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) + { + UpdateDpi(); + return 0; + } + + int m_dpi = DPIOnInit; + + BEGIN_MESSAGE_MAP_INLINE(this_type, base_type) + ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) + END_MESSAGE_MAP_INLINE() }; } diff --git a/Externals/crystaledit/editlib/utils/mfc_templ_defines.h b/Externals/crystaledit/editlib/utils/mfc_templ_defines.h new file mode 100644 index 00000000000..3f7c1fa311f --- /dev/null +++ b/Externals/crystaledit/editlib/utils/mfc_templ_defines.h @@ -0,0 +1,150 @@ +// Usage is granted as specified in the following "Boost Software License - Version 1.0", but usage and / or distribution and / or selling as a or as part of a commercial Fortran to C / C++ translation - tool and / or translation - service is prohibited. +// +// +// Boost Software License - Version 1.0 - August 17th, 2003 +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license(the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third - parties to whom the Software is furnished to +// do so, all subject to the following : +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine - executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON - INFRINGEMENT.IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +/*============================================================================= +Copyright (c) 2019 Tobias Loew + +Distributed under the Boost Software License, Version 1.0. (See above or at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ + + +#pragma once + +/////////////////////////////////////////////////////////////////////////////// +// +// mfc_templ_defines.h +// +// inline versions of MFC's message-map macros that work within template-class +// (but also work in non-template classes) +// usage: +// +// template<...> +// class derived : public base { +// +// public: +// using this_type = derived; +// using base_type = base; +// +// ... +// +// BEGIN_MESSAGE_MAP_INLINE(this_type, base_type) +// ON_WM_... +// END_MESSAGE_MAP_INLINE() +// }; +// +// // no DECLARE_MESSAGE_MAP... or IMPLEMENT_MESSAGE_MAP... needed! +// +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// definition for MESSAGE_MAP: + +// the original, non-template version +/********************************************** + +#define BEGIN_MESSAGE_MAP(theClass, baseClass) \ + PTM_WARNING_DISABLE \ + const AFX_MSGMAP* theClass::GetMessageMap() const \ + { return GetThisMessageMap(); } \ + const AFX_MSGMAP* PASCAL theClass::GetThisMessageMap() \ + { \ + typedef theClass ThisClass; \ + typedef baseClass TheBaseClass; \ + static const AFX_MSGMAP_ENTRY _messageEntries[] = \ + { + +#define END_MESSAGE_MAP() \ + {0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } \ + }; \ + static const AFX_MSGMAP messageMap = \ + { &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; \ + return &messageMap; \ + } \ + PTM_WARNING_RESTORE + +*************************************************/ + +#ifndef POINTER_CAST_WARNING_DISABLE + +#define POINTER_CAST_WARNING_DISABLE \ + __pragma(warning( push )) \ + __pragma(warning( disable : 4407 )) +#define POINTER_CAST_WARNING_RESTORE \ + __pragma(warning( pop )) + +#endif + + +#ifndef PTM_WARNING_DISABLE + +#define PTM_WARNING_DISABLE \ + __pragma(warning( push )) \ + __pragma(warning( disable : 4867 )) +#define PTM_WARNING_RESTORE \ + __pragma(warning( pop )) + +#endif + + +#define STATIC_ASSERT_CCMDTARGET_IS_FIRST_BASE(theClass) \ + static_assert(offsetof(theClass, CCmdTarget::m_dwRef) == offsetof(CCmdTarget, m_dwRef), "") + + +// class inline version +#define BEGIN_MESSAGE_MAP_INLINE(theClass, baseClass) \ + protected: \ + PTM_WARNING_DISABLE \ + POINTER_CAST_WARNING_DISABLE \ + virtual const AFX_MSGMAP* GetMessageMap() const \ + { return GetThisMessageMap(); } \ + static const AFX_MSGMAP* PASCAL GetThisMessageMap() \ + { \ + static_assert(offsetof(theClass, CCmdTarget::m_dwRef) == offsetof(CCmdTarget, m_dwRef), "");\ + typedef theClass ThisClass; \ + typedef baseClass TheBaseClass; \ + __pragma(warning(push)) \ + __pragma(warning(disable: 4640)) /* message maps can only be called by single threaded message pump */ \ + static const AFX_MSGMAP_ENTRY _messageEntries[] = \ + { + + + +#define END_MESSAGE_MAP_INLINE() \ + {0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } \ + }; \ + static const AFX_MSGMAP messageMap = \ + { &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; \ + return &messageMap; \ + } \ + POINTER_CAST_WARNING_RESTORE \ + PTM_WARNING_RESTORE + + +#define BEGIN_MESSAGE_MAP_INLINE_THIS_BASE() BEGIN_MESSAGE_MAP_INLINE(this_type, base_type) + + + diff --git a/Src/Common/MDITabBar.cpp b/Src/Common/MDITabBar.cpp index ace4c5a2332..1014de5d909 100644 --- a/Src/Common/MDITabBar.cpp +++ b/Src/Common/MDITabBar.cpp @@ -28,7 +28,7 @@ BEGIN_MESSAGE_MAP(CMDITabBar, CControlBar) ON_WM_MOUSELEAVE() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() - ON_MESSAGE(WM_DPICHANGED_AFTERPARENT, OnDpiChangedBeforeParent) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) //}}AFX_MSG_MAP END_MESSAGE_MAP() diff --git a/Src/Common/MDITabBar.h b/Src/Common/MDITabBar.h index f691d2dd464..893bf9eb901 100644 --- a/Src/Common/MDITabBar.h +++ b/Src/Common/MDITabBar.h @@ -11,7 +11,7 @@ /** * @brief Class for Tab bar. */ -class CMDITabBar : public CControlBar, public DpiAware::PerMonitorDpiAwareWindow +class CMDITabBar : public DpiAware::PerMonitorDpiAwareCWnd { DECLARE_DYNAMIC(CMDITabBar) diff --git a/Src/Common/MessageBoxDialog.cpp b/Src/Common/MessageBoxDialog.cpp index 42aabbf0ffe..4691e328771 100644 --- a/Src/Common/MessageBoxDialog.cpp +++ b/Src/Common/MessageBoxDialog.cpp @@ -85,7 +85,7 @@ IMPLEMENT_DYNAMIC(CMessageBoxDialog, CDialog) */ CMessageBoxDialog::CMessageBoxDialog ( CWnd* pParent, CString strMessage, CString strTitle, UINT nStyle, UINT nHelp ) - : CDialog ( CMessageBoxDialog::IDD, pParent ) + : DpiAware::PerMonitorDpiAwareCWnd ( CMessageBoxDialog::IDD, pParent ) , m_strMessage(strMessage) , m_strTitle(strTitle.IsEmpty() ? AfxGetAppName() : strTitle) , m_nStyle(nStyle) @@ -421,7 +421,7 @@ INT_PTR CMessageBoxDialog::DoModal ( ) } // Call the parent method. - return CDialog::DoModal(); + return __super::DoModal(); } /* @@ -456,7 +456,7 @@ void CMessageBoxDialog::EndDialog ( int nResult ) } // Call the parent method. - CDialog::EndDialog(nResult); + __super::EndDialog(nResult); } /* @@ -468,8 +468,10 @@ void CMessageBoxDialog::EndDialog ( int nResult ) */ BOOL CMessageBoxDialog::OnInitDialog ( ) { + UpdateDpi(); + // Call the parent method. - if ( !CDialog::OnInitDialog() ) + if ( !__super::OnInitDialog() ) { // Return with an error. return FALSE; @@ -614,7 +616,7 @@ BOOL CMessageBoxDialog::OnCmdMsg ( UINT nID, int nCode, void* pExtra, } // Call the parent method. - return CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); + return __super::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); } /* @@ -692,7 +694,7 @@ BOOL CMessageBoxDialog::PreTranslateMessage ( MSG* pMsg ) } // Call the parent method. - return CDialog::PreTranslateMessage(pMsg); + return __super::PreTranslateMessage(pMsg); } /* @@ -774,7 +776,7 @@ void CMessageBoxDialog::OnTimer ( UINT_PTR nIDEvent ) } // Call the parent method. - CDialog::OnTimer(nIDEvent); + __super::OnTimer(nIDEvent); } BOOL CMessageBoxDialog::OnEraseBkgnd(CDC* pDC) @@ -796,7 +798,7 @@ HBRUSH CMessageBoxDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) pDC->SetTextColor(m_clrMainInstructionFont); return static_cast(GetSysColorBrush(COLOR_WINDOW)); } - return CDialog::OnCtlColor(pDC, pWnd, nCtlColor); + return __super::OnCtlColor(pDC, pWnd, nCtlColor); } LRESULT CMessageBoxDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) @@ -846,10 +848,10 @@ BOOL CMessageBoxDialog::OnWndMsg ( UINT message, WPARAM wParam, LPARAM lParam, } // Call the parent method. - return CDialog::OnWndMsg(message, wParam, lParam, pResult); + return __super::OnWndMsg(message, wParam, lParam, pResult); } -BEGIN_MESSAGE_MAP(CMessageBoxDialog, CDialog) +BEGIN_MESSAGE_MAP(CMessageBoxDialog, DpiAware::PerMonitorDpiAwareCWnd) ON_WM_TIMER() ON_WM_ERASEBKGND() ON_WM_CTLCOLOR() diff --git a/Src/Common/MessageBoxDialog.h b/Src/Common/MessageBoxDialog.h index 7f2dfcfd55c..d39ded47beb 100644 --- a/Src/Common/MessageBoxDialog.h +++ b/Src/Common/MessageBoxDialog.h @@ -86,7 +86,7 @@ ////////////////////////////////////////////////////////////////////////////// // Class definition. -class CMessageBoxDialog : public CDialog, public DpiAware::PerMonitorDpiAwareWindow +class CMessageBoxDialog : public DpiAware::PerMonitorDpiAwareCWnd { DECLARE_DYNAMIC(CMessageBoxDialog) @@ -184,8 +184,6 @@ class CMessageBoxDialog : public CDialog, public DpiAware::PerMonitorDpiAwareWin // Method for handling messages before dispatching them. virtual BOOL PreTranslateMessage ( MSG* pMsg ); - virtual void CallWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) { CalcWindowRectImpl(lpClientRect, nAdjustType); } - // Method for handling a timer event. afx_msg void OnTimer ( UINT_PTR nIDEvent ); afx_msg BOOL OnEraseBkgnd( CDC* pDC ); diff --git a/Src/Common/SuperComboBox.cpp b/Src/Common/SuperComboBox.cpp index 1143ee372ca..047f1fa64ce 100644 --- a/Src/Common/SuperComboBox.cpp +++ b/Src/Common/SuperComboBox.cpp @@ -23,7 +23,7 @@ T &placement_cast(void *p) ///////////////////////////////////////////////////////////////////////////// // CSuperComboBox -HIMAGELIST CSuperComboBox::m_himlSystem = nullptr; +std::map CSuperComboBox::m_himlSystemMap; CSuperComboBox::CSuperComboBox() : m_pDropHandler(nullptr) @@ -66,6 +66,7 @@ BEGIN_MESSAGE_MAP(CSuperComboBox, CComboBoxEx) ON_WM_DESTROY() ON_WM_DRAWITEM() ON_NOTIFY_REFLECT(CBEN_GETDISPINFO, OnGetDispInfo) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -74,7 +75,8 @@ END_MESSAGE_MAP() void CSuperComboBox::PreSubclassWindow() { - CComboBoxEx::PreSubclassWindow(); + UpdateDpi(); + __super::PreSubclassWindow(); m_pDropHandler = new DropHandler(std::bind(&CSuperComboBox::OnDropFiles, this, std::placeholders::_1)); RegisterDragDrop(m_hWnd, m_pDropHandler); @@ -115,7 +117,7 @@ int CSuperComboBox::InsertString(int nIndex, LPCTSTR lpszItem) { if (m_bComboBoxEx) { - CString sShortName; // scoped to remain valid for calling CComboBoxEx::InsertItem() + CString sShortName; // scoped to remain valid for calling __super::InsertItem() if (m_bExtendedFileNames) { if (nIndex >= static_cast(m_sFullStateText.size())) @@ -150,7 +152,7 @@ int CSuperComboBox::InsertString(int nIndex, LPCTSTR lpszItem) cbitem.iItem = nIndex; cbitem.iImage = I_IMAGECALLBACK; cbitem.iSelectedImage = I_IMAGECALLBACK; - return CComboBoxEx::InsertItem(&cbitem); + return __super::InsertItem(&cbitem); } else { @@ -165,7 +167,7 @@ int CSuperComboBox::DeleteString(int nIndex) { m_sFullStateText.erase(m_sFullStateText.begin() + nIndex); } - return CComboBoxEx::DeleteString(nIndex); + return __super::DeleteString(nIndex); } int CSuperComboBox::FindString(int nStartAfter, LPCTSTR lpszString) const @@ -200,15 +202,11 @@ int CSuperComboBox::FindString(int nStartAfter, LPCTSTR lpszString) const bool CSuperComboBox::AttachSystemImageList() { ASSERT(m_bComboBoxEx); - if (m_himlSystem==nullptr) - { - SHFILEINFO sfi = {0}; - m_himlSystem = (HIMAGELIST)SHGetFileInfo(_T(""), 0, - &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); - if (m_himlSystem==nullptr) - return false; - } - SetImageList(CImageList::FromHandle(m_himlSystem)); + HIMAGELIST hImageList = DpiAware::LoadShellImageList(m_dpi); + if (hImageList==nullptr) + return false; + m_himlSystemMap.emplace(m_dpi, hImageList); + SetImageList(CImageList::FromHandle(hImageList)); m_bHasImageList = true; return true; } @@ -256,7 +254,7 @@ void CSuperComboBox::GetLBText(int nIndex, CString &rString) const } else { - CComboBoxEx::GetLBText(nIndex, rString.GetBufferSetLength(GetLBTextLen(nIndex))); + __super::GetLBText(nIndex, rString.GetBufferSetLength(GetLBTextLen(nIndex))); rString.ReleaseBuffer(); } } @@ -269,7 +267,7 @@ int CSuperComboBox::GetLBTextLen(int nIndex) const } else { - return CComboBoxEx::GetLBTextLen(nIndex); + return __super::GetLBTextLen(nIndex); } } @@ -419,7 +417,7 @@ BOOL CSuperComboBox::PreTranslateMessage(MSG* pMsg) } } - return CComboBoxEx::PreTranslateMessage(pMsg); + return __super::PreTranslateMessage(pMsg); } void CSuperComboBox::SetAutoComplete(INT nSource) @@ -463,12 +461,12 @@ void CSuperComboBox::ResetContent() m_sFullStateText[i] = _T(""); } } - CComboBoxEx::ResetContent(); + __super::ResetContent(); } int CSuperComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct) { - if (CComboBoxEx::OnCreate(lpCreateStruct) == -1) + if (__super::OnCreate(lpCreateStruct) == -1) return -1; m_pDropHandler = new DropHandler(std::bind(&CSuperComboBox::OnDropFiles, this, std::placeholders::_1)); @@ -567,14 +565,12 @@ void CSuperComboBox::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) if (!pEdit->GetModify() || GetFocus() != pEdit) GetWindowText(sText); int iIcon = GetFileTypeIconIndex(pvText); - const int cxsmicon = GetSystemMetrics(SM_CXSMICON); - const int cysmicon = GetSystemMetrics(SM_CYSMICON); - ImageList_DrawEx(m_himlSystem, iIcon, lpDrawItemStruct->hDC, + ImageList_DrawEx(m_himlSystemMap[m_dpi], iIcon, lpDrawItemStruct->hDC, lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top, - cxsmicon, cysmicon, GetSysColor(COLOR_WINDOW), CLR_NONE, ILD_NORMAL); + 0, 0, GetSysColor(COLOR_WINDOW), CLR_NONE, ILD_NORMAL); return; } - CComboBoxEx::OnDrawItem(nIDCtl, lpDrawItemStruct); + __super::OnDrawItem(nIDCtl, lpDrawItemStruct); } /** @@ -594,3 +590,18 @@ void CSuperComboBox::OnGetDispInfo(NMHDR *pNotifyStruct, LRESULT *pResult) } *pResult = 0; } + +LRESULT CSuperComboBox::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) +{ + UpdateDpi(); + if (m_bHasImageList) + { + if (m_himlSystemMap.find(m_dpi) == m_himlSystemMap.end()) + { + HIMAGELIST hImageList = DpiAware::LoadShellImageList(m_dpi); + m_himlSystemMap.emplace(m_dpi, hImageList); + } + SetImageList(CImageList::FromHandle(m_himlSystemMap[m_dpi])); + } + return 0; +} diff --git a/Src/Common/SuperComboBox.h b/Src/Common/SuperComboBox.h index cd6afd5bb39..3d105de22e0 100644 --- a/Src/Common/SuperComboBox.h +++ b/Src/Common/SuperComboBox.h @@ -12,7 +12,7 @@ class DropHandler; ///////////////////////////////////////////////////////////////////////////// // CSuperComboBox window -class CSuperComboBox : public CComboBoxEx, DpiAware::PerMonitorDpiAwareWindow +class CSuperComboBox : public DpiAware::PerMonitorDpiAwareCWnd { // Construction public: @@ -32,7 +32,7 @@ class CSuperComboBox : public CComboBoxEx, DpiAware::PerMonitorDpiAwareWindow m_himlSystemMap; DropHandler *m_pDropHandler; @@ -86,6 +86,7 @@ class CSuperComboBox : public CComboBoxEx, DpiAware::PerMonitorDpiAwareWindow) //{{AFX_MSG_MAP(CSizingControlBar) ON_WM_CREATE() ON_WM_PAINT() @@ -123,6 +123,8 @@ BOOL CSizingControlBar::Create(LPCTSTR lpszWindowName, CRect(0, 0, 0, 0), pParentWnd, nID)) return FALSE; + UpdateDpi(); + return TRUE; } @@ -186,12 +188,6 @@ LRESULT CSizingControlBar::OnSetText(WPARAM wParam, LPARAM lParam) return lResult; } -LRESULT CSizingControlBar::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) -{ - UpdateDpi(); - return 0; -} - const bool CSizingControlBar::IsFloating() const { return !IsHorzDocked() && !IsVertDocked(); diff --git a/Src/Common/sizecbar.h b/Src/Common/sizecbar.h index 02cb671a619..096a6069c29 100644 --- a/Src/Common/sizecbar.h +++ b/Src/Common/sizecbar.h @@ -73,7 +73,7 @@ class CSCBDockBar : public CDockBar class CSizingControlBar; typedef CTypedPtrArray CSCBArray; -class CSizingControlBar : public baseCSizingControlBar, public DpiAware::PerMonitorDpiAwareWindow +class CSizingControlBar : public DpiAware::PerMonitorDpiAwareCWnd { DECLARE_DYNAMIC(CSizingControlBar); @@ -179,7 +179,6 @@ class CSizingControlBar : public baseCSizingControlBar, public DpiAware::PerMoni afx_msg void OnSize(UINT nType, int cx, int cy); //}}AFX_MSG afx_msg LRESULT OnSetText(WPARAM wParam, LPARAM lParam); - afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() diff --git a/Src/DirCompProgressBar.cpp b/Src/DirCompProgressBar.cpp index 46a2095f802..5ffaa853d50 100644 --- a/Src/DirCompProgressBar.cpp +++ b/Src/DirCompProgressBar.cpp @@ -57,7 +57,7 @@ DirCompProgressBar::~DirCompProgressBar() #endif } -BEGIN_MESSAGE_MAP(DirCompProgressBar, CDialogBar) +BEGIN_MESSAGE_MAP(DirCompProgressBar, CTrDialogBar) //{{AFX_MSG_MAP(DirCompProgressBar) ON_WM_WINDOWPOSCHANGING() ON_WM_TIMER() diff --git a/Src/DirFrame.cpp b/Src/DirFrame.cpp index 95f426fcc1e..7b174193e2f 100644 --- a/Src/DirFrame.cpp +++ b/Src/DirFrame.cpp @@ -90,7 +90,7 @@ END_MESSAGE_MAP() */ int CDirFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { - if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1) + if (__super::OnCreate(lpCreateStruct) == -1) return -1; EnableDocking(CBRS_ALIGN_TOP); diff --git a/Src/DirView.cpp b/Src/DirView.cpp index 2c569f2d473..3adaf425e54 100644 --- a/Src/DirView.cpp +++ b/Src/DirView.cpp @@ -118,7 +118,7 @@ CDirView::~CDirView() { } -BEGIN_MESSAGE_MAP(CDirView, CListView) +BEGIN_MESSAGE_MAP(CDirView, DpiAware::PerMonitorDpiAwareCWnd) ON_WM_CONTEXTMENU() //{{AFX_MSG_MAP(CDirView) ON_WM_LBUTTONDBLCLK() @@ -334,6 +334,7 @@ BEGIN_MESSAGE_MAP(CDirView, CListView) ON_BN_CLICKED(IDC_COMPARISON_STOP, OnBnClickedComparisonStop) ON_BN_CLICKED(IDC_COMPARISON_PAUSE, OnBnClickedComparisonPause) ON_BN_CLICKED(IDC_COMPARISON_CONTINUE, OnBnClickedComparisonContinue) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// @@ -353,6 +354,7 @@ CDirDoc* CDirView::GetDocument() // non-debug version is inline void CDirView::OnInitialUpdate() { + UpdateDpi(); const int iconCX = [this]() { const int cx = GetSystemMetrics(SM_CXSMICON); if (cx < 24) @@ -364,7 +366,7 @@ void CDirView::OnInitialUpdate() return 48; }(); const int iconCY = iconCX; - CListView::OnInitialUpdate(); + __super::OnInitialUpdate(); m_pList = &GetListCtrl(); m_pIList.reset(new IListCtrlImpl(m_pList->m_hWnd)); GetDocument()->SetDirView(this); @@ -431,7 +433,7 @@ void CDirView::OnInitialUpdate() BOOL CDirView::PreCreateWindow(CREATESTRUCT& cs) { - CListView::PreCreateWindow(cs); + __super::PreCreateWindow(cs); cs.dwExStyle &= ~WS_EX_CLIENTEDGE; return TRUE; } @@ -483,7 +485,7 @@ void CDirView::OnLButtonDblClk(UINT nFlags, CPoint point) OpenSelection(); } } - CListView::OnLButtonDblClk(nFlags, point); + __super::OnLButtonDblClk(nFlags, point); } /** @@ -1118,7 +1120,7 @@ void CDirView::OnDestroy() m_pColItems->SaveColumnWidths(std::bind(&CListCtrl::GetColumnWidth, m_pList, _1))); } - CListView::OnDestroy(); + __super::OnDestroy(); GetMainFrame()->ClearStatusbarItemCount(); } @@ -1148,7 +1150,7 @@ void CDirView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) } } } - CListView::OnChar(nChar, nRepCnt, nFlags); + __super::OnChar(nChar, nRepCnt, nFlags); } /** @@ -2149,7 +2151,7 @@ CDirFrame * CDirView::GetParentFrame() { // can't verify cast without introducing more coupling // (CDirView doesn't include DirFrame.h) - return static_cast(CListView::GetParentFrame()); + return static_cast(__super::GetParentFrame()); } void CDirView::OnRefresh() @@ -2260,7 +2262,7 @@ BOOL CDirView::PreTranslateMessage(MSG* pMsg) } } } - return CListView::PreTranslateMessage(pMsg); + return __super::PreTranslateMessage(pMsg); } void CDirView::OnUpdateRefresh(CCmdUI* pCmdUI) @@ -2346,7 +2348,7 @@ BOOL CDirView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) if (hdr->code == HDN_BEGINDRAG) return OnHeaderBeginDrag((LPNMHEADER)hdr, pResult); - return CListView::OnNotify(wParam, lParam, pResult); + return __super::OnNotify(wParam, lParam, pResult); } BOOL CDirView::OnChildNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult) @@ -2364,7 +2366,7 @@ BOOL CDirView::OnChildNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* p return TRUE; } } - return CListView::OnChildNotify(uMsg, wParam, lParam, pResult); + return __super::OnChildNotify(uMsg, wParam, lParam, pResult); } /** @@ -2397,6 +2399,14 @@ bool CDirView::OnHeaderEndDrag(LPNMHEADER hdr, LRESULT* pResult) return true; } +LRESULT CDirView::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) +{ + int olddpi = m_dpi; + UpdateDpi(); + DpiAware::ListView_UpdateColumnWidths(m_hWnd, olddpi, m_dpi); + return 0; +} + /** * @brief Remove any windows reordering of columns */ @@ -2477,7 +2487,7 @@ void CDirView::OnTimer(UINT_PTR nIDEvent) GetParentFrame()->SetStatus(msg.c_str()); } - CListView::OnTimer(nIDEvent); + __super::OnTimer(nIDEvent); } /** @@ -3071,7 +3081,7 @@ void CDirView::OnUpdateCtxtDirMoveTo(CCmdUI* pCmdUI) */ void CDirView::OnSize(UINT nType, int cx, int cy) { - CListView::OnSize(nType, cx, cy); + __super::OnSize(nType, cx, cy); GetDocument()->SetTitle(nullptr); } @@ -3798,7 +3808,7 @@ LRESULT CDirView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) pMenu->HandleMenuMessage(message, wParam, lParam, res); } - return CListView::WindowProc(message, wParam, lParam); + return __super::WindowProc(message, wParam, lParam); } /** diff --git a/Src/DirView.h b/Src/DirView.h index aaf98a3366e..ee9491c89b4 100644 --- a/Src/DirView.h +++ b/Src/DirView.h @@ -60,7 +60,7 @@ const UINT DefColumnWidth = 150; * CDiffContext items are linked by storing POSITION of CDiffContext item * as CDirView listitem key. */ -class CDirView : public CListView, public DpiAware::PerMonitorDpiAwareWindow +class CDirView : public DpiAware::PerMonitorDpiAwareCWnd { friend struct FileCmpReport; friend DirItemEnumerator; @@ -381,6 +381,7 @@ class CDirView : public CListView, public DpiAware::PerMonitorDpiAwareWindow) ON_NOTIFY_EX (TTN_NEEDTEXT, 0, OnToolTipNotify) ON_CONTROL_RANGE (EN_SETFOCUS, IDC_STATIC_TITLE_PANE0, IDC_STATIC_TITLE_PANE2, OnSetFocusEdit) - ON_MESSAGE(WM_DPICHANGED_AFTERPARENT, OnDpiChangedBeforeParent) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP() @@ -48,10 +47,12 @@ CEditorFilePathBar::~CEditorFilePathBar() */ BOOL CEditorFilePathBar::Create(CWnd* pParentWnd) { - if (! CDialogBar::Create(pParentWnd, CEditorFilePathBar::IDD, + if (! __super::Create(pParentWnd, CEditorFilePathBar::IDD, CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, CEditorFilePathBar::IDD)) return FALSE; + UpdateDpi(); + LOGFONT lfStatusFont; if (DpiAware::GetNonClientLogFont(lfStatusFont, offsetof(NONCLIENTMETRICS, lfStatusFont), GetDpi())) m_font.CreateFontIndirect(&lfStatusFont); diff --git a/Src/EditorFilepathBar.h b/Src/EditorFilepathBar.h index 7be947d7930..32687e7018b 100644 --- a/Src/EditorFilepathBar.h +++ b/Src/EditorFilepathBar.h @@ -36,7 +36,7 @@ class IHeaderBar * The bar looks like a statusBar (font, height). The control * displays a tip for each path (as a tooltip). */ -class CEditorFilePathBar : public CDialogBar, public DpiAware::PerMonitorDpiAwareWindow, public IHeaderBar +class CEditorFilePathBar : public DpiAware::PerMonitorDpiAwareCWnd, public IHeaderBar { public : CEditorFilePathBar(); diff --git a/Src/EncodingErrorBar.cpp b/Src/EncodingErrorBar.cpp index cff8877b3f0..dee8022eb44 100644 --- a/Src/EncodingErrorBar.cpp +++ b/Src/EncodingErrorBar.cpp @@ -29,7 +29,7 @@ void CEncodingErrorBar::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(CEncodingErrorBar, CDialogBar) +BEGIN_MESSAGE_MAP(CEncodingErrorBar, CTrDialogBar) //{{AFX_MSG_MAP(CEncodingErrorBar) //}}AFX_MSG_MAP END_MESSAGE_MAP() diff --git a/Src/FileFiltersDlg.cpp b/Src/FileFiltersDlg.cpp index 7bedae0943a..f09efffd790 100644 --- a/Src/FileFiltersDlg.cpp +++ b/Src/FileFiltersDlg.cpp @@ -33,7 +33,7 @@ static const TCHAR FilterHelpLocation[] = _T("::/htmlhelp/Filters.html"); ///////////////////////////////////////////////////////////////////////////// // CFiltersDlg dialog -IMPLEMENT_DYNCREATE(FileFiltersDlg, CPropertyPage) +IMPLEMENT_DYNCREATE(FileFiltersDlg, CTrPropertyPage) /** * @brief Constructor. @@ -56,7 +56,7 @@ void FileFiltersDlg::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(FileFiltersDlg, CDialog) +BEGIN_MESSAGE_MAP(FileFiltersDlg, CTrPropertyPage) //{{AFX_MSG_MAP(FileFiltersDlg) ON_BN_CLICKED(IDC_FILTERFILE_EDITBTN, OnFiltersEditbtn) ON_NOTIFY(NM_DBLCLK, IDC_FILTERFILE_LIST, OnDblclkFiltersList) diff --git a/Src/LineFiltersDlg.cpp b/Src/LineFiltersDlg.cpp index 2be2023db38..945979be06f 100644 --- a/Src/LineFiltersDlg.cpp +++ b/Src/LineFiltersDlg.cpp @@ -48,7 +48,7 @@ void LineFiltersDlg::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(LineFiltersDlg, CPropertyPage) +BEGIN_MESSAGE_MAP(LineFiltersDlg, CTrPropertyPage) //{{AFX_MSG_MAP(LineFiltersDlg) ON_COMMAND(ID_HELP, OnHelp) //}}AFX_MSG_MAP diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index ad27e61a9c2..b04c971fdb5 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -156,7 +156,7 @@ const CMainFrame::MENUITEM_ICON CMainFrame::m_MenuIcons[] = { IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) -BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) +BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::PerMonitorDpiAwareCWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_MENUCHAR() ON_WM_MEASUREITEM() @@ -289,7 +289,7 @@ const TCHAR CMainFrame::szClassName[] = _T("WinMergeWindowClassW"); BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { WNDCLASS wndcls; - BOOL bRes = CMDIFrameWnd::PreCreateWindow(cs); + BOOL bRes = __super::PreCreateWindow(cs); HINSTANCE hInst = AfxGetInstanceHandle(); // see if the class already exists if (!::GetClassInfo(hInst, szClassName, &wndcls)) @@ -307,10 +307,13 @@ BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { - if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) + if (__super::OnCreate(lpCreateStruct) == -1) return -1; + UpdateDpi(); + m_wndMDIClient.SubclassWindow(m_hWndMDIClient); + m_wndMDIClient.UpdateDpi(); if (!CreateToolbar()) { @@ -326,7 +329,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) m_wndTabBar.SetAutoMaxWidth(GetOptionsMgr()->GetBool(OPT_TABBAR_AUTO_MAXWIDTH)); if (!GetOptionsMgr()->GetBool(OPT_SHOW_TABBAR)) - CMDIFrameWnd::ShowControlBar(&m_wndTabBar, false, 0); + __super::ShowControlBar(&m_wndTabBar, false, 0); if (!m_wndStatusBar.Create(this)) { @@ -342,7 +345,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) m_wndStatusBar.SetPaneInfo(3, ID_STATUS_DIFFNUM, 0, PointToPixel(112)); if (!GetOptionsMgr()->GetBool(OPT_SHOW_STATUSBAR)) - CMDIFrameWnd::ShowControlBar(&m_wndStatusBar, false, 0); + __super::ShowControlBar(&m_wndStatusBar, false, 0); m_pDropHandler = new DropHandler(std::bind(&CMainFrame::OnDropFiles, this, std::placeholders::_1)); RegisterDragDrop(m_hWnd, m_pDropHandler); @@ -356,7 +359,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) void CMainFrame::OnTimer(UINT_PTR nIDEvent) { - CMDIFrameWnd::OnTimer(nIDEvent); + __super::OnTimer(nIDEvent); if (nIDEvent == IDT_UPDATEMAINMENU) { @@ -561,7 +564,7 @@ void CMainFrame::OnMeasureItem(int nIDCtl, } if (!setflag) - CMDIFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct); + __super::OnMeasureItem(nIDCtl, lpMeasureItemStruct); } /** @@ -574,7 +577,7 @@ LRESULT CMainFrame::OnMenuChar(UINT nChar, UINT nFlags, if(m_pMenus[MENU_DEFAULT]->IsMenu(pMenu)) lresult=BCMenu::FindKeyboardShortcut(nChar, nFlags, pMenu); else - lresult=CMDIFrameWnd::OnMenuChar(nChar, nFlags, pMenu); + lresult=__super::OnMenuChar(nChar, nFlags, pMenu); return lresult; } @@ -583,7 +586,7 @@ LRESULT CMainFrame::OnMenuChar(UINT nChar, UINT nFlags, */ void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) { - CMDIFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); + __super::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); if (!bSysMenu) { @@ -1171,7 +1174,7 @@ void CMainFrame::ActivateFrame(int nCmdShow) { if (!m_bFirstTime) { - CMDIFrameWnd::ActivateFrame(nCmdShow); + __super::ActivateFrame(nCmdShow); return; } @@ -1205,10 +1208,10 @@ void CMainFrame::ActivateFrame(int nCmdShow) if (dsk_rc.PtInRect(ptTopLeft)) SetWindowPlacement(&wp); else - CMDIFrameWnd::ActivateFrame(nCmdShow); + __super::ActivateFrame(nCmdShow); } else - CMDIFrameWnd::ActivateFrame(nCmdShow); + __super::ActivateFrame(nCmdShow); } /** @@ -1250,7 +1253,7 @@ void CMainFrame::OnClose() return; } - CMDIFrameWnd::OnClose(); + __super::OnClose(); } /** @@ -1730,7 +1733,7 @@ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) return TRUE; } - return CMDIFrameWnd::PreTranslateMessage(pMsg); + return __super::PreTranslateMessage(pMsg); } /** @@ -1741,7 +1744,7 @@ void CMainFrame::OnViewStatusBar() bool bShow = !GetOptionsMgr()->GetBool(OPT_SHOW_STATUSBAR); GetOptionsMgr()->SaveOption(OPT_SHOW_STATUSBAR, bShow); - CMDIFrameWnd::ShowControlBar(&m_wndStatusBar, bShow, 0); + __super::ShowControlBar(&m_wndStatusBar, bShow, 0); } /** @@ -1760,7 +1763,7 @@ void CMainFrame::OnViewTabBar() bool bShow = !GetOptionsMgr()->GetBool(OPT_SHOW_TABBAR); GetOptionsMgr()->SaveOption(OPT_SHOW_TABBAR, bShow); - CMDIFrameWnd::ShowControlBar(&m_wndTabBar, bShow, 0); + __super::ShowControlBar(&m_wndTabBar, bShow, 0); } /** @@ -1963,9 +1966,9 @@ void CMainFrame::OnActivateApp(BOOL bActive, HTASK hTask) #endif { #if _MFC_VER > 0x0600 - CMDIFrameWnd::OnActivateApp(bActive, dwThreadID); + __super::OnActivateApp(bActive, dwThreadID); #else - CMDIFrameWnd::OnActivateApp(bActive, hTask); + __super::OnActivateApp(bActive, hTask); #endif CFrameWnd * pFrame = GetActiveFrame(); @@ -2013,7 +2016,7 @@ BOOL CMainFrame::CreateToolbar() if (!GetOptionsMgr()->GetBool(OPT_SHOW_TOOLBAR)) { - CMDIFrameWnd::ShowControlBar(&m_wndToolBar, false, 0); + __super::ShowControlBar(&m_wndToolBar, false, 0); } return TRUE; @@ -2096,7 +2099,7 @@ void CMainFrame::OnToolbarSize(UINT id) if (id == ID_TOOLBAR_NONE) { GetOptionsMgr()->SaveOption(OPT_SHOW_TOOLBAR, false); - CMDIFrameWnd::ShowControlBar(&m_wndToolBar, false, 0); + __super::ShowControlBar(&m_wndToolBar, false, 0); } else { @@ -2105,7 +2108,7 @@ void CMainFrame::OnToolbarSize(UINT id) LoadToolbarImages(); - CMDIFrameWnd::ShowControlBar(&m_wndToolBar, true, 0); + __super::ShowControlBar(&m_wndToolBar, true, 0); } } @@ -2574,6 +2577,8 @@ void CMainFrame::OnAccelQuit() LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { + int olddpi = m_dpi; + Default(); int dpi = HIWORD(wParam); @@ -2583,6 +2588,12 @@ LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) DpiAware::UpdateAfxDataSysMetrics(dpi); BCMenu::ReopenTheme(dpi); + m_lfDiff.lfHeight = MulDiv(m_lfDiff.lfHeight, m_dpi, olddpi); + m_lfDir.lfHeight = MulDiv(m_lfDir.lfHeight, m_dpi, olddpi); + + UpdateFont(FRAME_FILE); + UpdateFont(FRAME_FOLDER); + return 0; } diff --git a/Src/MainFrm.h b/Src/MainFrm.h index 9a8e1f1630d..91a5c3c3854 100644 --- a/Src/MainFrm.h +++ b/Src/MainFrm.h @@ -50,7 +50,7 @@ CMainFrame * GetMainFrame(); // access to the singleton main frame object /** * @brief Frame class containing save-routines etc */ -class CMainFrame : public CMDIFrameWnd, public DpiAware::PerMonitorDpiAwareWindow +class CMainFrame : public DpiAware::PerMonitorDpiAwareCWnd { friend CLanguageSelect; DECLARE_DYNAMIC(CMainFrame) @@ -122,10 +122,6 @@ class CMainFrame : public CMDIFrameWnd, public DpiAware::PerMonitorDpiAwareWindo virtual BOOL PreTranslateMessage(MSG* pMsg); virtual void OnUpdateFrameTitle(BOOL bAddToTitle); virtual BOOL PreCreateWindow(CREATESTRUCT& cs); - virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) - { - CalcWindowRectImpl(lpClientRect, nAdjustType); - } //}}AFX_VIRTUAL @@ -147,7 +143,7 @@ class CMainFrame : public CMDIFrameWnd, public DpiAware::PerMonitorDpiAwareWindo CTypedPtrArray m_arrChild; // Tweak MDI client window behavior - class CMDIClient : public CWnd, public DpiAware::PerMonitorDpiAwareWindow + class CMDIClient : public DpiAware::PerMonitorDpiAwareCWnd { static UINT_PTR const m_nRedrawTimer = 1612; virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) @@ -184,10 +180,6 @@ class CMainFrame : public CMDIFrameWnd, public DpiAware::PerMonitorDpiAwareWindo } return CWnd::WindowProc(message, wParam, lParam); } - virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) - { - CalcWindowRectImpl(lpClientRect, nAdjustType); - } } m_wndMDIClient; /** @brief Toolbar image table indexes. */ diff --git a/Src/Merge.vs2017.vcxproj b/Src/Merge.vs2017.vcxproj index c104d9523c4..d8ac2d7303e 100644 --- a/Src/Merge.vs2017.vcxproj +++ b/Src/Merge.vs2017.vcxproj @@ -173,6 +173,7 @@ true true true + 5.01 @@ -283,6 +284,7 @@ MachineX86 true false + 5.01 @@ -336,6 +338,7 @@ MachineX86 true false + 5.01 @@ -1113,6 +1116,7 @@ + diff --git a/Src/Merge.vs2017.vcxproj.filters b/Src/Merge.vs2017.vcxproj.filters index dc844b4ea49..aa08bb5ff8a 100644 --- a/Src/Merge.vs2017.vcxproj.filters +++ b/Src/Merge.vs2017.vcxproj.filters @@ -1653,6 +1653,9 @@ EditLib\Utils + + EditLib\Utils + diff --git a/Src/Merge.vs2019.vcxproj b/Src/Merge.vs2019.vcxproj index 33b53361d41..bac44a37a55 100644 --- a/Src/Merge.vs2019.vcxproj +++ b/Src/Merge.vs2019.vcxproj @@ -1115,6 +1115,7 @@ + diff --git a/Src/Merge.vs2019.vcxproj.filters b/Src/Merge.vs2019.vcxproj.filters index dc844b4ea49..aa08bb5ff8a 100644 --- a/Src/Merge.vs2019.vcxproj.filters +++ b/Src/Merge.vs2019.vcxproj.filters @@ -1653,6 +1653,9 @@ EditLib\Utils + + EditLib\Utils + diff --git a/Src/MergeEditFrm.cpp b/Src/MergeEditFrm.cpp index 5d05766139c..21f137493f4 100644 --- a/Src/MergeEditFrm.cpp +++ b/Src/MergeEditFrm.cpp @@ -162,7 +162,7 @@ BOOL CMergeEditFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/, */ int CMergeEditFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { - if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1) + if (__super::OnCreate(lpCreateStruct) == -1) return -1; EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM|CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT); diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index 66164f3b048..4d84e2c48a3 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -14,12 +14,12 @@ IMPLEMENT_DYNCREATE(CMergeFrameCommon, CMDIChildWnd) -BEGIN_MESSAGE_MAP(CMergeFrameCommon, CMDIChildWnd) +BEGIN_MESSAGE_MAP(CMergeFrameCommon, DpiAware::PerMonitorDpiAwareCWnd) //{{AFX_MSG_MAP(CMergeFrameCommon) ON_WM_GETMINMAXINFO() ON_WM_DESTROY() ON_WM_MDIACTIVATE() - ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) +// ON_MESSAGE(WM_GETICON, OnGetIcon) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -37,6 +37,14 @@ CMergeFrameCommon::~CMergeFrameCommon() ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEREMOVED, 0, reinterpret_cast(this)); } +BOOL CMergeFrameCommon::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CMDIFrameWnd* pParentWnd, CCreateContext* pContext) +{ + if (!__super::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, pContext)) + return FALSE; + UpdateDpi(); + return TRUE; +} + void CMergeFrameCommon::ActivateFrame(int nCmdShow) { if (!m_bActivated) @@ -55,7 +63,7 @@ void CMergeFrameCommon::ActivateFrame(int nCmdShow) nCmdShow = SW_SHOWNORMAL; } - CMDIChildWnd::ActivateFrame(nCmdShow); + __super::ActivateFrame(nCmdShow); } void CMergeFrameCommon::SaveWindowState() @@ -103,8 +111,8 @@ void CMergeFrameCommon::SetLastCompareResult(int nResult) void CMergeFrameCommon::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { - CMDIChildWnd::OnGetMinMaxInfo(lpMMI); - if (IsDpiChanged()) + __super::OnGetMinMaxInfo(lpMMI); + if (IsDifferentDpiFromSystemDpi()) { CRect rc; CFrameWnd* pFrameWnd = GetParentFrame(); @@ -133,14 +141,15 @@ void CMergeFrameCommon::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* { // call the base class to let standard processing switch to // the top-level menu associated with this window - CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd); + __super::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd); if (bActivate) ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEACTIVATED, 0, reinterpret_cast(this)); } -LRESULT CMergeFrameCommon::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) +/* +LRESULT CMergeFrameCommon::OnGetIcon(WPARAM wParam, LPARAM lParam) { - UpdateDpi(); return 0; } +*/ diff --git a/Src/MergeFrameCommon.h b/Src/MergeFrameCommon.h index b51bbebbf46..a4e632350b5 100644 --- a/Src/MergeFrameCommon.h +++ b/Src/MergeFrameCommon.h @@ -8,11 +8,17 @@ #include "utils/DpiAware.h" -class CMergeFrameCommon: public CMDIChildWnd, public DpiAware::PerMonitorDpiAwareWindow +class CMergeFrameCommon: public DpiAware::PerMonitorDpiAwareCWnd { DECLARE_DYNCREATE(CMergeFrameCommon) public: CMergeFrameCommon(int nIdenticalIcon = -1, int nDifferentIcon = -1); + virtual BOOL Create(LPCTSTR lpszClassName, + LPCTSTR lpszWindowName, + DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, + const RECT& rect = rectDefault, + CMDIFrameWnd* pParentWnd = NULL, + CCreateContext* pContext = NULL); bool IsActivated() const { return m_bActivated; } void ActivateFrame(int nCmdShow); void SetLastCompareResult(int nResult); @@ -23,9 +29,6 @@ class CMergeFrameCommon: public CMDIChildWnd, public DpiAware::PerMonitorDpiAwar { return TRUE; // https://stackoverflow.com/questions/35553955/getting-rid-of-3d-look-of-mdi-frame-window } - virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder) { - CalcWindowRectImpl(lpClientRect, nAdjustType); - } protected: int m_nLastSplitPos[2]; @@ -42,7 +45,7 @@ class CMergeFrameCommon: public CMDIChildWnd, public DpiAware::PerMonitorDpiAwar afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); afx_msg void OnDestroy(); afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd); - afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam); +// afx_msg LRESULT OnGetIcon(WPARAM wParam, LPARAM lParam); //}}AFX_MSG DECLARE_MESSAGE_MAP() diff --git a/Src/MergeStatusBar.cpp b/Src/MergeStatusBar.cpp index 66488983616..9016962d52f 100644 --- a/Src/MergeStatusBar.cpp +++ b/Src/MergeStatusBar.cpp @@ -68,7 +68,7 @@ static UINT indicatorsBottom[] = ID_SEPARATOR, }; -BEGIN_MESSAGE_MAP(CMergeStatusBar, CStatusBar) +BEGIN_MESSAGE_MAP(CMergeStatusBar, DpiAware::PerMonitorDpiAwareCWnd) END_MESSAGE_MAP() /** @@ -93,9 +93,11 @@ CMergeStatusBar::~CMergeStatusBar() BOOL CMergeStatusBar::Create(CWnd* pParentWnd) { - if (! CStatusBar::Create(pParentWnd)) + if (! __super::Create(pParentWnd)) return FALSE; + UpdateDpi(); + SetIndicators(indicatorsBottom, sizeof(indicatorsBottom) / sizeof(UINT)); // Set text to read-only info panes diff --git a/Src/MergeStatusBar.h b/Src/MergeStatusBar.h index d91630aa175..b3185d0b131 100644 --- a/Src/MergeStatusBar.h +++ b/Src/MergeStatusBar.h @@ -16,7 +16,7 @@ #include "UnicodeString.h" #include "utils/DpiAware.h" -class CMergeStatusBar : public CStatusBar, public DpiAware::PerMonitorDpiAwareWindow +class CMergeStatusBar : public DpiAware::PerMonitorDpiAwareCWnd { public : CMergeStatusBar(); diff --git a/Src/OpenView.cpp b/Src/OpenView.cpp index db028d66cb0..92f7df9b14d 100644 --- a/Src/OpenView.cpp +++ b/Src/OpenView.cpp @@ -54,7 +54,7 @@ static TCHAR OpenDlgHelpLocation[] = _T("::/htmlhelp/Open_paths.html"); IMPLEMENT_DYNCREATE(COpenView, CFormView) -BEGIN_MESSAGE_MAP(COpenView, CFormView) +BEGIN_MESSAGE_MAP(COpenView, DpiAware::PerMonitorDpiAwareCWnd) //{{AFX_MSG_MAP(COpenView) ON_BN_CLICKED(IDC_PATH0_BUTTON, OnPathButton<0>) ON_BN_CLICKED(IDC_PATH1_BUTTON, OnPathButton<1>) @@ -104,7 +104,7 @@ END_MESSAGE_MAP() // COpenView construction/destruction COpenView::COpenView() - : CFormView(COpenView::IDD) + : DpiAware::PerMonitorDpiAwareCWnd(COpenView::IDD) , m_pUpdateButtonStatusThread(nullptr) , m_bRecurse(false) , m_pDropHandler(nullptr) @@ -126,7 +126,7 @@ COpenView::~COpenView() void COpenView::DoDataExchange(CDataExchange* pDX) { - CFormView::DoDataExchange(pDX); + __super::DoDataExchange(pDX); //{{AFX_DATA_MAP(COpenView) DDX_Control(pDX, IDC_EXT_COMBO, m_ctlExt); DDX_Control(pDX, IDC_PATH0_COMBO, m_ctlPath[0]); @@ -150,11 +150,13 @@ BOOL COpenView::PreCreateWindow(CREATESTRUCT& cs) // the CREATESTRUCT cs cs.style &= ~WS_BORDER; cs.dwExStyle &= ~WS_EX_CLIENTEDGE; - return CFormView::PreCreateWindow(cs); + return __super::PreCreateWindow(cs); } void COpenView::OnInitialUpdate() { + UpdateDpi(); + if (!IsVista_OrGreater()) { // fallback for XP @@ -172,7 +174,7 @@ void COpenView::OnInitialUpdate() m_image.Create(1, 1, 24, 0); } - CFormView::OnInitialUpdate(); + __super::OnInitialUpdate(); // set caption to "swap paths" button LOGFONT lf; @@ -333,7 +335,7 @@ void COpenView::OnPaint() dc.LineTo(rc.right, rcStatus.top - 3); dc.SelectObject(oldpen); - CFormView::OnPaint(); + __super::OnPaint(); } void COpenView::OnLButtonUp(UINT nFlags, CPoint point) @@ -458,7 +460,7 @@ void COpenView::OnWindowPosChanged(WINDOWPOS* lpwndpos) pFrameWnd->SetWindowPlacement(&wp); } } - CFormView::OnWindowPosChanged(lpwndpos); + __super::OnWindowPosChanged(lpwndpos); } void COpenView::OnDestroy() @@ -466,7 +468,7 @@ void COpenView::OnDestroy() if (m_pDropHandler != nullptr) RevokeDragDrop(m_hWnd); - CFormView::OnDestroy(); + __super::OnDestroy(); } LRESULT COpenView::OnNcHitTest(CPoint point) @@ -480,7 +482,7 @@ LRESULT COpenView::OnNcHitTest(CPoint point) if (PtInRect(&rc, point)) return HTRIGHT; } - return CFormView::OnNcHitTest(point); + return __super::OnNcHitTest(point); } void COpenView::OnButton(int index) @@ -1058,7 +1060,7 @@ void COpenView::OnTimer(UINT_PTR nIDEvent) if (nIDEvent == IDT_CHECKFILES) UpdateButtonStates(); - CFormView::OnTimer(nIDEvent); + __super::OnTimer(nIDEvent); } /** @@ -1257,7 +1259,7 @@ void COpenView::TrimPaths() */ void COpenView::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) { - CFormView::OnActivate(nState, pWndOther, bMinimized); + __super::OnActivate(nState, pWndOther, bMinimized); if (nState == WA_ACTIVE || nState == WA_CLICKACTIVE) UpdateButtonStates(); diff --git a/Src/OpenView.h b/Src/OpenView.h index 97137be0a58..fac26f75f63 100644 --- a/Src/OpenView.h +++ b/Src/OpenView.h @@ -34,7 +34,7 @@ class DropHandler; * The dialog shows also a status of the selected paths (found/not found), * if enabled in the options (enabled by default). */ -class COpenView : public CFormView, public DlgUtils, public DpiAware::PerMonitorDpiAwareWindow +class COpenView : public DpiAware::PerMonitorDpiAwareCWnd, public DlgUtils { protected: // create from serialization only COpenView(); diff --git a/Src/PropArchive.cpp b/Src/PropArchive.cpp index 0acde3aa8af..9f7145a0da3 100644 --- a/Src/PropArchive.cpp +++ b/Src/PropArchive.cpp @@ -35,7 +35,7 @@ void PropArchive::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropArchive, CPropertyPage) +BEGIN_MESSAGE_MAP(PropArchive, OptionsPanel) ON_BN_CLICKED(IDC_ARCHIVE_ENABLE, OnEnableClicked) END_MESSAGE_MAP() diff --git a/Src/PropBackups.cpp b/Src/PropBackups.cpp index d0b27b5b7e7..de914a8c016 100644 --- a/Src/PropBackups.cpp +++ b/Src/PropBackups.cpp @@ -42,7 +42,7 @@ void PropBackups::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropBackups, CPropertyPage) +BEGIN_MESSAGE_MAP(PropBackups, OptionsPanel) ON_BN_CLICKED(IDC_BACKUP_BROWSE, OnBnClickedBackupBrowse) END_MESSAGE_MAP() diff --git a/Src/PropCodepage.cpp b/Src/PropCodepage.cpp index 0bb1d3931a0..9b3d3a962ca 100644 --- a/Src/PropCodepage.cpp +++ b/Src/PropCodepage.cpp @@ -48,7 +48,7 @@ void PropCodepage::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropCodepage, CPropertyPage) +BEGIN_MESSAGE_MAP(PropCodepage, OptionsPanel) //{{AFX_MSG_MAP(PropCodepage) ON_BN_CLICKED(IDC_CP_SYSTEM, OnCpSystem) ON_BN_CLICKED(IDC_CP_CUSTOM, OnCpCustom) diff --git a/Src/PropColorSchemes.cpp b/Src/PropColorSchemes.cpp index 54e9b4972dd..f8ea1df040b 100644 --- a/Src/PropColorSchemes.cpp +++ b/Src/PropColorSchemes.cpp @@ -36,7 +36,7 @@ void PropColorSchemes::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropColorSchemes, CDialog) +BEGIN_MESSAGE_MAP(PropColorSchemes, OptionsPanel) //{{AFX_MSG_MAP(PropColorSchemes) ON_CBN_SELCHANGE(IDC_COLOR_SCHEMES, OnCbnSelchangeColorSchemes) //}}AFX_MSG_MAP diff --git a/Src/PropCompare.cpp b/Src/PropCompare.cpp index 951c31a0685..402d81152f4 100644 --- a/Src/PropCompare.cpp +++ b/Src/PropCompare.cpp @@ -52,7 +52,7 @@ void PropCompare::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropCompare, CPropertyPage) +BEGIN_MESSAGE_MAP(PropCompare, OptionsPanel) //{{AFX_MSG_MAP(PropCompare) ON_BN_CLICKED(IDC_COMPARE_DEFAULTS, OnDefaults) ON_CBN_SELCHANGE(IDC_DIFF_ALGORITHM, OnCbnSelchangeDiffAlgorithm) diff --git a/Src/PropCompareBinary.cpp b/Src/PropCompareBinary.cpp index 3eba2266102..6ffd3944a93 100644 --- a/Src/PropCompareBinary.cpp +++ b/Src/PropCompareBinary.cpp @@ -69,7 +69,7 @@ void PropCompareBinary::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropCompareBinary, CPropertyPage) +BEGIN_MESSAGE_MAP(PropCompareBinary, OptionsPanel) //{{AFX_MSG_MAP(PropCompareBinary) ON_BN_CLICKED(IDC_COMPAREBINARY_VIEWSETTINGS, OnViewSettings) ON_BN_CLICKED(IDC_COMPAREBINARY_BINARYMODE, OnBinaryMode) diff --git a/Src/PropCompareFolder.cpp b/Src/PropCompareFolder.cpp index 0e490d6e969..57f1dd7e252 100644 --- a/Src/PropCompareFolder.cpp +++ b/Src/PropCompareFolder.cpp @@ -54,7 +54,7 @@ void PropCompareFolder::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropCompareFolder, CPropertyPage) +BEGIN_MESSAGE_MAP(PropCompareFolder, OptionsPanel) //{{AFX_MSG_MAP(PropCompareFolder) ON_BN_CLICKED(IDC_COMPARE_DEFAULTS, OnDefaults) //}}AFX_MSG_MAP diff --git a/Src/PropCompareImage.cpp b/Src/PropCompareImage.cpp index b564c56e37e..dda7fd87d59 100644 --- a/Src/PropCompareImage.cpp +++ b/Src/PropCompareImage.cpp @@ -35,7 +35,7 @@ void PropCompareImage::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropCompareImage, CPropertyPage) +BEGIN_MESSAGE_MAP(PropCompareImage, OptionsPanel) //{{AFX_MSG_MAP(PropCompareImage) ON_BN_CLICKED(IDC_COMPARE_DEFAULTS, OnDefaults) ON_CBN_DROPDOWN(IDC_COMPAREIMAGE_PATTERNS, OnDropDownPatterns) diff --git a/Src/PropCompareTable.cpp b/Src/PropCompareTable.cpp index c6a26c62936..c5c57543d44 100644 --- a/Src/PropCompareTable.cpp +++ b/Src/PropCompareTable.cpp @@ -44,7 +44,7 @@ void PropCompareTable::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropCompareTable, CPropertyPage) +BEGIN_MESSAGE_MAP(PropCompareTable, OptionsPanel) //{{AFX_MSG_MAP(PropCompareTable) ON_BN_CLICKED(IDC_COMPARE_DEFAULTS, OnDefaults) ON_CBN_DROPDOWN(IDC_COMPARETABLE_CSV_PATTERNS, OnDropDownCSVPatterns) diff --git a/Src/PropDirColors.cpp b/Src/PropDirColors.cpp index eb8fa511f72..86495887b2c 100644 --- a/Src/PropDirColors.cpp +++ b/Src/PropDirColors.cpp @@ -43,7 +43,7 @@ void PropDirColors::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropDirColors, CDialog) +BEGIN_MESSAGE_MAP(PropDirColors, OptionsPanel) //{{AFX_MSG_MAP(PropDirColors) ON_BN_CLICKED(IDC_DIR_ITEM_EQUAL_COLOR, OnDirItemEqualColor) ON_BN_CLICKED(IDC_DIR_ITEM_EQUAL_TEXT_COLOR, OnDirItemEqualTextColor) diff --git a/Src/PropEditor.cpp b/Src/PropEditor.cpp index 811c1fd743c..d5209b2cd27 100644 --- a/Src/PropEditor.cpp +++ b/Src/PropEditor.cpp @@ -57,7 +57,7 @@ void PropEditor::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropEditor, CDialog) +BEGIN_MESSAGE_MAP(PropEditor, OptionsPanel) //{{AFX_MSG_MAP(PropEditor) ON_BN_CLICKED(IDC_VIEW_LINE_DIFFERENCES, OnLineDiffControlClicked) ON_BN_CLICKED(IDC_EDITOR_CHARLEVEL, OnLineDiffControlClicked) diff --git a/Src/PropGeneral.cpp b/Src/PropGeneral.cpp index c545fe9d40e..973063352f8 100644 --- a/Src/PropGeneral.cpp +++ b/Src/PropGeneral.cpp @@ -94,7 +94,7 @@ void PropGeneral::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropGeneral, CPropertyPage) +BEGIN_MESSAGE_MAP(PropGeneral, OptionsPanel) //{{AFX_MSG_MAP(PropGeneral) ON_BN_CLICKED(IDC_RESET_ALL_MESSAGE_BOXES, OnResetAllMessageBoxes) ON_MESSAGE(WM_APP, OnLoadLanguages) diff --git a/Src/PropMarkerColors.cpp b/Src/PropMarkerColors.cpp index 702aee29a48..3e6f252e948 100644 --- a/Src/PropMarkerColors.cpp +++ b/Src/PropMarkerColors.cpp @@ -38,7 +38,7 @@ void PropMarkerColors::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropMarkerColors, CDialog) +BEGIN_MESSAGE_MAP(PropMarkerColors, OptionsPanel) //{{AFX_MSG_MAP(PropMarkerColors) ON_COMMAND_RANGE(IDC_MARKER0_BKGD_COLOR, IDC_MARKER3_BKGD_COLOR, OnMarkerColors) //}}AFX_MSG_MAP diff --git a/Src/PropMergeColors.cpp b/Src/PropMergeColors.cpp index 3ec36cfa8c0..df8f74c47ba 100644 --- a/Src/PropMergeColors.cpp +++ b/Src/PropMergeColors.cpp @@ -61,7 +61,7 @@ void PropMergeColors::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropMergeColors, CDialog) +BEGIN_MESSAGE_MAP(PropMergeColors, OptionsPanel) //{{AFX_MSG_MAP(PropMergeColors) ON_BN_CLICKED(IDC_DIFFERENCE_COLOR, OnDifferenceColor) ON_BN_CLICKED(IDC_DIFFERENCE_DELETED_COLOR, OnDifferenceDeletedColor) diff --git a/Src/PropRegistry.cpp b/Src/PropRegistry.cpp index 16f119f4fa3..6bb6cbdce01 100644 --- a/Src/PropRegistry.cpp +++ b/Src/PropRegistry.cpp @@ -40,7 +40,7 @@ void PropRegistry::DoDataExchange(CDataExchange* pDX) //}}AFX_DATA_MAP } -BEGIN_MESSAGE_MAP(PropRegistry, CDialog) +BEGIN_MESSAGE_MAP(PropRegistry, OptionsPanel) //{{AFX_MSG_MAP(PropRegistry) ON_BN_CLICKED(IDC_EXT_EDITOR_BROWSE, OnBrowseEditor) ON_BN_CLICKED(IDC_FILTER_USER_BROWSE, OnBrowseFilterPath) diff --git a/Src/PropShell.cpp b/Src/PropShell.cpp index 66b8f10bd85..10958d49002 100644 --- a/Src/PropShell.cpp +++ b/Src/PropShell.cpp @@ -119,7 +119,7 @@ void PropShell::DoDataExchange(CDataExchange* pDX) //}}AFX_DATA_MAP } -BEGIN_MESSAGE_MAP(PropShell, CPropertyPage) +BEGIN_MESSAGE_MAP(PropShell, OptionsPanel) //{{AFX_MSG_MAP(PropShell) ON_BN_CLICKED(IDC_EXPLORER_CONTEXT, OnAddToExplorer) ON_BN_CLICKED(IDC_REGISTER_SHELLEXTENSION, OnRegisterShellExtension) diff --git a/Src/PropSyntaxColors.cpp b/Src/PropSyntaxColors.cpp index d91db5c6bdd..26db4cc83ab 100644 --- a/Src/PropSyntaxColors.cpp +++ b/Src/PropSyntaxColors.cpp @@ -55,7 +55,7 @@ void PropSyntaxColors::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropSyntaxColors, CPropertyPage) +BEGIN_MESSAGE_MAP(PropSyntaxColors, OptionsPanel) ON_BN_CLICKED(IDC_SCOLOR_KEYWORDS, OnBnClickedEcolor) ON_BN_CLICKED(IDC_SCOLOR_FUNCTIONS, OnBnClickedEcolor) ON_BN_CLICKED(IDC_SCOLOR_COMMENTS, OnBnClickedEcolor) diff --git a/Src/PropTextColors.cpp b/Src/PropTextColors.cpp index e5c93cc57c1..31add85e06b 100644 --- a/Src/PropTextColors.cpp +++ b/Src/PropTextColors.cpp @@ -46,7 +46,7 @@ void PropTextColors::DoDataExchange(CDataExchange* pDX) } -BEGIN_MESSAGE_MAP(PropTextColors, CDialog) +BEGIN_MESSAGE_MAP(PropTextColors, OptionsPanel) //{{AFX_MSG_MAP(PropTextColors) ON_BN_CLICKED(IDC_DEFAULT_STANDARD_COLORS, OnDefaultsStandardColors) ON_BN_CLICKED(IDC_WHITESPACE_BKGD_COLOR, OnWhitespaceBackgroundColor) diff --git a/Src/TrDialogs.cpp b/Src/TrDialogs.cpp index c778bd37d01..cce118df6c8 100644 --- a/Src/TrDialogs.cpp +++ b/Src/TrDialogs.cpp @@ -6,10 +6,24 @@ IMPLEMENT_DYNAMIC(CTrDialog, CDialog) IMPLEMENT_DYNAMIC(CTrPropertyPage, CPropertyPage) IMPLEMENT_DYNAMIC(CTrDialogBar, CDialogBar) -BEGIN_MESSAGE_MAP(CTrDialog, CDialog) +BEGIN_MESSAGE_MAP(CTrDialog, DpiAware::PerMonitorDpiAwareCWnd) ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) END_MESSAGE_MAP() +BEGIN_MESSAGE_MAP(CTrPropertyPage, DpiAware::PerMonitorDpiAwareCWnd) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) +END_MESSAGE_MAP() + +BEGIN_MESSAGE_MAP(CTrDialogBar, DpiAware::PerMonitorDpiAwareCWnd) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) +END_MESSAGE_MAP() + +void DpiChangedImplHelper(HWND hwnd, int olddpi, int newdpi) +{ + theApp.ChangeDialogFont(hwnd, newdpi); + DpiAware::Dialog_UpdateControlInnerWidths(hwnd, olddpi, newdpi); +} + void StaticDlgUtils::WildcardRemoveDuplicatePatterns(String& patterns) { size_t i = 0, j = 0, k = 0; @@ -32,30 +46,25 @@ void StaticDlgUtils::WildcardRemoveDuplicatePatterns(String& patterns) BOOL CTrDialog::OnInitDialog() { + UpdateDpi(); theApp.TranslateDialog(m_hWnd); - CDialog::OnInitDialog(); + __super::OnInitDialog(); return TRUE; } -LRESULT CTrDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) -{ - UpdateDpi(); - Default(); - theApp.ChangeDialogFont(m_hWnd, GetDpi()); - return 0; -} - BOOL CTrPropertyPage::OnInitDialog() { + UpdateDpi(); theApp.TranslateDialog(m_hWnd); - CPropertyPage::OnInitDialog(); + __super::OnInitDialog(); return TRUE; } BOOL CTrDialogBar::Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName, UINT nStyle, UINT nID) { - BOOL bSucceeded = CDialogBar::Create(pParentWnd, lpszTemplateName, nStyle, nID); + UpdateDpi(); + BOOL bSucceeded = __super::Create(pParentWnd, lpszTemplateName, nStyle, nID); if (bSucceeded) theApp.TranslateDialog(m_hWnd); return bSucceeded; @@ -64,7 +73,8 @@ BOOL CTrDialogBar::Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName, BOOL CTrDialogBar::Create(CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID) { - BOOL bSucceeded = CDialogBar::Create(pParentWnd, nIDTemplate, nStyle, nID); + UpdateDpi(); + BOOL bSucceeded = __super::Create(pParentWnd, nIDTemplate, nStyle, nID); if (bSucceeded) theApp.TranslateDialog(m_hWnd); return bSucceeded; diff --git a/Src/TrDialogs.h b/Src/TrDialogs.h index 46893b2fb63..519182e89b8 100644 --- a/Src/TrDialogs.h +++ b/Src/TrDialogs.h @@ -42,39 +42,74 @@ class DlgUtils : public StaticDlgUtils } }; -class CTrDialog : public CDialog, public DlgUtils, public DpiAware::PerMonitorDpiAwareWindow +void DpiChangedImplHelper(HWND hwnd, int olddpi, int newdpi); + +template +class DpiChangedImpl +{ +public: + LRESULT OnDpiChangedImpl(WPARAM wParam, LPARAM lParam) + { + T* pwnd = static_cast(this); + int olddpi = pwnd->m_dpi; + pwnd->UpdateDpi(); + pwnd->Default(); + if (olddpi != pwnd->m_dpi) + DpiChangedImplHelper(pwnd->m_hWnd, olddpi, pwnd->m_dpi); + return 0; + } +}; + +class CTrDialog + : public DpiAware::PerMonitorDpiAwareCWnd + , public DlgUtils + , public DpiChangedImpl { + friend DpiChangedImpl; DECLARE_DYNAMIC(CTrDialog) public: - CTrDialog() : CDialog() {} - explicit CTrDialog(UINT nIDTemplate, CWnd *pParent = nullptr) : CDialog(nIDTemplate, pParent) {} - explicit CTrDialog(LPCTSTR lpszTemplateName, CWnd *pParentWnd = nullptr) : CDialog(lpszTemplateName, pParentWnd) {} + using DpiAware::PerMonitorDpiAwareCWnd::PerMonitorDpiAwareCWnd; virtual BOOL OnInitDialog(); DECLARE_MESSAGE_MAP() - afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); + afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam) + { + return OnDpiChangedImpl(wParam, lParam); + } }; -class CTrPropertyPage : public CPropertyPage, public DlgUtils, public DpiAware::PerMonitorDpiAwareWindow +class CTrPropertyPage + : public DpiAware::PerMonitorDpiAwareCWnd + , public DlgUtils + , public DpiChangedImpl { + friend DpiChangedImpl; DECLARE_DYNAMIC(CTrPropertyPage) public: - CTrPropertyPage() : CPropertyPage() {} - explicit CTrPropertyPage(UINT nIDTemplate, UINT nIDCaption = 0, DWORD dwSize = sizeof(PROPSHEETPAGE)) - : CPropertyPage(nIDTemplate, nIDCaption, dwSize) {} - explicit CTrPropertyPage(LPCTSTR lpszTemplateName, UINT nIDCaption = 0, DWORD dwSize = sizeof(PROPSHEETPAGE)) - : CPropertyPage(lpszTemplateName, nIDCaption, dwSize) {} + using DpiAware::PerMonitorDpiAwareCWnd::PerMonitorDpiAwareCWnd; virtual BOOL OnInitDialog(); + + DECLARE_MESSAGE_MAP() + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) { + return OnDpiChangedImpl(wParam, lParam); + } }; -class CTrDialogBar : public CDialogBar, public DlgUtils, public DpiAware::PerMonitorDpiAwareWindow +class CTrDialogBar + : public DpiAware::PerMonitorDpiAwareCWnd + , public DlgUtils + , public DpiChangedImpl { + friend DpiChangedImpl; DECLARE_DYNAMIC(CTrDialogBar) public: virtual BOOL Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName, UINT nStyle, UINT nID); virtual BOOL Create(CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID); + + DECLARE_MESSAGE_MAP() + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) { return OnDpiChangedImpl(wParam, lParam); } }; From 59cf6d9d50f0134e51c328bf1b1cd788acb2297a Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Fri, 11 Sep 2020 09:05:13 +0900 Subject: [PATCH 08/23] WIP: Add support for per-monitor DPI awareness (8) --- Externals/crystaledit/Sample/ChildFrm.cpp | 9 ++++++--- Externals/crystaledit/Sample/ChildFrm.h | 9 ++++++--- Externals/crystaledit/Sample/MainFrm.cpp | 6 ++---- Externals/crystaledit/Sample/MainFrm.h | 2 +- Externals/crystaledit/Sample/SampleView.cpp | 2 +- .../crystaledit/editlib/ccrystaltextview.cpp | 4 +--- .../crystaledit/editlib/ccrystaltextview.h | 3 +-- .../crystaledit/editlib/dialogs/memcombo.cpp | 8 +++++++- Externals/crystaledit/editlib/utils/DpiAware.h | 13 +++++++++++-- Src/Common/BCMenu.cpp | 2 +- Src/Common/LanguageSelect.cpp | 7 ++++++- Src/Common/MDITabBar.h | 2 +- Src/Common/MessageBoxDialog.cpp | 12 +++++++----- Src/Common/MessageBoxDialog.h | 2 +- Src/Common/PreferencesDlg.cpp | 6 ++---- Src/Common/SuperComboBox.cpp | 1 - Src/Common/SuperComboBox.h | 2 +- Src/Common/scbarcf.cpp | 1 - Src/Common/sizecbar.cpp | 7 ++----- Src/Common/sizecbar.h | 2 +- Src/DirView.cpp | 3 +-- Src/DirView.h | 2 +- Src/EditorFilepathBar.cpp | 4 +--- Src/EditorFilepathBar.h | 2 +- Src/MainFrm.cpp | 12 +++++------- Src/MainFrm.h | 4 ++-- Src/MergeFrameCommon.cpp | 17 +---------------- Src/MergeFrameCommon.h | 11 +---------- Src/MergeStatusBar.cpp | 4 +--- Src/MergeStatusBar.h | 2 +- Src/OpenView.cpp | 6 ++---- Src/OpenView.h | 2 +- Src/TrDialogs.cpp | 10 +++------- Src/TrDialogs.h | 10 +++++----- Src/WindowsManagerDialog.cpp | 2 +- 35 files changed, 85 insertions(+), 106 deletions(-) diff --git a/Externals/crystaledit/Sample/ChildFrm.cpp b/Externals/crystaledit/Sample/ChildFrm.cpp index f8a026d5f52..0a57d381224 100755 --- a/Externals/crystaledit/Sample/ChildFrm.cpp +++ b/Externals/crystaledit/Sample/ChildFrm.cpp @@ -15,10 +15,14 @@ static char THIS_FILE[] = __FILE__; ///////////////////////////////////////////////////////////////////////////// // CChildFrame -IMPLEMENT_DYNCREATE(CChildFrame, DpiAware::PerMonitorDpiAwareCWnd) +IMPLEMENT_DYNCREATE(CChildFrame, DpiAware::CDpiAwareWnd) -BEGIN_MESSAGE_MAP(CChildFrame, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CChildFrame, DpiAware::CDpiAwareWnd) + //{{AFX_MSG_MAP(CChildFrame) ON_WM_GETMINMAXINFO() + // NOTE - the ClassWizard will add and remove mapping macros here. + // DO NOT EDIT what you see in these blocks of generated code ! + //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// @@ -63,7 +67,6 @@ void CChildFrame::Dump(CDumpContext& dc) const BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { - UpdateDpi(); return m_wndSplitter.Create(this, 2, 2, CSize(30, 30), pContext); } diff --git a/Externals/crystaledit/Sample/ChildFrm.h b/Externals/crystaledit/Sample/ChildFrm.h index c1a8a447625..f3a7c1b35c6 100755 --- a/Externals/crystaledit/Sample/ChildFrm.h +++ b/Externals/crystaledit/Sample/ChildFrm.h @@ -6,7 +6,7 @@ #include "utils/DpiAware.h" -class CChildFrame : public DpiAware::PerMonitorDpiAwareCWnd +class CChildFrame : public DpiAware::CDpiAwareWnd { DECLARE_DYNCREATE(CChildFrame) public: @@ -38,9 +38,12 @@ class CChildFrame : public DpiAware::PerMonitorDpiAwareCWnd // Generated message map functions protected: - DECLARE_MESSAGE_MAP() -public: + //{{AFX_MSG(CChildFrame) + // NOTE - the ClassWizard will add and remove member functions here. + // DO NOT EDIT what you see in these blocks of generated code! + //}}AFX_MSG afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); + DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// diff --git a/Externals/crystaledit/Sample/MainFrm.cpp b/Externals/crystaledit/Sample/MainFrm.cpp index 0a340cca01f..d74445b458b 100755 --- a/Externals/crystaledit/Sample/MainFrm.cpp +++ b/Externals/crystaledit/Sample/MainFrm.cpp @@ -16,9 +16,9 @@ static char THIS_FILE[] = __FILE__; ///////////////////////////////////////////////////////////////////////////// // CMainFrame -IMPLEMENT_DYNAMIC(CMainFrame, DpiAware::PerMonitorDpiAwareCWnd) +IMPLEMENT_DYNAMIC(CMainFrame, DpiAware::CDpiAwareWnd) -BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::CDpiAwareWnd) //{{AFX_MSG_MAP(CMainFrame) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code ! @@ -59,8 +59,6 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (__super::OnCreate(lpCreateStruct) == -1) return -1; - - UpdateDpi(); if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) diff --git a/Externals/crystaledit/Sample/MainFrm.h b/Externals/crystaledit/Sample/MainFrm.h index f414981240f..85e78a2c138 100755 --- a/Externals/crystaledit/Sample/MainFrm.h +++ b/Externals/crystaledit/Sample/MainFrm.h @@ -6,7 +6,7 @@ #include "utils/DpiAware.h" -class CMainFrame : public DpiAware::PerMonitorDpiAwareCWnd +class CMainFrame : public DpiAware::CDpiAwareWnd { DECLARE_DYNAMIC(CMainFrame) public: diff --git a/Externals/crystaledit/Sample/SampleView.cpp b/Externals/crystaledit/Sample/SampleView.cpp index 129f782b8eb..b766cf9f017 100755 --- a/Externals/crystaledit/Sample/SampleView.cpp +++ b/Externals/crystaledit/Sample/SampleView.cpp @@ -85,7 +85,7 @@ CCrystalTextBuffer *CSampleView::LocateTextBuffer() return &GetDocument()->m_xTextBuffer; } -void CSampleView::OnInitialUpdate() +void CSampleView::OnInitialUpdate() { CCrystalEditViewEx::OnInitialUpdate(); diff --git a/Externals/crystaledit/editlib/ccrystaltextview.cpp b/Externals/crystaledit/editlib/ccrystaltextview.cpp index c1cafcf0e75..bb07f57e6c4 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview.cpp @@ -171,7 +171,7 @@ CCrystalTextView::RENDERING_MODE CCrystalTextView::s_nRenderingModeDefault = REN static ptrdiff_t FindStringHelper(LPCTSTR pszLineBegin, size_t nLineLength, LPCTSTR pszFindWhere, LPCTSTR pszFindWhat, DWORD dwFlags, int &nLen, RxNode *&rxnode, RxMatchRes *rxmatch); -BEGIN_MESSAGE_MAP (CCrystalTextView, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP (CCrystalTextView, DpiAware::CDpiAwareWnd) //{{AFX_MSG_MAP(CCrystalTextView) ON_WM_DESTROY () ON_WM_ERASEBKGND () @@ -3225,7 +3225,6 @@ void CCrystalTextView:: OnInitialUpdate () { __super::OnInitialUpdate (); - UpdateDpi (); CString sDoc = GetDocument ()->GetPathName (), sExt = GetExt (sDoc); if (!sExt.IsEmpty()) SetTextType (sExt); @@ -5040,7 +5039,6 @@ GetResourceHandle () int CCrystalTextView:: OnCreate (LPCREATESTRUCT lpCreateStruct) { - UpdateDpi (); m_lfBaseFont = {}; _tcscpy_s (m_lfBaseFont.lfFaceName, _T ("FixedSys")); m_lfBaseFont.lfHeight = 0; diff --git a/Externals/crystaledit/editlib/ccrystaltextview.h b/Externals/crystaledit/editlib/ccrystaltextview.h index e683b020648..fc30d0de592 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.h +++ b/Externals/crystaledit/editlib/ccrystaltextview.h @@ -83,7 +83,7 @@ enum : unsigned * not implement text editing. There are classes inherited from this * class which implement text editing. */ -class EDITPADC_CLASS CCrystalTextView : public DpiAware::PerMonitorDpiAwareCWnd +class EDITPADC_CLASS CCrystalTextView : public DpiAware::CDpiAwareWnd { DECLARE_DYNCREATE (CCrystalTextView) @@ -814,7 +814,6 @@ protected : virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo); virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo); virtual void OnPrint (CDC * pDC, CPrintInfo * pInfo); - //}}AFX_VIRTUAL // Implementation diff --git a/Externals/crystaledit/editlib/dialogs/memcombo.cpp b/Externals/crystaledit/editlib/dialogs/memcombo.cpp index 6211e8bc8ea..4f0e7e8405e 100644 --- a/Externals/crystaledit/editlib/dialogs/memcombo.cpp +++ b/Externals/crystaledit/editlib/dialogs/memcombo.cpp @@ -69,9 +69,14 @@ void SetComboBoxWidth(CComboBox &Control, LPCTSTR lpszText = nullptr) if(!cnt) return; + + HMONITOR monitor = MonitorFromWindow(Control.m_hWnd, MONITOR_DEFAULTTONEAREST); + MONITORINFO info{ sizeof MONITORINFO }; + GetMonitorInfo(monitor, &info); + CClientDC dc(&Control); CFont *oldFont; - int width = 0, nMax = ::GetSystemMetrics(SM_CXSCREEN) - 48; + int width = 0, nMax = info.rcMonitor.right - 48; CRect rc; CSize size; @@ -90,6 +95,7 @@ void SetComboBoxWidth(CComboBox &Control, LPCTSTR lpszText = nullptr) width = size.cx; } } + width += GetSystemMetrics(SM_CXVSCROLL) + 2 * GetSystemMetrics(SM_CXEDGE); Control.GetClientRect(rc); Control.ClientToScreen(rc); if(rc.left + width > nMax) diff --git a/Externals/crystaledit/editlib/utils/DpiAware.h b/Externals/crystaledit/editlib/utils/DpiAware.h index dd41d595bf1..17bc5f1e7ac 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.h +++ b/Externals/crystaledit/editlib/utils/DpiAware.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "mfc_templ_defines.h" #ifndef WM_DPICHANGED @@ -41,10 +42,10 @@ namespace DpiAware HIMAGELIST LoadShellImageList(int dpi); template - class PerMonitorDpiAwareCWnd : public Base + class CDpiAwareWnd : public Base { public: - using this_type = PerMonitorDpiAwareCWnd; + using this_type = CDpiAwareWnd; using base_type = Base; using Base::Base; @@ -77,6 +78,12 @@ namespace DpiAware return DPIOnInit != m_dpi; } + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct) + { + UpdateDpi(); + return __super::OnCreate(lpCreateStruct); + } + afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam) { UpdateDpi(); @@ -92,6 +99,8 @@ namespace DpiAware int m_dpi = DPIOnInit; BEGIN_MESSAGE_MAP_INLINE(this_type, base_type) + ON_WM_CREATE() + ON_WM_CREATE() ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP_INLINE() diff --git a/Src/Common/BCMenu.cpp b/Src/Common/BCMenu.cpp index 330d09bef56..89b204e6a22 100644 --- a/Src/Common/BCMenu.cpp +++ b/Src/Common/BCMenu.cpp @@ -772,7 +772,7 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) VERIFY(::GetTextExtentPoint32W(dc.m_hDC,lpstrText, lstrlenW(lpstrText),&size)); //SK should also work on 95 - CSize t = size; + CSize t = CSize(size); dc.SelectObject (pFont); // Select old font in // Set width and height: diff --git a/Src/Common/LanguageSelect.cpp b/Src/Common/LanguageSelect.cpp index 52f641f1c49..f38c310a493 100644 --- a/Src/Common/LanguageSelect.cpp +++ b/Src/Common/LanguageSelect.cpp @@ -738,7 +738,12 @@ void CLanguageSelect::SetIndicators(CStatusBar &sb, const UINT *rgid, int n) con sb.SetIndicators(0, n); else n = sb.m_nCount; - int cx = ::GetSystemMetrics(SM_CXSCREEN) / 4; // default to 1/4 the screen width + + HMONITOR monitor = MonitorFromWindow(sb.m_hWnd, MONITOR_DEFAULTTONEAREST); + MONITORINFO info{ sizeof MONITORINFO }; + GetMonitorInfo(monitor, &info); + + int cx = (info.rcMonitor.right - info.rcMonitor.left) / 4; // default to 1/4 the screen width UINT style = SBPS_STRETCH | SBPS_NOBORDERS; // first pane is stretchy for (int i = 0 ; i < n ; ++i) { diff --git a/Src/Common/MDITabBar.h b/Src/Common/MDITabBar.h index 893bf9eb901..35fad19ef40 100644 --- a/Src/Common/MDITabBar.h +++ b/Src/Common/MDITabBar.h @@ -11,7 +11,7 @@ /** * @brief Class for Tab bar. */ -class CMDITabBar : public DpiAware::PerMonitorDpiAwareCWnd +class CMDITabBar : public DpiAware::CDpiAwareWnd { DECLARE_DYNAMIC(CMDITabBar) diff --git a/Src/Common/MessageBoxDialog.cpp b/Src/Common/MessageBoxDialog.cpp index 4691e328771..220d1097aca 100644 --- a/Src/Common/MessageBoxDialog.cpp +++ b/Src/Common/MessageBoxDialog.cpp @@ -85,7 +85,7 @@ IMPLEMENT_DYNAMIC(CMessageBoxDialog, CDialog) */ CMessageBoxDialog::CMessageBoxDialog ( CWnd* pParent, CString strMessage, CString strTitle, UINT nStyle, UINT nHelp ) - : DpiAware::PerMonitorDpiAwareCWnd ( CMessageBoxDialog::IDD, pParent ) + : DpiAware::CDpiAwareWnd ( CMessageBoxDialog::IDD, pParent ) , m_strMessage(strMessage) , m_strTitle(strTitle.IsEmpty() ? AfxGetAppName() : strTitle) , m_nStyle(nStyle) @@ -468,8 +468,6 @@ void CMessageBoxDialog::EndDialog ( int nResult ) */ BOOL CMessageBoxDialog::OnInitDialog ( ) { - UpdateDpi(); - // Call the parent method. if ( !__super::OnInitDialog() ) { @@ -851,7 +849,7 @@ BOOL CMessageBoxDialog::OnWndMsg ( UINT message, WPARAM wParam, LPARAM lParam, return __super::OnWndMsg(message, wParam, lParam, pResult); } -BEGIN_MESSAGE_MAP(CMessageBoxDialog, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CMessageBoxDialog, DpiAware::CDpiAwareWnd) ON_WM_TIMER() ON_WM_ERASEBKGND() ON_WM_CTLCOLOR() @@ -1275,8 +1273,12 @@ void CMessageBoxDialog::CreateMessageControl ( ) // Select the new font and store the old one. CFont* pOldFont = dcDisplay.SelectObject(&m_fontMainInstruction); + HMONITOR monitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST); + MONITORINFO info{ sizeof MONITORINFO }; + GetMonitorInfo(monitor, &info); + // Define the maximum width of the message. - int nMaxWidth = ( GetSystemMetrics(SM_CXSCREEN) / 2 ) + 100; + int nMaxWidth = ( info.rcMonitor.right / 2 ) + 100; // Check whether an icon is displayed. if ( m_hIcon != nullptr ) diff --git a/Src/Common/MessageBoxDialog.h b/Src/Common/MessageBoxDialog.h index d39ded47beb..d9b0f282470 100644 --- a/Src/Common/MessageBoxDialog.h +++ b/Src/Common/MessageBoxDialog.h @@ -86,7 +86,7 @@ ////////////////////////////////////////////////////////////////////////////// // Class definition. -class CMessageBoxDialog : public DpiAware::PerMonitorDpiAwareCWnd +class CMessageBoxDialog : public DpiAware::CDpiAwareWnd { DECLARE_DYNAMIC(CMessageBoxDialog) diff --git a/Src/Common/PreferencesDlg.cpp b/Src/Common/PreferencesDlg.cpp index 0d110fcd89c..942402b1c4d 100644 --- a/Src/Common/PreferencesDlg.cpp +++ b/Src/Common/PreferencesDlg.cpp @@ -118,21 +118,19 @@ BOOL CPreferencesDlg::OnInitDialog() AddPage(&m_pageShell, IDS_OPTIONSPG_SHELL); ReadOptions(); - + CRect rPPHost; GetDlgItem(IDC_TREEOPT_HOSTFRAME)->GetWindowRect(rPPHost); ScreenToClient(rPPHost); if (m_pphost.Create(rPPHost, this)) SetActivePage(AfxGetApp()->GetProfileInt(_T("Settings"), _T("OptStartPage"), 0)); - + // setup handler for resizing this dialog - /* m_constraint.InitializeCurrentSize(this); m_constraint.DisallowHeightGrowth(); m_constraint.SubclassWnd(); // install subclassing m_constraint.LoadPosition(_T("ResizeableDialogs"), _T("OptionsDlg"), false); // persist size via registry -*/ return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } diff --git a/Src/Common/SuperComboBox.cpp b/Src/Common/SuperComboBox.cpp index 047f1fa64ce..ca01cb40b0d 100644 --- a/Src/Common/SuperComboBox.cpp +++ b/Src/Common/SuperComboBox.cpp @@ -75,7 +75,6 @@ END_MESSAGE_MAP() void CSuperComboBox::PreSubclassWindow() { - UpdateDpi(); __super::PreSubclassWindow(); m_pDropHandler = new DropHandler(std::bind(&CSuperComboBox::OnDropFiles, this, std::placeholders::_1)); RegisterDragDrop(m_hWnd, m_pDropHandler); diff --git a/Src/Common/SuperComboBox.h b/Src/Common/SuperComboBox.h index 3d105de22e0..15c48f5f51e 100644 --- a/Src/Common/SuperComboBox.h +++ b/Src/Common/SuperComboBox.h @@ -12,7 +12,7 @@ class DropHandler; ///////////////////////////////////////////////////////////////////////////// // CSuperComboBox window -class CSuperComboBox : public DpiAware::PerMonitorDpiAwareCWnd +class CSuperComboBox : public DpiAware::CDpiAwareWnd { // Construction public: diff --git a/Src/Common/scbarcf.cpp b/Src/Common/scbarcf.cpp index b5257a5761b..4d778bd0b38 100644 --- a/Src/Common/scbarcf.cpp +++ b/Src/Common/scbarcf.cpp @@ -220,4 +220,3 @@ LRESULT CSizingControlBarCF::OnSetText(WPARAM wParam, LPARAM lParam) return lResult; } - diff --git a/Src/Common/sizecbar.cpp b/Src/Common/sizecbar.cpp index 67f848467f2..569154a7f31 100644 --- a/Src/Common/sizecbar.cpp +++ b/Src/Common/sizecbar.cpp @@ -75,7 +75,7 @@ CSizingControlBar::~CSizingControlBar() { } -BEGIN_MESSAGE_MAP(CSizingControlBar, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CSizingControlBar, DpiAware::CDpiAwareWnd) //{{AFX_MSG_MAP(CSizingControlBar) ON_WM_CREATE() ON_WM_PAINT() @@ -96,7 +96,6 @@ BEGIN_MESSAGE_MAP(CSizingControlBar, DpiAware::PerMonitorDpiAwareCWndm_pointPos.x++; pInfo->m_pointPos.y += - ::GetSystemMetrics(SM_CYSMCAPTION) + 1; + GetSystemMetrics(SM_CYSMCAPTION) + 1; pInfo->SaveState(lpszProfileName, i); } } diff --git a/Src/Common/sizecbar.h b/Src/Common/sizecbar.h index 096a6069c29..d43217bcacc 100644 --- a/Src/Common/sizecbar.h +++ b/Src/Common/sizecbar.h @@ -73,7 +73,7 @@ class CSCBDockBar : public CDockBar class CSizingControlBar; typedef CTypedPtrArray CSCBArray; -class CSizingControlBar : public DpiAware::PerMonitorDpiAwareCWnd +class CSizingControlBar : public DpiAware::CDpiAwareWnd { DECLARE_DYNAMIC(CSizingControlBar); diff --git a/Src/DirView.cpp b/Src/DirView.cpp index 3adaf425e54..9737dad6541 100644 --- a/Src/DirView.cpp +++ b/Src/DirView.cpp @@ -118,7 +118,7 @@ CDirView::~CDirView() { } -BEGIN_MESSAGE_MAP(CDirView, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CDirView, DpiAware::CDpiAwareWnd) ON_WM_CONTEXTMENU() //{{AFX_MSG_MAP(CDirView) ON_WM_LBUTTONDBLCLK() @@ -354,7 +354,6 @@ CDirDoc* CDirView::GetDocument() // non-debug version is inline void CDirView::OnInitialUpdate() { - UpdateDpi(); const int iconCX = [this]() { const int cx = GetSystemMetrics(SM_CXSMICON); if (cx < 24) diff --git a/Src/DirView.h b/Src/DirView.h index ee9491c89b4..57135993545 100644 --- a/Src/DirView.h +++ b/Src/DirView.h @@ -60,7 +60,7 @@ const UINT DefColumnWidth = 150; * CDiffContext items are linked by storing POSITION of CDiffContext item * as CDirView listitem key. */ -class CDirView : public DpiAware::PerMonitorDpiAwareCWnd +class CDirView : public DpiAware::CDpiAwareWnd { friend struct FileCmpReport; friend DirItemEnumerator; diff --git a/Src/EditorFilepathBar.cpp b/Src/EditorFilepathBar.cpp index 07691d37ddd..a1ec7fafbd0 100644 --- a/Src/EditorFilepathBar.cpp +++ b/Src/EditorFilepathBar.cpp @@ -17,7 +17,7 @@ #define new DEBUG_NEW #endif -BEGIN_MESSAGE_MAP(CEditorFilePathBar, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CEditorFilePathBar, DpiAware::CDpiAwareWnd) ON_NOTIFY_EX (TTN_NEEDTEXT, 0, OnToolTipNotify) ON_CONTROL_RANGE (EN_SETFOCUS, IDC_STATIC_TITLE_PANE0, IDC_STATIC_TITLE_PANE2, OnSetFocusEdit) ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) @@ -51,8 +51,6 @@ BOOL CEditorFilePathBar::Create(CWnd* pParentWnd) CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, CEditorFilePathBar::IDD)) return FALSE; - UpdateDpi(); - LOGFONT lfStatusFont; if (DpiAware::GetNonClientLogFont(lfStatusFont, offsetof(NONCLIENTMETRICS, lfStatusFont), GetDpi())) m_font.CreateFontIndirect(&lfStatusFont); diff --git a/Src/EditorFilepathBar.h b/Src/EditorFilepathBar.h index 32687e7018b..e126cc3526f 100644 --- a/Src/EditorFilepathBar.h +++ b/Src/EditorFilepathBar.h @@ -36,7 +36,7 @@ class IHeaderBar * The bar looks like a statusBar (font, height). The control * displays a tip for each path (as a tooltip). */ -class CEditorFilePathBar : public DpiAware::PerMonitorDpiAwareCWnd, public IHeaderBar +class CEditorFilePathBar : public DpiAware::CDpiAwareWnd, public IHeaderBar { public : CEditorFilePathBar(); diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index b04c971fdb5..00fc7f107d2 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -156,7 +156,7 @@ const CMainFrame::MENUITEM_ICON CMainFrame::m_MenuIcons[] = { IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) -BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::CDpiAwareWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_MENUCHAR() ON_WM_MEASUREITEM() @@ -310,8 +310,6 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) if (__super::OnCreate(lpCreateStruct) == -1) return -1; - UpdateDpi(); - m_wndMDIClient.SubclassWindow(m_hWndMDIClient); m_wndMDIClient.UpdateDpi(); @@ -1194,10 +1192,10 @@ void CMainFrame::ActivateFrame(int nCmdShow) CRect dsk_rc,rc(wp.rcNormalPosition); - dsk_rc.left = ::GetSystemMetrics(SM_XVIRTUALSCREEN); - dsk_rc.top = ::GetSystemMetrics(SM_YVIRTUALSCREEN); - dsk_rc.right = dsk_rc.left + ::GetSystemMetrics(SM_CXVIRTUALSCREEN); - dsk_rc.bottom = dsk_rc.top + ::GetSystemMetrics(SM_CYVIRTUALSCREEN); + dsk_rc.left = GetSystemMetrics(SM_XVIRTUALSCREEN); + dsk_rc.top = GetSystemMetrics(SM_YVIRTUALSCREEN); + dsk_rc.right = dsk_rc.left + GetSystemMetrics(SM_CXVIRTUALSCREEN); + dsk_rc.bottom = dsk_rc.top + GetSystemMetrics(SM_CYVIRTUALSCREEN); if (rc.Width() != 0 && rc.Height() != 0) { // Ensure top-left corner is on visible area, diff --git a/Src/MainFrm.h b/Src/MainFrm.h index 91a5c3c3854..ac05304510a 100644 --- a/Src/MainFrm.h +++ b/Src/MainFrm.h @@ -50,7 +50,7 @@ CMainFrame * GetMainFrame(); // access to the singleton main frame object /** * @brief Frame class containing save-routines etc */ -class CMainFrame : public DpiAware::PerMonitorDpiAwareCWnd +class CMainFrame : public DpiAware::CDpiAwareWnd { friend CLanguageSelect; DECLARE_DYNAMIC(CMainFrame) @@ -143,7 +143,7 @@ class CMainFrame : public DpiAware::PerMonitorDpiAwareCWnd CTypedPtrArray m_arrChild; // Tweak MDI client window behavior - class CMDIClient : public DpiAware::PerMonitorDpiAwareCWnd + class CMDIClient : public DpiAware::CDpiAwareWnd { static UINT_PTR const m_nRedrawTimer = 1612; virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index 4d84e2c48a3..f0a22666ede 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -14,7 +14,7 @@ IMPLEMENT_DYNCREATE(CMergeFrameCommon, CMDIChildWnd) -BEGIN_MESSAGE_MAP(CMergeFrameCommon, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CMergeFrameCommon, DpiAware::CDpiAwareWnd) //{{AFX_MSG_MAP(CMergeFrameCommon) ON_WM_GETMINMAXINFO() ON_WM_DESTROY() @@ -37,14 +37,6 @@ CMergeFrameCommon::~CMergeFrameCommon() ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEREMOVED, 0, reinterpret_cast(this)); } -BOOL CMergeFrameCommon::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CMDIFrameWnd* pParentWnd, CCreateContext* pContext) -{ - if (!__super::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, pContext)) - return FALSE; - UpdateDpi(); - return TRUE; -} - void CMergeFrameCommon::ActivateFrame(int nCmdShow) { if (!m_bActivated) @@ -146,10 +138,3 @@ void CMergeFrameCommon::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* if (bActivate) ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEACTIVATED, 0, reinterpret_cast(this)); } - -/* -LRESULT CMergeFrameCommon::OnGetIcon(WPARAM wParam, LPARAM lParam) -{ - return 0; -} -*/ diff --git a/Src/MergeFrameCommon.h b/Src/MergeFrameCommon.h index a4e632350b5..8f5e8b2573e 100644 --- a/Src/MergeFrameCommon.h +++ b/Src/MergeFrameCommon.h @@ -8,17 +8,11 @@ #include "utils/DpiAware.h" -class CMergeFrameCommon: public DpiAware::PerMonitorDpiAwareCWnd +class CMergeFrameCommon: public DpiAware::CDpiAwareWnd { DECLARE_DYNCREATE(CMergeFrameCommon) public: CMergeFrameCommon(int nIdenticalIcon = -1, int nDifferentIcon = -1); - virtual BOOL Create(LPCTSTR lpszClassName, - LPCTSTR lpszWindowName, - DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, - const RECT& rect = rectDefault, - CMDIFrameWnd* pParentWnd = NULL, - CCreateContext* pContext = NULL); bool IsActivated() const { return m_bActivated; } void ActivateFrame(int nCmdShow); void SetLastCompareResult(int nResult); @@ -29,7 +23,6 @@ class CMergeFrameCommon: public DpiAware::PerMonitorDpiAwareCWnd { return TRUE; // https://stackoverflow.com/questions/35553955/getting-rid-of-3d-look-of-mdi-frame-window } - protected: int m_nLastSplitPos[2]; private: @@ -45,8 +38,6 @@ class CMergeFrameCommon: public DpiAware::PerMonitorDpiAwareCWnd afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); afx_msg void OnDestroy(); afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd); -// afx_msg LRESULT OnGetIcon(WPARAM wParam, LPARAM lParam); - //}}AFX_MSG DECLARE_MESSAGE_MAP() }; diff --git a/Src/MergeStatusBar.cpp b/Src/MergeStatusBar.cpp index 9016962d52f..5de4e641169 100644 --- a/Src/MergeStatusBar.cpp +++ b/Src/MergeStatusBar.cpp @@ -68,7 +68,7 @@ static UINT indicatorsBottom[] = ID_SEPARATOR, }; -BEGIN_MESSAGE_MAP(CMergeStatusBar, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CMergeStatusBar, DpiAware::CDpiAwareWnd) END_MESSAGE_MAP() /** @@ -96,8 +96,6 @@ BOOL CMergeStatusBar::Create(CWnd* pParentWnd) if (! __super::Create(pParentWnd)) return FALSE; - UpdateDpi(); - SetIndicators(indicatorsBottom, sizeof(indicatorsBottom) / sizeof(UINT)); // Set text to read-only info panes diff --git a/Src/MergeStatusBar.h b/Src/MergeStatusBar.h index b3185d0b131..dc88a506220 100644 --- a/Src/MergeStatusBar.h +++ b/Src/MergeStatusBar.h @@ -16,7 +16,7 @@ #include "UnicodeString.h" #include "utils/DpiAware.h" -class CMergeStatusBar : public DpiAware::PerMonitorDpiAwareCWnd +class CMergeStatusBar : public DpiAware::CDpiAwareWnd { public : CMergeStatusBar(); diff --git a/Src/OpenView.cpp b/Src/OpenView.cpp index 92f7df9b14d..ee1e77486ca 100644 --- a/Src/OpenView.cpp +++ b/Src/OpenView.cpp @@ -54,7 +54,7 @@ static TCHAR OpenDlgHelpLocation[] = _T("::/htmlhelp/Open_paths.html"); IMPLEMENT_DYNCREATE(COpenView, CFormView) -BEGIN_MESSAGE_MAP(COpenView, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(COpenView, DpiAware::CDpiAwareWnd) //{{AFX_MSG_MAP(COpenView) ON_BN_CLICKED(IDC_PATH0_BUTTON, OnPathButton<0>) ON_BN_CLICKED(IDC_PATH1_BUTTON, OnPathButton<1>) @@ -104,7 +104,7 @@ END_MESSAGE_MAP() // COpenView construction/destruction COpenView::COpenView() - : DpiAware::PerMonitorDpiAwareCWnd(COpenView::IDD) + : DpiAware::CDpiAwareWnd(COpenView::IDD) , m_pUpdateButtonStatusThread(nullptr) , m_bRecurse(false) , m_pDropHandler(nullptr) @@ -155,8 +155,6 @@ BOOL COpenView::PreCreateWindow(CREATESTRUCT& cs) void COpenView::OnInitialUpdate() { - UpdateDpi(); - if (!IsVista_OrGreater()) { // fallback for XP diff --git a/Src/OpenView.h b/Src/OpenView.h index fac26f75f63..f7b3564612e 100644 --- a/Src/OpenView.h +++ b/Src/OpenView.h @@ -34,7 +34,7 @@ class DropHandler; * The dialog shows also a status of the selected paths (found/not found), * if enabled in the options (enabled by default). */ -class COpenView : public DpiAware::PerMonitorDpiAwareCWnd, public DlgUtils +class COpenView : public DpiAware::CDpiAwareWnd, public DlgUtils { protected: // create from serialization only COpenView(); diff --git a/Src/TrDialogs.cpp b/Src/TrDialogs.cpp index cce118df6c8..76b2f14a7db 100644 --- a/Src/TrDialogs.cpp +++ b/Src/TrDialogs.cpp @@ -6,15 +6,15 @@ IMPLEMENT_DYNAMIC(CTrDialog, CDialog) IMPLEMENT_DYNAMIC(CTrPropertyPage, CPropertyPage) IMPLEMENT_DYNAMIC(CTrDialogBar, CDialogBar) -BEGIN_MESSAGE_MAP(CTrDialog, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CTrDialog, DpiAware::CDpiAwareWnd) ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) END_MESSAGE_MAP() -BEGIN_MESSAGE_MAP(CTrPropertyPage, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CTrPropertyPage, DpiAware::CDpiAwareWnd) ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP() -BEGIN_MESSAGE_MAP(CTrDialogBar, DpiAware::PerMonitorDpiAwareCWnd) +BEGIN_MESSAGE_MAP(CTrDialogBar, DpiAware::CDpiAwareWnd) ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP() @@ -46,7 +46,6 @@ void StaticDlgUtils::WildcardRemoveDuplicatePatterns(String& patterns) BOOL CTrDialog::OnInitDialog() { - UpdateDpi(); theApp.TranslateDialog(m_hWnd); __super::OnInitDialog(); return TRUE; @@ -54,7 +53,6 @@ BOOL CTrDialog::OnInitDialog() BOOL CTrPropertyPage::OnInitDialog() { - UpdateDpi(); theApp.TranslateDialog(m_hWnd); __super::OnInitDialog(); return TRUE; @@ -63,7 +61,6 @@ BOOL CTrPropertyPage::OnInitDialog() BOOL CTrDialogBar::Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName, UINT nStyle, UINT nID) { - UpdateDpi(); BOOL bSucceeded = __super::Create(pParentWnd, lpszTemplateName, nStyle, nID); if (bSucceeded) theApp.TranslateDialog(m_hWnd); @@ -73,7 +70,6 @@ BOOL CTrDialogBar::Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName, BOOL CTrDialogBar::Create(CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID) { - UpdateDpi(); BOOL bSucceeded = __super::Create(pParentWnd, nIDTemplate, nStyle, nID); if (bSucceeded) theApp.TranslateDialog(m_hWnd); diff --git a/Src/TrDialogs.h b/Src/TrDialogs.h index 519182e89b8..f753c10f200 100644 --- a/Src/TrDialogs.h +++ b/Src/TrDialogs.h @@ -61,14 +61,14 @@ class DpiChangedImpl }; class CTrDialog - : public DpiAware::PerMonitorDpiAwareCWnd + : public DpiAware::CDpiAwareWnd , public DlgUtils , public DpiChangedImpl { friend DpiChangedImpl; DECLARE_DYNAMIC(CTrDialog) public: - using DpiAware::PerMonitorDpiAwareCWnd::PerMonitorDpiAwareCWnd; + using DpiAware::CDpiAwareWnd::CDpiAwareWnd; virtual BOOL OnInitDialog(); @@ -80,14 +80,14 @@ class CTrDialog }; class CTrPropertyPage - : public DpiAware::PerMonitorDpiAwareCWnd + : public DpiAware::CDpiAwareWnd , public DlgUtils , public DpiChangedImpl { friend DpiChangedImpl; DECLARE_DYNAMIC(CTrPropertyPage) public: - using DpiAware::PerMonitorDpiAwareCWnd::PerMonitorDpiAwareCWnd; + using DpiAware::CDpiAwareWnd::CDpiAwareWnd; virtual BOOL OnInitDialog(); @@ -98,7 +98,7 @@ class CTrPropertyPage }; class CTrDialogBar - : public DpiAware::PerMonitorDpiAwareCWnd + : public DpiAware::CDpiAwareWnd , public DlgUtils , public DpiChangedImpl { diff --git a/Src/WindowsManagerDialog.cpp b/Src/WindowsManagerDialog.cpp index db85669d00f..94b1cfb62c1 100644 --- a/Src/WindowsManagerDialog.cpp +++ b/Src/WindowsManagerDialog.cpp @@ -139,7 +139,7 @@ void CWindowsManagerDialog::AdjustSize() const int nImgWidth = rect.right - rect.left; const int nSpaceWidth = m_List.GetStringWidth(_T(" ")); - const int nLeftMargin = ::GetSystemMetrics(SM_CXFRAME) * 2 + nSpaceWidth * 4; + const int nLeftMargin = GetSystemMetrics(SM_CXFRAME) * 2 + nSpaceWidth * 4; int nMaxWidth = -1; From ae46e46c4ca93d6f6954d082960b0dac800afdf9 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Fri, 11 Sep 2020 23:02:23 +0900 Subject: [PATCH 09/23] memcombo.cpp: The text width was calculated using the wrong font.WIP: Add support for per-monitor DPI awareness (9) --- .../crystaledit/editlib/utils/DpiAware.cpp | 9 +++++++-- .../crystaledit/editlib/utils/DpiAware.h | 1 - Src/Common/MDITabBar.cpp | 2 +- Src/Common/MessageBoxDialog.cpp | 5 ++--- Src/Common/SuperComboBox.cpp | 19 ++++++++++++++----- Src/Common/scbarcf.cpp | 4 ++-- Src/Common/scbarg.cpp | 6 +++--- Src/Common/sizecbar.cpp | 16 ++++++++-------- Src/DirView.cpp | 2 +- Src/EditorFilepathBar.cpp | 7 ++++--- Src/MainFrm.cpp | 8 ++++---- Src/MergeStatusBar.cpp | 17 +++++++++++++++++ Src/MergeStatusBar.h | 5 +++++ 13 files changed, 68 insertions(+), 33 deletions(-) diff --git a/Externals/crystaledit/editlib/utils/DpiAware.cpp b/Externals/crystaledit/editlib/utils/DpiAware.cpp index 6baa7143543..840f209f1b0 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.cpp +++ b/Externals/crystaledit/editlib/utils/DpiAware.cpp @@ -120,14 +120,19 @@ namespace DpiAware } else { + int cxsmicon = ::GetSystemMetrics(SM_CXSMICON); + int iconsize = MulDiv(16, dpi, 96); int size = SHIL_EXTRALARGE; - if (dpi < 96 * 2) + if (iconsize < cxsmicon * 2) size = SHIL_SMALL; - else if (dpi < 96 * 3) + else if (iconsize < cxsmicon * 3) size = SHIL_LARGE; IImageList *pImageList = nullptr; if (FAILED(SHGetImageList(size, IID_IImageList, (void**)&pImageList))) return nullptr; + CComQIPtr pImageList2(pImageList); + if (pImageList2) + pImageList2->Resize(iconsize, iconsize); return IImageListToHIMAGELIST(pImageList); } } diff --git a/Externals/crystaledit/editlib/utils/DpiAware.h b/Externals/crystaledit/editlib/utils/DpiAware.h index 17bc5f1e7ac..58e72eb349c 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.h +++ b/Externals/crystaledit/editlib/utils/DpiAware.h @@ -99,7 +99,6 @@ namespace DpiAware int m_dpi = DPIOnInit; BEGIN_MESSAGE_MAP_INLINE(this_type, base_type) - ON_WM_CREATE() ON_WM_CREATE() ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) diff --git a/Src/Common/MDITabBar.cpp b/Src/Common/MDITabBar.cpp index 1014de5d909..5e7e19d3c2a 100644 --- a/Src/Common/MDITabBar.cpp +++ b/Src/Common/MDITabBar.cpp @@ -285,7 +285,7 @@ void CMDITabBar::UpdateTabs() LRESULT CMDITabBar::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) { - UpdateDpi(); + __super::OnDpiChangedBeforeParent(wParam, lParam); m_cxSMIcon = GetSystemMetrics(SM_CXSMICON); diff --git a/Src/Common/MessageBoxDialog.cpp b/Src/Common/MessageBoxDialog.cpp index 220d1097aca..013d8456582 100644 --- a/Src/Common/MessageBoxDialog.cpp +++ b/Src/Common/MessageBoxDialog.cpp @@ -801,9 +801,8 @@ HBRUSH CMessageBoxDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) LRESULT CMessageBoxDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) { - const int dpi = HIWORD(wParam); - UpdateDpi(); - UpdateResources(dpi); + __super::OnDpiChanged(wParam, lParam); + UpdateResources(m_dpi); Default(); if (!GetDlgItem(IDCHECKBOX)) return 0; diff --git a/Src/Common/SuperComboBox.cpp b/Src/Common/SuperComboBox.cpp index ca01cb40b0d..8135ae429fe 100644 --- a/Src/Common/SuperComboBox.cpp +++ b/Src/Common/SuperComboBox.cpp @@ -75,6 +75,7 @@ END_MESSAGE_MAP() void CSuperComboBox::PreSubclassWindow() { + UpdateDpi(); __super::PreSubclassWindow(); m_pDropHandler = new DropHandler(std::bind(&CSuperComboBox::OnDropFiles, this, std::placeholders::_1)); RegisterDragDrop(m_hWnd, m_pDropHandler); @@ -200,11 +201,17 @@ int CSuperComboBox::FindString(int nStartAfter, LPCTSTR lpszString) const */ bool CSuperComboBox::AttachSystemImageList() { + HIMAGELIST hImageList = nullptr; ASSERT(m_bComboBoxEx); - HIMAGELIST hImageList = DpiAware::LoadShellImageList(m_dpi); - if (hImageList==nullptr) - return false; - m_himlSystemMap.emplace(m_dpi, hImageList); + if (m_himlSystemMap.find(m_dpi) == m_himlSystemMap.end()) + { + hImageList = DpiAware::LoadShellImageList(m_dpi); + if (hImageList == nullptr) + return false; + m_himlSystemMap.emplace(m_dpi, hImageList); + } + else + hImageList = m_himlSystemMap[m_dpi]; SetImageList(CImageList::FromHandle(hImageList)); m_bHasImageList = true; return true; @@ -592,12 +599,14 @@ void CSuperComboBox::OnGetDispInfo(NMHDR *pNotifyStruct, LRESULT *pResult) LRESULT CSuperComboBox::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) { - UpdateDpi(); + __super::OnDpiChangedBeforeParent(wParam, lParam); if (m_bHasImageList) { if (m_himlSystemMap.find(m_dpi) == m_himlSystemMap.end()) { HIMAGELIST hImageList = DpiAware::LoadShellImageList(m_dpi); + if (!hImageList) + return 0; m_himlSystemMap.emplace(m_dpi, hImageList); } SetImageList(CImageList::FromHandle(m_himlSystemMap[m_dpi])); diff --git a/Src/Common/scbarcf.cpp b/Src/Common/scbarcf.cpp index 4d778bd0b38..2787757b4ac 100644 --- a/Src/Common/scbarcf.cpp +++ b/Src/Common/scbarcf.cpp @@ -67,7 +67,7 @@ END_MESSAGE_MAP() void CSizingControlBarCF::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler) { - baseCSizingControlBarCF::OnUpdateCmdUI(pTarget, bDisableIfNoHndler); + __super::OnUpdateCmdUI(pTarget, bDisableIfNoHndler); if (!HasGripper()) return; @@ -214,7 +214,7 @@ void CSizingControlBarCF::NcPaintGripper(CDC* pDC, CRect rcClient) LRESULT CSizingControlBarCF::OnSetText(WPARAM wParam, LPARAM lParam) { - LRESULT lResult = baseCSizingControlBarCF::OnSetText(wParam, lParam); + LRESULT lResult = __super::OnSetText(wParam, lParam); SendMessage(WM_NCPAINT); diff --git a/Src/Common/scbarg.cpp b/Src/Common/scbarg.cpp index 5ebbbe8af58..dd2224c7603 100644 --- a/Src/Common/scbarg.cpp +++ b/Src/Common/scbarg.cpp @@ -68,14 +68,14 @@ void CSizingControlBarG::OnNcLButtonUp(UINT nHitTest, CPoint point) if (nHitTest == HTCLOSE) m_pDockSite->ShowControlBar(this, FALSE, FALSE); // hide - baseCSizingControlBarG::OnNcLButtonUp(nHitTest, point); + __super::OnNcLButtonUp(nHitTest, point); } void CSizingControlBarG::NcCalcClient(LPRECT pRc, UINT nDockBarID) { CRect rcBar(pRc); // save the bar rect // subtract edges - baseCSizingControlBarG::NcCalcClient(pRc, nDockBarID); + __super::NcCalcClient(pRc, nDockBarID); if (!HasGripper()) return; @@ -144,7 +144,7 @@ NCHITTEST_RESULT CSizingControlBarG::OnNcHitTest(CPoint point) CRect rcBar; GetWindowRect(rcBar); - LRESULT nRet = baseCSizingControlBarG::OnNcHitTest(point); + LRESULT nRet = __super::OnNcHitTest(point); if (nRet != HTCLIENT) return nRet; diff --git a/Src/Common/sizecbar.cpp b/Src/Common/sizecbar.cpp index 569154a7f31..0d02d950497 100644 --- a/Src/Common/sizecbar.cpp +++ b/Src/Common/sizecbar.cpp @@ -152,7 +152,7 @@ void CSizingControlBar::EnableDocking(DWORD dwDockStyle) int CSizingControlBar::OnCreate(LPCREATESTRUCT lpCreateStruct) { - if (baseCSizingControlBar::OnCreate(lpCreateStruct) == -1) + if (__super::OnCreate(lpCreateStruct) == -1) return -1; // query SPI_GETDRAGFULLWINDOWS system parameter @@ -263,7 +263,7 @@ CSize CSizingControlBar::CalcDynamicLayout(int nLength, DWORD dwMode) if (nLength == -1) m_bParentSizing = true; - return baseCSizingControlBar::CalcDynamicLayout(nLength, dwMode); + return __super::CalcDynamicLayout(nLength, dwMode); } if (dwMode & LM_MRUWIDTH) return m_szFloat; @@ -318,7 +318,7 @@ void CSizingControlBar::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) // force non-client recalc if moved or resized lpwndpos->flags |= SWP_FRAMECHANGED; - baseCSizingControlBar::OnWindowPosChanging(lpwndpos); + __super::OnWindowPosChanging(lpwndpos); // find on which side are we docked m_nDockBarID = GetParent()->GetDlgCtrlID(); @@ -372,7 +372,7 @@ void CSizingControlBar::OnLButtonUp(UINT nFlags, CPoint point) if (m_bTracking) StopTracking(); - baseCSizingControlBar::OnLButtonUp(nFlags, point); + __super::OnLButtonUp(nFlags, point); } void CSizingControlBar::OnRButtonDown(UINT nFlags, CPoint point) @@ -380,7 +380,7 @@ void CSizingControlBar::OnRButtonDown(UINT nFlags, CPoint point) if (m_bTracking) StopTracking(); - baseCSizingControlBar::OnRButtonDown(nFlags, point); + __super::OnRButtonDown(nFlags, point); } void CSizingControlBar::OnMouseMove(UINT nFlags, CPoint point) @@ -393,7 +393,7 @@ void CSizingControlBar::OnMouseMove(UINT nFlags, CPoint point) OnTrackUpdateSize(ptScreen); } - baseCSizingControlBar::OnMouseMove(nFlags, point); + __super::OnMouseMove(nFlags, point); } void CSizingControlBar::OnCaptureChanged(CWnd *pWnd) @@ -401,7 +401,7 @@ void CSizingControlBar::OnCaptureChanged(CWnd *pWnd) if (m_bTracking && (pWnd != this)) StopTracking(); - baseCSizingControlBar::OnCaptureChanged(pWnd); + __super::OnCaptureChanged(pWnd); } void CSizingControlBar::OnNcCalcSize(BOOL bCalcValidRects, @@ -558,7 +558,7 @@ NCHITTEST_RESULT CSizingControlBar::OnNcHitTest(CPoint point) void CSizingControlBar::OnSettingChange(UINT uFlags, LPCTSTR lpszSection) { - baseCSizingControlBar::OnSettingChange(uFlags, lpszSection); + __super::OnSettingChange(uFlags, lpszSection); BOOL bDragShowContent = m_bDragShowContent = false; ::SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, diff --git a/Src/DirView.cpp b/Src/DirView.cpp index 9737dad6541..65fa4b9842d 100644 --- a/Src/DirView.cpp +++ b/Src/DirView.cpp @@ -2401,7 +2401,7 @@ bool CDirView::OnHeaderEndDrag(LPNMHEADER hdr, LRESULT* pResult) LRESULT CDirView::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) { int olddpi = m_dpi; - UpdateDpi(); + __super::OnDpiChangedBeforeParent(wParam, lParam); DpiAware::ListView_UpdateColumnWidths(m_hWnd, olddpi, m_dpi); return 0; } diff --git a/Src/EditorFilepathBar.cpp b/Src/EditorFilepathBar.cpp index a1ec7fafbd0..b11aee3cb0f 100644 --- a/Src/EditorFilepathBar.cpp +++ b/Src/EditorFilepathBar.cpp @@ -179,13 +179,14 @@ void CEditorFilePathBar::OnSetFocusEdit(UINT id) LRESULT CEditorFilePathBar::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) { - UpdateDpi(); - - m_font.DeleteObject(); + __super::OnDpiChangedBeforeParent(wParam, lParam); LOGFONT lfStatusFont; if (DpiAware::GetNonClientLogFont(lfStatusFont, offsetof(NONCLIENTMETRICS, lfStatusFont), GetDpi())) + { + m_font.DeleteObject(); m_font.CreateFontIndirect(&lfStatusFont); + } for (int pane = 0; pane < static_cast(std::size(m_Edit)); pane++) m_Edit[pane].SetFont(&m_font); diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index 00fc7f107d2..eb447dce3df 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -2579,12 +2579,12 @@ LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) Default(); - int dpi = HIWORD(wParam); + __super::OnDpiChanged(wParam, lParam); + RECT* const prcNew = (RECT*)lParam; - UpdateDpi(); - DpiAware::UpdateAfxDataSysMetrics(dpi); - BCMenu::ReopenTheme(dpi); + DpiAware::UpdateAfxDataSysMetrics(m_dpi); + BCMenu::ReopenTheme(m_dpi); m_lfDiff.lfHeight = MulDiv(m_lfDiff.lfHeight, m_dpi, olddpi); m_lfDir.lfHeight = MulDiv(m_lfDir.lfHeight, m_dpi, olddpi); diff --git a/Src/MergeStatusBar.cpp b/Src/MergeStatusBar.cpp index 5de4e641169..f425ff804a0 100644 --- a/Src/MergeStatusBar.cpp +++ b/Src/MergeStatusBar.cpp @@ -69,6 +69,7 @@ static UINT indicatorsBottom[] = }; BEGIN_MESSAGE_MAP(CMergeStatusBar, DpiAware::CDpiAwareWnd) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP() /** @@ -297,3 +298,19 @@ void CMergeStatusBar::MergeStatus::SetLineInfo(LPCTSTR szLine, int nColumn, Update(); } } + +LRESULT CMergeStatusBar::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) +{ + __super::OnDpiChangedBeforeParent(wParam, lParam); + + if (m_font.m_hObject == GetFont()->m_hObject) + m_font.DeleteObject(); + + LOGFONT lfStatusFont; + if (DpiAware::GetNonClientLogFont(lfStatusFont, offsetof(NONCLIENTMETRICS, lfStatusFont), GetDpi())) + m_font.CreateFontIndirect(&lfStatusFont); + + SetFont(&m_font); + return 0; +} + diff --git a/Src/MergeStatusBar.h b/Src/MergeStatusBar.h index dc88a506220..1af72def929 100644 --- a/Src/MergeStatusBar.h +++ b/Src/MergeStatusBar.h @@ -30,6 +30,10 @@ public : void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); protected: + + //{{AFX_MSG(CEditorFilePathBar) + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM, LPARAM); + //}}AFX_MSG DECLARE_MESSAGE_MAP(); private: @@ -69,4 +73,5 @@ public : }; friend class MergeStatus; // MergeStatus accesses status bar MergeStatus m_status[3]; + CFont m_font; }; From a36ba454dff0353a505f8258b73ad807a595eaa9 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sat, 12 Sep 2020 23:34:10 +0900 Subject: [PATCH 10/23] WIP: Add support for per-monitor DPI awareness (10) --- Externals/crystaledit/Sample/MainFrm.cpp | 28 ++++++++++++++++++- Externals/crystaledit/Sample/MainFrm.h | 2 ++ .../crystaledit/editlib/utils/DpiAware.cpp | 7 +++-- .../crystaledit/editlib/utils/DpiAware.h | 11 +++++--- Src/Common/BCMenu.cpp | 4 +-- Src/Common/MessageBoxDialog.cpp | 16 ++++++++--- Src/Common/sizecbar.cpp | 18 ++++++++++++ Src/Common/sizecbar.h | 1 + Src/MainFrm.cpp | 9 +++--- 9 files changed, 79 insertions(+), 17 deletions(-) diff --git a/Externals/crystaledit/Sample/MainFrm.cpp b/Externals/crystaledit/Sample/MainFrm.cpp index d74445b458b..c8da1fc1c02 100755 --- a/Externals/crystaledit/Sample/MainFrm.cpp +++ b/Externals/crystaledit/Sample/MainFrm.cpp @@ -6,6 +6,7 @@ #include "MainFrm.h" #include "ceditcmd.h" +#include #ifdef _DEBUG #define new DEBUG_NEW @@ -61,7 +62,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) return -1; if (!m_wndToolBar.Create(this) || - !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) + !LoadToolBar()) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create @@ -107,6 +108,11 @@ LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { __super::OnDpiChanged(wParam, lParam); DpiAware::UpdateAfxDataSysMetrics(GetDpi()); + LoadToolBar(); + const RECT* pRect = reinterpret_cast(lParam); + SetWindowPos(nullptr, pRect->left, pRect->top, + pRect->right - pRect->left, + pRect->bottom - pRect->top, SWP_NOZORDER | SWP_NOACTIVATE); Default(); return 0; } @@ -119,6 +125,26 @@ BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) return __super::PreCreateWindow(cs); } +BOOL CMainFrame::LoadToolBar() +{ + m_wndToolBar.LoadToolBar(IDR_MAINFRAME); + CToolBarCtrl& toolbarCtrl = m_wndToolBar.GetToolBarCtrl(); + int cx = 16; + int cy = 15; + m_imgListToolBar.DeleteImageList(); + m_imgListToolBar.Create(IDR_MAINFRAME, cx, 0, RGB(192, 192, 192)); + CComQIPtr pImageList2(reinterpret_cast(m_imgListToolBar.m_hImageList)); + if (pImageList2) + { + cx = 16 * m_dpi / 96; + cy = 15 * m_dpi / 96; + HRESULT hr = pImageList2->Resize(cx, cy); + } + toolbarCtrl.SetImageList(&m_imgListToolBar); + toolbarCtrl.SetButtonSize({ cx + 8, cy + 8 }); + return TRUE; +} + ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics diff --git a/Externals/crystaledit/Sample/MainFrm.h b/Externals/crystaledit/Sample/MainFrm.h index 85e78a2c138..8263585ac7e 100755 --- a/Externals/crystaledit/Sample/MainFrm.h +++ b/Externals/crystaledit/Sample/MainFrm.h @@ -31,10 +31,12 @@ class CMainFrame : public DpiAware::CDpiAwareWnd virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif + BOOL LoadToolBar(); protected: // control bar embedded members CStatusBar m_wndStatusBar; CToolBar m_wndToolBar; + CImageList m_imgListToolBar; // Generated message map functions protected: diff --git a/Externals/crystaledit/editlib/utils/DpiAware.cpp b/Externals/crystaledit/editlib/utils/DpiAware.cpp index 840f209f1b0..21b7eaef312 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.cpp +++ b/Externals/crystaledit/editlib/utils/DpiAware.cpp @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: BSL-1.0 +// Copyright (c) 2020 Takashi Sawanaka + #include "StdAfx.h" #include "DpiAware.h" #include @@ -16,7 +19,7 @@ namespace DpiAware bool DpiAwareSupport = []() { - DPIOnInit = MulDiv(96, ::GetSystemMetrics(SM_CXSMICON), 16); + DPIOnInit = MulDiv(USER_DEFAULT_SCREEN_DPI, ::GetSystemMetrics(SM_CXSMICON), 16); HMODULE hLibraryUser32 = GetModuleHandleW(L"user32.dll"); if (hLibraryUser32) { @@ -121,7 +124,7 @@ namespace DpiAware else { int cxsmicon = ::GetSystemMetrics(SM_CXSMICON); - int iconsize = MulDiv(16, dpi, 96); + int iconsize = MulDiv(16, dpi, USER_DEFAULT_SCREEN_DPI); int size = SHIL_EXTRALARGE; if (iconsize < cxsmicon * 2) size = SHIL_SMALL; diff --git a/Externals/crystaledit/editlib/utils/DpiAware.h b/Externals/crystaledit/editlib/utils/DpiAware.h index 58e72eb349c..d0827882f6c 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.h +++ b/Externals/crystaledit/editlib/utils/DpiAware.h @@ -1,5 +1,8 @@ #pragma once +// SPDX-License-Identifier: BSL-1.0 +// Copyright (c) 2020 Takashi Sawanaka + #include #include #include "mfc_templ_defines.h" @@ -9,13 +12,13 @@ #define WM_DPICHANGED_BEFOREPARENT 0x02E2 #define WM_DPICHANGED_AFTERPARENT 0x02E3 #endif +#ifndef USER_DEFAULT_SCREEN_DPI +#define USER_DEFAULT_SCREEN_DPI 96 +#endif namespace DpiAware { - struct NONCLIENTMETRICS6 : public NONCLIENTMETRICS - { - int iPaddedBorderWidth; - }; + struct NONCLIENTMETRICS6 : public NONCLIENTMETRICS { int iPaddedBorderWidth; }; using AdjustWindowRectExForDpiType = BOOL(__stdcall*)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi); using GetDpiForWindowType = UINT(__stdcall*)(HWND hwnd); diff --git a/Src/Common/BCMenu.cpp b/Src/Common/BCMenu.cpp index 89b204e6a22..068b222fe61 100644 --- a/Src/Common/BCMenu.cpp +++ b/Src/Common/BCMenu.cpp @@ -779,11 +779,11 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) const int BCMENU_PAD=4; if (m_hTheme == nullptr) - lpMIS->itemWidth = MulDiv(m_iconX+BCMENU_PAD+8, dpi, 96) +t.cx; + lpMIS->itemWidth = MulDiv(m_iconX+BCMENU_PAD+8, dpi, USER_DEFAULT_SCREEN_DPI) +t.cx; else lpMIS->itemWidth = m_gutterWidth+m_textBorder+t.cx+m_arrowWidth; int temp = DpiAware::GetSystemMetricsForDpi(SM_CYMENU, dpi); - int temp2 = MulDiv(m_iconY + BCMENU_PAD, dpi, 96); + int temp2 = MulDiv(m_iconY + BCMENU_PAD, dpi, USER_DEFAULT_SCREEN_DPI); lpMIS->itemHeight = temp>temp2 ? temp : temp2; } } diff --git a/Src/Common/MessageBoxDialog.cpp b/Src/Common/MessageBoxDialog.cpp index 013d8456582..b25f3bbc6f0 100644 --- a/Src/Common/MessageBoxDialog.cpp +++ b/Src/Common/MessageBoxDialog.cpp @@ -811,6 +811,7 @@ LRESULT CMessageBoxDialog::OnDpiChanged(WPARAM wParam, LPARAM lParam) GetDlgItem(IDCHECKBOX)->SetFont(&m_font); m_stcMessage.SetFont(&m_fontMainInstruction); Invalidate(); + m_sDialogUnit = {}; return 0; } @@ -1178,38 +1179,45 @@ void CMessageBoxDialog::ParseStyle ( ) if ( ( m_nStyle & MB_ICONMASK ) && ( m_hIcon == nullptr ) ) { // Switch the icon. + LPTSTR icon = nullptr; switch ( m_nStyle & MB_ICONMASK ) { case MB_ICONEXCLAMATION: // Load the icon with the exclamation mark. - m_hIcon = AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION); + icon = IDI_EXCLAMATION; break; case MB_ICONHAND: // Load the icon with the error symbol. - m_hIcon = AfxGetApp()->LoadStandardIcon(IDI_HAND); + icon = IDI_HAND; break; case MB_ICONQUESTION: // Load the icon with the question mark. - m_hIcon = AfxGetApp()->LoadStandardIcon(IDI_QUESTION); + icon = IDI_QUESTION; break; case MB_ICONASTERISK: // Load the icon with the information symbol. - m_hIcon = AfxGetApp()->LoadStandardIcon(IDI_ASTERISK); + icon = IDI_ASTERISK; break; } + if (icon) + { + const int cx = GetSystemMetrics(SM_CXICON); + const int cy = GetSystemMetrics(SM_CYICON); + DpiAware::LoadIconWithScaleDown(nullptr, icon, cx, cy, &m_hIcon); + } } } diff --git a/Src/Common/sizecbar.cpp b/Src/Common/sizecbar.cpp index 0d02d950497..ee18d35ca46 100644 --- a/Src/Common/sizecbar.cpp +++ b/Src/Common/sizecbar.cpp @@ -96,6 +96,7 @@ BEGIN_MESSAGE_MAP(CSizingControlBar, DpiAware::CDpiAwareWndcx = MulDiv(size->cx, m_dpi, olddpi); + size->cy = MulDiv(size->cy, m_dpi, olddpi); + } + + m_pDockSite->DelayRecalcLayout(); + + return 0; +} + #ifdef _SCB_REPLACE_MINIFRAME #ifndef _SCB_MINIFRAME_CAPTION ///////////////////////////////////////////////////////////////////////////// diff --git a/Src/Common/sizecbar.h b/Src/Common/sizecbar.h index d43217bcacc..87163c3dd60 100644 --- a/Src/Common/sizecbar.h +++ b/Src/Common/sizecbar.h @@ -179,6 +179,7 @@ class CSizingControlBar : public DpiAware::CDpiAwareWnd afx_msg void OnSize(UINT nType, int cx, int cy); //}}AFX_MSG afx_msg LRESULT OnSetText(WPARAM wParam, LPARAM lParam); + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index eb447dce3df..8ce78ba9c0c 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -2577,12 +2577,8 @@ LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { int olddpi = m_dpi; - Default(); - __super::OnDpiChanged(wParam, lParam); - RECT* const prcNew = (RECT*)lParam; - DpiAware::UpdateAfxDataSysMetrics(m_dpi); BCMenu::ReopenTheme(m_dpi); @@ -2592,6 +2588,11 @@ LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) UpdateFont(FRAME_FILE); UpdateFont(FRAME_FOLDER); + const RECT* pRect = reinterpret_cast(lParam); + SetWindowPos(nullptr, pRect->left, pRect->top, + pRect->right - pRect->left, + pRect->bottom - pRect->top, SWP_NOZORDER | SWP_NOACTIVATE); + return 0; } From 6e972450abd2d1b97c4e2bf92504e41050608eb9 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Wed, 16 Sep 2020 23:32:33 +0900 Subject: [PATCH 11/23] WIP: Add support for per-monitor DPI awareness (11) --- Externals/crystaledit/Sample/MainFrm.cpp | 4 +- .../crystaledit/editlib/utils/DpiAware.cpp | 14 ++ .../crystaledit/editlib/utils/DpiAware.h | 77 ++++++++++- Src/Common/CMoveConstraint.cpp | 46 +++++-- Src/Common/CMoveConstraint.h | 2 + Src/Common/MDITabBar.cpp | 2 +- Src/MainFrm.cpp | 130 ++++++++++++++---- Src/Merge.cpp | 2 + Src/Merge.h | 1 + Src/Merge2.rc | 2 - Src/MergeDoc.cpp | 4 +- Src/MergeEditView.cpp | 2 +- Src/OpenView.cpp | 16 +++ Src/OpenView.h | 1 + Src/TrDialogs.cpp | 6 +- Src/TrDialogs.h | 50 +++---- Src/res/ToolbarEnabledMask.bmp | Bin 722 -> 0 bytes Src/res/ToolbarEnabledMask32.bmp | Bin 2790 -> 0 bytes Src/resource.h | 2 - 19 files changed, 284 insertions(+), 77 deletions(-) delete mode 100644 Src/res/ToolbarEnabledMask.bmp delete mode 100644 Src/res/ToolbarEnabledMask32.bmp diff --git a/Externals/crystaledit/Sample/MainFrm.cpp b/Externals/crystaledit/Sample/MainFrm.cpp index c8da1fc1c02..e455fe5a269 100755 --- a/Externals/crystaledit/Sample/MainFrm.cpp +++ b/Externals/crystaledit/Sample/MainFrm.cpp @@ -136,8 +136,8 @@ BOOL CMainFrame::LoadToolBar() CComQIPtr pImageList2(reinterpret_cast(m_imgListToolBar.m_hImageList)); if (pImageList2) { - cx = 16 * m_dpi / 96; - cy = 15 * m_dpi / 96; + cx = MulDiv(16, m_dpi, USER_DEFAULT_SCREEN_DPI); + cy = MulDiv(15, m_dpi, USER_DEFAULT_SCREEN_DPI); HRESULT hr = pImageList2->Resize(cx, cy); } toolbarCtrl.SetImageList(&m_imgListToolBar); diff --git a/Externals/crystaledit/editlib/utils/DpiAware.cpp b/Externals/crystaledit/editlib/utils/DpiAware.cpp index 21b7eaef312..f18a54404e2 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.cpp +++ b/Externals/crystaledit/editlib/utils/DpiAware.cpp @@ -1,5 +1,9 @@ // SPDX-License-Identifier: BSL-1.0 // Copyright (c) 2020 Takashi Sawanaka +// +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include "StdAfx.h" #include "DpiAware.h" @@ -43,6 +47,8 @@ namespace DpiAware { return AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle); }; if (!GetDpiForWindow) GetDpiForWindow = [](HWND hwnd) -> UINT { return CClientDC(CWnd::FromHandle(hwnd)).GetDeviceCaps(LOGPIXELSX); }; + if (!SystemParametersInfoForDpi) + SystemParametersInfoForDpi = [](UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi) -> BOOL { return SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni); }; if (!GetSystemMetricsForDpi) GetSystemMetricsForDpi = [](int nIndex, UINT dpi) -> int { return GetSystemMetrics(nIndex); }; if (!LoadIconWithScaleDown) @@ -87,6 +93,12 @@ namespace DpiAware afxData.cyPixelsPerInch = dpi; } + void TreeView_UpdateIndent(HWND hwnd, int olddpi, int newdpi) + { + int indent = TreeView_GetIndent(hwnd); + TreeView_SetIndent(hwnd, MulDiv(indent, newdpi, olddpi)); + } + void ListView_UpdateColumnWidths(HWND hwnd, int olddpi, int newdpi) { HWND hwndHeader = ListView_GetHeader(hwnd); @@ -108,6 +120,8 @@ namespace DpiAware GetClassName(hwnd, name, sizeof(name) / sizeof(TCHAR)); if (_tcsicmp(name, _T("SysListView32")) == 0 && pdpis->hwndParent == GetParent(hwnd)) ListView_UpdateColumnWidths(hwnd, pdpis->olddpi, pdpis->newdpi); + else if (_tcsicmp(name, _T("SysTreeView32")) == 0 && pdpis->hwndParent == GetParent(hwnd)) + TreeView_UpdateIndent(hwnd, pdpis->olddpi, pdpis->newdpi); return TRUE; }; EnumChildWindows(hwnd, enumfunc, (LPARAM)&dpis); diff --git a/Externals/crystaledit/editlib/utils/DpiAware.h b/Externals/crystaledit/editlib/utils/DpiAware.h index d0827882f6c..639b692637c 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.h +++ b/Externals/crystaledit/editlib/utils/DpiAware.h @@ -1,7 +1,11 @@ -#pragma once - // SPDX-License-Identifier: BSL-1.0 // Copyright (c) 2020 Takashi Sawanaka +// +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#pragma once #include #include @@ -43,6 +47,16 @@ namespace DpiAware void ListView_UpdateColumnWidths(HWND hwnd, int olddpi, int newdpi); void Dialog_UpdateControlInnerWidths(HWND hwnd, int olddpi, int newdpi); HIMAGELIST LoadShellImageList(int dpi); + template + T MulDivRect(const T* p, int nNumerator, int nDenominator) + { + T rc; + rc.left = MulDiv(p->left, nNumerator, nDenominator); + rc.top = MulDiv(p->top, nNumerator, nDenominator); + rc.right = MulDiv(p->right, nNumerator, nDenominator); + rc.bottom = MulDiv(p->bottom, nNumerator, nDenominator); + return rc; + } template class CDpiAwareWnd : public Base @@ -89,6 +103,7 @@ namespace DpiAware afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam) { + int olddpi = m_dpi; UpdateDpi(); return 0; } @@ -108,5 +123,63 @@ namespace DpiAware END_MESSAGE_MAP_INLINE() }; + template + class CDpiAwareDialog : public CDpiAwareWnd + { + public: + using this_type = CDpiAwareDialog; + using base_type = CDpiAwareWnd; + using CDpiAwareWnd::CDpiAwareWnd; + + CRect m_rcInit; + + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct) + { + GetClientRect(m_rcInit); + return __super::OnCreate(lpCreateStruct); + } + + afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam) + { + int olddpi = m_dpi; + bool bDynamicLayoutEnabled = IsDynamicLayoutEnabled(); + CSize sizeMin; + if (bDynamicLayoutEnabled) + { +// sizeMin = GetDynamicLayout()->GetMinSize(); +// CRect rc = m_rcInit; +// AdjustWindowRectEx(&rc, GetStyle(), false, GetExStyle()); +// SetWindowPos(nullptr, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER); +// GetDynamicLayout()->Adjust(); + EnableDynamicLayout(FALSE); + } + UpdateDpi(); + Default(); + /* + if (bDynamicLayoutEnabled) + { + m_rcInit = DpiAware::MulDivRect(&m_rcInit, m_dpi, olddpi); + sizeMin.cx = MulDiv(sizeMin.cx, m_dpi, olddpi); + sizeMin.cy = MulDiv(sizeMin.cy, m_dpi, olddpi); + CRect rc = m_rcInit; + AdjustWindowRectEx(&rc, GetStyle(), false, GetExStyle()); + SetWindowPos(nullptr, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER); + LoadDynamicLayoutResource(m_lpszTemplateName); + } + */ + return 0; + } + + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) + { + return OnDpiChanged(wParam, lParam); + } + + BEGIN_MESSAGE_MAP_INLINE(this_type, base_type) + ON_WM_CREATE() + ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) + END_MESSAGE_MAP_INLINE() + }; } diff --git a/Src/Common/CMoveConstraint.cpp b/Src/Common/CMoveConstraint.cpp index 18f59914615..1611e2e1af0 100644 --- a/Src/Common/CMoveConstraint.cpp +++ b/Src/Common/CMoveConstraint.cpp @@ -17,6 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include "StdAfx.h" #include "CMoveConstraint.h" +#include "utils/DpiAware.h" #include // MFC template collection classes #include // needed for CFormView @@ -39,8 +40,9 @@ static RECT getGripRect(HWND hwnd) { RECT rc; GetClientRect(hwnd, &rc); - rc.left = rc.right - GetSystemMetrics(SM_CXVSCROLL); - rc.top = rc.bottom - GetSystemMetrics(SM_CYHSCROLL); + const int dpi = DpiAware::GetDpiForWindow(hwnd); + rc.left = rc.right - DpiAware::GetSystemMetricsForDpi(SM_CXVSCROLL, dpi); + rc.top = rc.bottom - DpiAware::GetSystemMetricsForDpi(SM_CYHSCROLL, dpi); return rc; } @@ -89,6 +91,7 @@ CMoveConstraint::InitializeCurrentSize(HWND hwndDlg) if (!IsWindow(hwndDlg)) return false; m_hwndDlg = hwndDlg; + m_dpi = DpiAware::GetDpiForWindow(hwndDlg); GrabCurrentDimensionsAsOriginal(hwndDlg); return true; @@ -132,6 +135,7 @@ CMoveConstraint::InitializeOriginalSize(HWND hwndDlg) { ASSERT(hwndDlg != nullptr && m_hwndDlg == nullptr); m_hwndDlg = hwndDlg; + m_dpi = DpiAware::GetDpiForWindow(hwndDlg); return m_nOrigX != 0; // if 0, we didn't get WM_SIZE so we don't know the original size } @@ -246,6 +250,7 @@ CMoveConstraint::ClearMostData() m_nMaxX=0; m_nMaxY=0; m_nDelayed=0; + m_dpi=0; // this specifically does NOT touch m_bSubclassed, as a subclass may still be in use m_pFormView=nullptr; m_nOrigScrollX=0; @@ -651,12 +656,37 @@ CMoveConstraint::WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, L } else if (msg==WM_NOTIFY && TTN_NEEDTEXT==((NMHDR*)lParam)->code) { if (OnTtnNeedText((TOOLTIPTEXT*)lParam, plresult)) return true; -/* } else if (WM_DPICHANGED == msg) { - const int dpi = HIWORD(wParam); - const RECT *prcNew = reinterpret_cast(lParam); - m_nMaxX = prcNew->right - prcNew->left; - m_nMaxY = prcNew->bottom - prcNew->top; - return true;*/ + } else if (WM_DPICHANGED == msg) { + const int olddpi = m_dpi; + m_dpi = HIWORD(wParam); + const int oldnonclientsx = m_nOrigX - m_rectDlgOriginal.Width(); + const int oldnonclientsy = m_nOrigY - m_rectDlgOriginal.Height(); + CRect rc, rcClient; + GetWindowRect(m_hwndDlg, &rc); + GetClientRect(m_hwndDlg, &rcClient); + const int newnonclientsx = rc.Width() - rcClient.Width(); + const int newnonclientsy = rc.Height() - rcClient.Height(); + const RECT* pRect = reinterpret_cast(lParam); + m_rectDlgOriginal = DpiAware::MulDivRect(&m_rectDlgOriginal, m_dpi, olddpi); + for (auto& pval : { &m_nMaxX, &m_nMinX, &m_nOrigX }) + { + if (*pval) + *pval = MulDiv(*pval - oldnonclientsx, m_dpi, olddpi) + newnonclientsx; + } + for (auto& pval : { &m_nMaxY, &m_nMinY, &m_nOrigY }) + { + if (*pval) + *pval = MulDiv(*pval - oldnonclientsy, m_dpi, olddpi) + newnonclientsy; + } + ConstraintList & constraintList = m_ConstraintList; + for (POSITION pos=constraintList.GetHeadPosition(); pos != nullptr; constraintList.GetNext(pos)) + { + Constraint & constraint = constraintList.GetAt(pos); + for (auto& pval : + { &constraint.m_rectChildOriginal.left,&constraint.m_rectChildOriginal.top, + &constraint.m_rectChildOriginal.right, &constraint.m_rectChildOriginal.bottom }) + *pval = MulDiv(*pval, m_dpi, olddpi); + } } return false; diff --git a/Src/Common/CMoveConstraint.h b/Src/Common/CMoveConstraint.h index ec442bb7569..7e4ad93916d 100644 --- a/Src/Common/CMoveConstraint.h +++ b/Src/Common/CMoveConstraint.h @@ -213,6 +213,7 @@ class CMoveConstraint private: HWND m_hwndDlg; // parent of controls - could be FormView or PropertyPage or whatever as well CRect m_rectDlgOriginal; + CRect m_rectDlgOriginalIncludingNonClient; int m_nOrigX; int m_nOrigY; EGRIP m_nGrip; @@ -222,6 +223,7 @@ class CMoveConstraint int m_nMaxX; int m_nMaxY; int m_nDelayed; // CWnds without HWND + int m_dpi; bool m_bSubclassed; WNDPROC m_oldWndProc; // formview stuff diff --git a/Src/Common/MDITabBar.cpp b/Src/Common/MDITabBar.cpp index 5e7e19d3c2a..1b0bdd6556e 100644 --- a/Src/Common/MDITabBar.cpp +++ b/Src/Common/MDITabBar.cpp @@ -291,7 +291,7 @@ LRESULT CMDITabBar::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) TabCtrl_SetPadding(m_hWnd, m_cxSMIcon, 4); - LOGFONT lfMenuFont; + LOGFONT lfMenuFont{}; DpiAware::GetNonClientLogFont(lfMenuFont, offsetof(NONCLIENTMETRICS, lfMenuFont), m_dpi); m_font.DeleteObject(); m_font.CreateFontIndirect(&lfMenuFont); diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index 8ce78ba9c0c..b7a63cf5c60 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -69,7 +69,7 @@ using boost::end; #define new DEBUG_NEW #endif -static void LoadToolbarImageList(int imageWidth, UINT nIDResource, UINT nIDResourceMask, bool bGrayscale, CImageList& ImgList); +static void LoadToolbarImageList(int orgImageWidth, int newImageHeight, UINT nIDResource, bool bGrayscale, CImageList& ImgList); static CPtrList &GetDocList(CMultiDocTemplate *pTemplate); template DocClass * GetMergeDocForDiff(CMultiDocTemplate *pTemplate, CDirDoc *pDirDoc, int nFiles, bool bMakeVisible = true); @@ -2023,22 +2023,22 @@ BOOL CMainFrame::CreateToolbar() /** @brief Load toolbar images from the resource. */ void CMainFrame::LoadToolbarImages() { - const int toolbarSize = 16 << GetOptionsMgr()->GetInt(OPT_TOOLBAR_SIZE); + const int toolbarNewImgSize = MulDiv(16, m_dpi, USER_DEFAULT_SCREEN_DPI) << GetOptionsMgr()->GetInt(OPT_TOOLBAR_SIZE); + const int toolbarOrgImgSize = toolbarNewImgSize == 16 ? 16 : 32; CToolBarCtrl& BarCtrl = m_wndToolBar.GetToolBarCtrl(); m_ToolbarImages[TOOLBAR_IMAGES_ENABLED].DeleteImageList(); m_ToolbarImages[TOOLBAR_IMAGES_DISABLED].DeleteImageList(); CSize sizeButton(0, 0); - LoadToolbarImageList(toolbarSize, - toolbarSize <= 16 ? IDB_TOOLBAR_ENABLED : IDB_TOOLBAR_ENABLED32, - toolbarSize <= 16 ? IDB_TOOLBAR_ENABLED_MASK : IDB_TOOLBAR_ENABLED_MASK32, + LoadToolbarImageList(toolbarOrgImgSize, toolbarNewImgSize, + toolbarOrgImgSize <= 16 ? IDB_TOOLBAR_ENABLED : IDB_TOOLBAR_ENABLED32, false, m_ToolbarImages[TOOLBAR_IMAGES_ENABLED]); - LoadToolbarImageList(toolbarSize, - toolbarSize <= 16 ? IDB_TOOLBAR_ENABLED : IDB_TOOLBAR_ENABLED32, - toolbarSize <= 16 ? IDB_TOOLBAR_ENABLED_MASK : IDB_TOOLBAR_ENABLED_MASK32, + LoadToolbarImageList(toolbarOrgImgSize, toolbarNewImgSize, + toolbarOrgImgSize <= 16 ? IDB_TOOLBAR_ENABLED : IDB_TOOLBAR_ENABLED32, true, m_ToolbarImages[TOOLBAR_IMAGES_DISABLED]); - sizeButton = CSize(toolbarSize + 8, toolbarSize + 8); + + sizeButton = CSize(toolbarNewImgSize + 8, toolbarNewImgSize + 8); BarCtrl.SetButtonSize(sizeButton); BarCtrl.SetImageList(&m_ToolbarImages[TOOLBAR_IMAGES_ENABLED]); @@ -2055,29 +2055,111 @@ void CMainFrame::LoadToolbarImages() /** - * @brief Load a transparent 24-bit color image list. + * @brief Load a transparent 32-bit color image list. */ -static void LoadHiColImageList(UINT nIDResource, UINT nIDResourceMask, int nWidth, int nHeight, int nCount, bool bGrayscale, CImageList& ImgList) +static void LoadHiColImageList(UINT nIDResource, int nWidth, int nHeight, int nNewWidth, int nNewHeight, int nCount, bool bGrayscale, CImageList& ImgList) { - CBitmap bm, bmMask; - bm.Attach(LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(nIDResource), IMAGE_BITMAP, nWidth * nCount, nHeight, LR_DEFAULTCOLOR)); - bmMask.Attach(LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(nIDResourceMask), IMAGE_BITMAP, nWidth * nCount, nHeight, LR_MONOCHROME)); - if (bGrayscale) - GrayScale(&bm); - VERIFY(ImgList.Create(nWidth, nHeight, ILC_COLORDDB|ILC_MASK, nCount, 0)); - int nIndex = ImgList.Add(&bm, &bmMask); - ASSERT(-1 != nIndex); + auto convert24bitImageTo32bit = [](int width, int height, bool grayscale, const BYTE* src, BYTE* dst) + { + for (int y = 0; y < height; ++y) + { + const BYTE* pSrc = src + y * ((width * 3 * 4 + 3) / 4); + BYTE* pDst = dst + (height - 1 - y) * ((width * 4 * 4 + 3) / 4); + if (!grayscale) + { + for (int x = 0; x < width; ++x) + { + if (pSrc[x * 3] == 0xff && pSrc[x * 3 + 1] == 0 && pSrc[x * 3 + 2] == 0xff) // rgb(0xff, 0, 0xff) == mask color + { + pDst[x * 4] = 0; + pDst[x * 4 + 1] = 0; + pDst[x * 4 + 2] = 0; + pDst[x * 4 + 3] = 0; + } + else + { + pDst[x * 4 + 0] = pSrc[x * 3 + 0]; + pDst[x * 4 + 1] = pSrc[x * 3 + 1]; + pDst[x * 4 + 2] = pSrc[x * 3 + 2]; + pDst[x * 4 + 3] = 0xff; + } + } + } + else + { + for (int x = 0; x < width; ++x) + { + if (pSrc[x * 3] == 0xff && pSrc[x * 3 + 1] == 0 && pSrc[x * 3 + 2] == 0xff) // rgb(0xff, 0, 0xff) == mask color + { + pDst[x * 4] = 0; + pDst[x * 4 + 1] = 0; + pDst[x * 4 + 2] = 0; + pDst[x * 4 + 3] = 0; + } + else + { + const BYTE b = pSrc[x * 3]; + const BYTE g = pSrc[x * 3 + 1]; + const BYTE r = pSrc[x * 3 + 2]; + const BYTE gray = static_cast( + (static_cast(0.114 * 256) * (((255 - b) >> 1) + b) + + static_cast(0.587 * 256) * (((255 - g) >> 1) + g) + + static_cast(0.299 * 256) * (((255 - r) >> 1) + r)) >> 8); + pDst[x * 4 + 0] = gray; + pDst[x * 4 + 1] = gray; + pDst[x * 4 + 2] = gray; + pDst[x * 4 + 3] = 0xff; + } + } + } + } + }; + + auto createImageListFromBitmap = [](CImageList& imgList, Gdiplus::Bitmap& bitmap, int width, int height, int count) + { + CBitmap bm; + HBITMAP hBitmap; + bitmap.GetHBITMAP(Gdiplus::Color::Transparent, &hBitmap); + bm.Attach(hBitmap); + + VERIFY(imgList.Create(width, height, ILC_COLOR32, count, 0)); + int nIndex = imgList.Add(&bm, nullptr); + ASSERT(-1 != nIndex); + }; + + ATL::CImage img; + img.Attach((HBITMAP)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(nIDResource), IMAGE_BITMAP, nWidth * nCount, nHeight, LR_CREATEDIBSECTION), ATL::CImage::DIBOR_TOPDOWN); + const int stride = (nWidth * nCount * 4 * 4 + 3) / 4; + std::vector buf(stride * nHeight); + convert24bitImageTo32bit(nWidth * nCount, nHeight, bGrayscale, reinterpret_cast(img.GetBits()), buf.data()); + + if (nWidth != nNewWidth && nHeight != nNewHeight) + { + Gdiplus::Bitmap bitmapSrc(nWidth * nCount, nHeight, stride, PixelFormat32bppPARGB, buf.data()); + Gdiplus::Bitmap bitmapDst(nNewWidth * nCount, nNewHeight, PixelFormat32bppPARGB); + Gdiplus::Graphics dcDst(&bitmapDst); + dcDst.SetInterpolationMode(Gdiplus::InterpolationMode::InterpolationModeHighQualityBicubic); + dcDst.DrawImage(&bitmapSrc, 0, 0, nNewWidth * nCount, nNewHeight); + + createImageListFromBitmap(ImgList, bitmapDst, nNewWidth, nNewHeight, nCount); + } + else + { + Gdiplus::Bitmap bitmapDst(nWidth * nCount, nHeight, stride, PixelFormat32bppPARGB, buf.data()); + + createImageListFromBitmap(ImgList, bitmapDst, nNewWidth, nNewHeight, nCount); + } } /** * @brief Load toolbar image list. */ -static void LoadToolbarImageList(int imageWidth, UINT nIDResource, UINT nIDResourceMask, bool bGrayscale, - CImageList& ImgList) +static void LoadToolbarImageList(int orgImageWidth, int newImageWidth, UINT nIDResource, bool bGrayscale, CImageList& ImgList) { const int ImageCount = 22; - const int imageHeight = imageWidth - 1; - LoadHiColImageList(nIDResource, nIDResourceMask, imageWidth, imageHeight, ImageCount, bGrayscale, ImgList); + const int orgImageHeight = orgImageWidth - 1; + const int newImageHeight = newImageWidth - 1; + LoadHiColImageList(nIDResource, orgImageWidth, orgImageHeight, newImageWidth, newImageHeight, ImageCount, bGrayscale, ImgList); } /** @@ -2588,6 +2670,8 @@ LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) UpdateFont(FRAME_FILE); UpdateFont(FRAME_FOLDER); + LoadToolbarImages(); + const RECT* pRect = reinterpret_cast(lParam); SetWindowPos(nullptr, pRect->left, pRect->top, pRect->right - pRect->left, diff --git a/Src/Merge.cpp b/Src/Merge.cpp index 43db194e0fa..d8f468d2ec1 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -150,6 +150,8 @@ BOOL CMergeApp::InitInstance() InitCommonControls(); // initialize common control library CWinApp::InitInstance(); // call parent class method + m_imageForInitializingGdiplus.Load((IStream*)nullptr); + // Runtime switch so programmer may set this in interactive debugger int dbgmem = 0; if (dbgmem) diff --git a/Src/Merge.h b/Src/Merge.h index 69a3a6f0e57..3d10e7fef67 100644 --- a/Src/Merge.h +++ b/Src/Merge.h @@ -172,6 +172,7 @@ class CMergeApp : public CWinApp LONG m_nActiveOperations; /**< Active operations count. */ bool m_bMergingMode; /**< Merging or Edit mode */ mutable std::map m_mapFontGUI; + ATL::CImage m_imageForInitializingGdiplus; }; extern CMergeApp theApp; diff --git a/Src/Merge2.rc b/Src/Merge2.rc index 6469eb8a7fb..01a3e6e41db 100644 --- a/Src/Merge2.rc +++ b/Src/Merge2.rc @@ -113,8 +113,6 @@ IDR_MARGIN_ICONS_PNG IMAGE "res\\mg_icons.png" IDB_TOOLBAR_ENABLED8BIT BITMAP "res\\ToolbarEnabled8bit.bmp" IDB_TOOLBAR_ENABLED BITMAP "res\\ToolbarEnabled.bmp" IDB_TOOLBAR_ENABLED32 BITMAP "res\\ToolbarEnabled32.bmp" -IDB_TOOLBAR_ENABLED_MASK BITMAP "res\\ToolbarEnabledMask.bmp" -IDB_TOOLBAR_ENABLED_MASK32 BITMAP "res\\ToolbarEnabledMask32.bmp" IDB_EDIT_COPY BITMAP "res\\copy.bmp" IDB_EDIT_CUT BITMAP "res\\cut.bmp" IDB_EDIT_PASTE BITMAP "res\\paste.bmp" diff --git a/Src/MergeDoc.cpp b/Src/MergeDoc.cpp index d657dba3cec..2791bf492dc 100644 --- a/Src/MergeDoc.cpp +++ b/Src/MergeDoc.cpp @@ -3362,10 +3362,8 @@ bool CMergeDoc::GenerateReport(const String& sFileName) const { // calculate HTML font size LOGFONT lf; - CDC dc; - dc.CreateDC(_T("DISPLAY"), nullptr, nullptr, nullptr); m_pView[0][0]->GetFont(lf); - int nFontSize = -MulDiv (lf.lfHeight, 72, dc.GetDeviceCaps (LOGPIXELSY)); + int nFontSize = -MulDiv (lf.lfHeight, 72, m_pView[0][0]->m_dpi); // create HTML report UniStdioFile file; diff --git a/Src/MergeEditView.cpp b/Src/MergeEditView.cpp index ec4e18dd600..c61d6c03d32 100644 --- a/Src/MergeEditView.cpp +++ b/Src/MergeEditView.cpp @@ -4096,7 +4096,7 @@ void CMergeEditView::ZoomText(short amount) LOGFONT lf = { 0 }; GetFont(lf); - const int nLogPixelsY = CClientDC(this).GetDeviceCaps(LOGPIXELSY); + const int nLogPixelsY = m_dpi; int nPointSize = -MulDiv(lf.lfHeight, 72, nLogPixelsY); if ( amount == 0) diff --git a/Src/OpenView.cpp b/Src/OpenView.cpp index ee1e77486ca..fe1857ab08b 100644 --- a/Src/OpenView.cpp +++ b/Src/OpenView.cpp @@ -91,6 +91,7 @@ BEGIN_MESSAGE_MAP(COpenView, DpiAware::CDpiAwareWnd) ON_COMMAND(ID_EDIT_UNDO, OnEditAction) ON_COMMAND(ID_EDIT_SELECT_ALL, (OnEditAction)) ON_MESSAGE(WM_USER + 1, OnUpdateStatus) + ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) ON_WM_PAINT() ON_WM_LBUTTONUP() ON_WM_MOUSEMOVE() @@ -1121,6 +1122,21 @@ LRESULT COpenView::OnUpdateStatus(WPARAM wParam, LPARAM lParam) return 0; } +LRESULT COpenView::OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) +{ + const int olddpi = m_dpi; + CRect rc; + GetWindowRect(&rc); + __super::OnDpiChangedBeforeParent(wParam, lParam); + rc.left = MulDiv(rc.left, m_dpi, olddpi); + rc.right = MulDiv(rc.right, m_dpi, olddpi); + rc.top = MulDiv(rc.top, m_dpi, olddpi); + rc.bottom = MulDiv(rc.bottom, m_dpi, olddpi); + DefWindowProc(WM_DPICHANGED, (WPARAM)m_dpi, (LPARAM)&rc); + SetWindowPos(nullptr, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER); + return 0; +} + /** * @brief Sets the path status text. * The open dialog shows a status text of selected paths. This function diff --git a/Src/OpenView.h b/Src/OpenView.h index f7b3564612e..a5c2069d80b 100644 --- a/Src/OpenView.h +++ b/Src/OpenView.h @@ -133,6 +133,7 @@ virtual BOOL PreCreateWindow(CREATESTRUCT& cs); afx_msg void OnHelp(); afx_msg void OnDropFiles(const std::vector& files); afx_msg LRESULT OnUpdateStatus(WPARAM wParam, LPARAM lParam); + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam); afx_msg void OnPaint(); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point); diff --git a/Src/TrDialogs.cpp b/Src/TrDialogs.cpp index 76b2f14a7db..8385b316d75 100644 --- a/Src/TrDialogs.cpp +++ b/Src/TrDialogs.cpp @@ -6,15 +6,15 @@ IMPLEMENT_DYNAMIC(CTrDialog, CDialog) IMPLEMENT_DYNAMIC(CTrPropertyPage, CPropertyPage) IMPLEMENT_DYNAMIC(CTrDialogBar, CDialogBar) -BEGIN_MESSAGE_MAP(CTrDialog, DpiAware::CDpiAwareWnd) +BEGIN_MESSAGE_MAP(CTrDialog, DpiAware::CDpiAwareDialog) ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) END_MESSAGE_MAP() -BEGIN_MESSAGE_MAP(CTrPropertyPage, DpiAware::CDpiAwareWnd) +BEGIN_MESSAGE_MAP(CTrPropertyPage, DpiAware::CDpiAwareDialog) ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP() -BEGIN_MESSAGE_MAP(CTrDialogBar, DpiAware::CDpiAwareWnd) +BEGIN_MESSAGE_MAP(CTrDialogBar, DpiAware::CDpiAwareDialog) ON_MESSAGE(WM_DPICHANGED_BEFOREPARENT, OnDpiChangedBeforeParent) END_MESSAGE_MAP() diff --git a/Src/TrDialogs.h b/Src/TrDialogs.h index f753c10f200..7cc8f79c026 100644 --- a/Src/TrDialogs.h +++ b/Src/TrDialogs.h @@ -44,65 +44,49 @@ class DlgUtils : public StaticDlgUtils void DpiChangedImplHelper(HWND hwnd, int olddpi, int newdpi); -template -class DpiChangedImpl -{ -public: - LRESULT OnDpiChangedImpl(WPARAM wParam, LPARAM lParam) - { - T* pwnd = static_cast(this); - int olddpi = pwnd->m_dpi; - pwnd->UpdateDpi(); - pwnd->Default(); - if (olddpi != pwnd->m_dpi) - DpiChangedImplHelper(pwnd->m_hWnd, olddpi, pwnd->m_dpi); - return 0; - } -}; - class CTrDialog - : public DpiAware::CDpiAwareWnd + : public DpiAware::CDpiAwareDialog , public DlgUtils - , public DpiChangedImpl { - friend DpiChangedImpl; DECLARE_DYNAMIC(CTrDialog) public: - using DpiAware::CDpiAwareWnd::CDpiAwareWnd; + using DpiAware::CDpiAwareDialog::CDpiAwareDialog; virtual BOOL OnInitDialog(); DECLARE_MESSAGE_MAP() afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam) { - return OnDpiChangedImpl(wParam, lParam); + int olddpi = m_dpi; + LRESULT result = __super::OnDpiChanged(wParam, lParam); + DpiChangedImplHelper(m_hWnd, olddpi, m_dpi); + return result; } }; class CTrPropertyPage - : public DpiAware::CDpiAwareWnd + : public DpiAware::CDpiAwareDialog , public DlgUtils - , public DpiChangedImpl { - friend DpiChangedImpl; DECLARE_DYNAMIC(CTrPropertyPage) public: - using DpiAware::CDpiAwareWnd::CDpiAwareWnd; + using DpiAware::CDpiAwareDialog::CDpiAwareDialog; virtual BOOL OnInitDialog(); DECLARE_MESSAGE_MAP() afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) { - return OnDpiChangedImpl(wParam, lParam); + int olddpi = m_dpi; + LRESULT result = __super::OnDpiChangedBeforeParent(wParam, lParam); + DpiChangedImplHelper(m_hWnd, olddpi, m_dpi); + return result; } }; class CTrDialogBar - : public DpiAware::CDpiAwareWnd + : public DpiAware::CDpiAwareDialog , public DlgUtils - , public DpiChangedImpl { - friend DpiChangedImpl; DECLARE_DYNAMIC(CTrDialogBar) public: virtual BOOL Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName, @@ -111,5 +95,11 @@ class CTrDialogBar UINT nStyle, UINT nID); DECLARE_MESSAGE_MAP() - afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) { return OnDpiChangedImpl(wParam, lParam); } + afx_msg LRESULT OnDpiChangedBeforeParent(WPARAM wParam, LPARAM lParam) + { + int olddpi = m_dpi; + LRESULT result = __super::OnDpiChangedBeforeParent(wParam, lParam); + DpiChangedImplHelper(m_hWnd, olddpi, m_dpi); + return result; + } }; diff --git a/Src/res/ToolbarEnabledMask.bmp b/Src/res/ToolbarEnabledMask.bmp deleted file mode 100644 index 14f353cd6010f6536b05f2df70816c696ccec823..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 722 zcmZ9KzfQw25XR39k~35UwoZg@jFs3aV&@%r1va)Cu`t2H1G&n;f>enou+*VzP?kuo ze0+DdrNUYMlk?A)&v(AN|DKTA4aO_<2Se0gHfUlW*zZnLS4SS0nV5sY42u;}k7Iq~ zjK^A?yB)hqSIkS-dh$xg{ap2wv#j-26P!}7Bf*H^(3{V>0OK0j~4 z-cG=NwGJ}TAKz40VuRJ0x#=JrEUcct+RTovvgyki`RrG*Srfe^mdsg|cCqP*Fv!A) zFCUf&8kfvW{mvL%Uex+Zx@19AWXtR{vxLjUeXymGIErQVWP^~J6j@?Q>};8J zi(@va9b3^V{(tNYKIm9fewy|ZBR4E4<+#31?2`=_r4qvQ4RS0wW6n9N=iwYI@)p~1 zb<73}?NSS7sfE^Uympmi)EE}`scI6}8%?Jy7JogMfW DUN+W_ diff --git a/Src/res/ToolbarEnabledMask32.bmp b/Src/res/ToolbarEnabledMask32.bmp deleted file mode 100644 index d12f9cd7c1ef5aed4be90b4a3e9ec2f1d6e6bdae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2790 zcmb`JJB}1F5QfVb(GslG5(l7DPC<{zxx*kXfJBPaCV_B{K*}xfieSUNf>%gvNRLPc zY3Snr%k9~IunPe_Q&WDFzb=eiSJ5S*gzW>ThYoFC!KqhQKUF{4_z5?`h7ttt`9kiM_IjufwSGXGn{mTy zc0@2)AZ6Fn#QT>GxC`by2GfRG2-WPfD~E@E@Ty}rf>)M1n7Uo>LXP^=!w zeW!h!eDcGJJII!6!S>?sSB8#bDJWQ(`Y6&;tUY$Ha@sf1MR#0rkFu@OoV(xM!W~39 zO6Inz1GsfSTn{VmLDGyHq}}h1SOZ!6t8kyfK8=m)5!{Mg{Mx#4%*Nu|SE))9e}i=U z-EiVM&OdNHp*3JxAy$vI>H%EObxRAbxV}lV_+ofpYv#fk23k)#dMqe}?Ge(03t#&x zX0GHpLb=5Cochak9Q=ImqGGAwfw?<&3Tq{&GL`u z1M?WE$fSln&L75ngOSKLf2`8P-(BYJ13EG3d}oe2vMs_vlO~@#cokm?`y1{C=MK)J zG~s>>yldP~*q!ol)j9PQq;-MChAv?}HoaG~s?uyc4Qlg)!Au#$IFoDenuO z>kYZ zVa&lM-^cH8ACtSjH{oZOz~w<}ESllr`A~R8lYKz0QS$$XbNqj>XN>O#jA-{zsJI5O z(|GnTT;`hP-vxPB_`hS%2aXNc*%bS~qnx)i*eg$_T=>)!KZ{1cB;*7|FUk9Xk3E+W rZF4SN#X8`RT3~#~Cv(R;GGxtuj;9p6q7&v3d~_6vXRH2V_doP+MI Date: Thu, 17 Sep 2020 08:10:39 +0900 Subject: [PATCH 12/23] WIP: Add support for per-monitor DPI awareness (12) --- Src/MainFrm.cpp | 5 +++-- Src/Merge.cpp | 2 +- Src/OptionsInit.cpp | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index b7a63cf5c60..946db96dbd5 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -59,6 +59,7 @@ #include "VersionInfo.h" #include "Bitmap.h" #include "CCrystalTextMarkers.h" + #include "WindowsManagerDialog.h" using std::vector; @@ -2023,8 +2024,8 @@ BOOL CMainFrame::CreateToolbar() /** @brief Load toolbar images from the resource. */ void CMainFrame::LoadToolbarImages() { - const int toolbarNewImgSize = MulDiv(16, m_dpi, USER_DEFAULT_SCREEN_DPI) << GetOptionsMgr()->GetInt(OPT_TOOLBAR_SIZE); - const int toolbarOrgImgSize = toolbarNewImgSize == 16 ? 16 : 32; + const int toolbarNewImgSize = MulDiv(16, GetSystemMetrics(SM_CXSMICON), 16) * (1 + GetOptionsMgr()->GetInt(OPT_TOOLBAR_SIZE)); + const int toolbarOrgImgSize = toolbarNewImgSize <= 20 ? 16 : 32; CToolBarCtrl& BarCtrl = m_wndToolBar.GetToolBarCtrl(); m_ToolbarImages[TOOLBAR_IMAGES_ENABLED].DeleteImageList(); diff --git a/Src/Merge.cpp b/Src/Merge.cpp index d8f468d2ec1..2ff66782fa8 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -150,7 +150,7 @@ BOOL CMergeApp::InitInstance() InitCommonControls(); // initialize common control library CWinApp::InitInstance(); // call parent class method - m_imageForInitializingGdiplus.Load((IStream*)nullptr); + m_imageForInitializingGdiplus.Load((IStream*)nullptr); // initialize GDI+ // Runtime switch so programmer may set this in interactive debugger int dbgmem = 0; diff --git a/Src/OptionsInit.cpp b/Src/OptionsInit.cpp index aec048233a6..b4011bb22c3 100644 --- a/Src/OptionsInit.cpp +++ b/Src/OptionsInit.cpp @@ -61,8 +61,7 @@ void Init(COptionsMgr *pOptions) pOptions->InitOption(OPT_SHOW_TOOLBAR, true); pOptions->InitOption(OPT_SHOW_STATUSBAR, true); pOptions->InitOption(OPT_SHOW_TABBAR, true); - const int cxsmicon = GetSystemMetrics(SM_CXSMICON); - pOptions->InitOption(OPT_TOOLBAR_SIZE, (cxsmicon < 28) ? 0 : (cxsmicon < 40 ? 1 : 2)); + pOptions->InitOption(OPT_TOOLBAR_SIZE, 0); pOptions->InitOption(OPT_RESIZE_PANES, false); pOptions->InitOption(OPT_SYNTAX_HIGHLIGHT, true); From 11ec52843f72c3bab826933c8d1c805dc7441e1f Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sat, 19 Sep 2020 06:37:05 +0900 Subject: [PATCH 13/23] WIP: Add support for per-monitor DPI awareness (13) --- .../crystaledit/editlib/utils/DpiAware.cpp | 41 +++++++++++++++++++ .../crystaledit/editlib/utils/DpiAware.h | 17 ++++---- Src/Common/CMoveConstraint.cpp | 22 +++++++--- Src/Common/CMoveConstraint.h | 3 +- 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/Externals/crystaledit/editlib/utils/DpiAware.cpp b/Externals/crystaledit/editlib/utils/DpiAware.cpp index f18a54404e2..08a7f4acafd 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.cpp +++ b/Externals/crystaledit/editlib/utils/DpiAware.cpp @@ -127,6 +127,47 @@ namespace DpiAware EnumChildWindows(hwnd, enumfunc, (LPARAM)&dpis); } + CSize Dialog_GetSizeFromTemplate(const TCHAR *pTemplateID, const TCHAR *pszFaceName, int nFontSize) + { + CDialogTemplate tmpl; + CSize size; + tmpl.Load(pTemplateID); + tmpl.SetFont(pszFaceName, nFontSize); + tmpl.GetSizeInPixels(&size); + return size; + } + + CSize Dialog_CalcUpdatedSize(const TCHAR *pszFontFace, int nFontSize, const CSize& oldsize, int olddpi, int newdpi) + { + UINT cxSysChar[2], cySysChar[2]; + LOGFONT lf[2] = {}; + CClientDC dc(nullptr); + lf[0].lfHeight = -MulDiv(nFontSize, olddpi, 72); + lf[0].lfWeight = FW_NORMAL; + lf[0].lfCharSet = DEFAULT_CHARSET; + _tcscpy_s(lf[0].lfFaceName, pszFontFace); + lf[1] = lf[0]; + lf[1].lfHeight = -MulDiv(nFontSize, newdpi, 72); + + for (int i = 0; i < 2; ++i) + { + CFont font; + font.CreateFontIndirect(&lf[i]); + HFONT hFontOld = (HFONT)SelectObject(dc, font); + TEXTMETRIC tm; + dc.GetTextMetrics(&tm); + cySysChar[i] = tm.tmHeight + tm.tmExternalLeading; + SIZE size; + GetTextExtentPoint32(dc, _T("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), 52, &size); + cxSysChar[i] = (size.cx + 26) / 52; + dc.SelectObject(hFontOld); + } + + int newcx = MulDiv(oldsize.cx, cxSysChar[1], cxSysChar[0]); + int newcy = MulDiv(oldsize.cy, cySysChar[1], cySysChar[0]); + return { newcx, newcy }; + } + HIMAGELIST LoadShellImageList(int dpi) { SHFILEINFO sfi{}; diff --git a/Externals/crystaledit/editlib/utils/DpiAware.h b/Externals/crystaledit/editlib/utils/DpiAware.h index 639b692637c..17452895a00 100644 --- a/Externals/crystaledit/editlib/utils/DpiAware.h +++ b/Externals/crystaledit/editlib/utils/DpiAware.h @@ -46,6 +46,8 @@ namespace DpiAware void UpdateAfxDataSysMetrics(int dpi); void ListView_UpdateColumnWidths(HWND hwnd, int olddpi, int newdpi); void Dialog_UpdateControlInnerWidths(HWND hwnd, int olddpi, int newdpi); + CSize Dialog_CalcUpdatedSize(const TCHAR* pszFontFace, int nFontSize, const CSize& oldsize, int olddpi, int newdpi); + CSize Dialog_GetSizeFromTemplate(const TCHAR* pTemplateID, const TCHAR* pszFaceName, int nFontSize); HIMAGELIST LoadShellImageList(int dpi); template T MulDivRect(const T* p, int nNumerator, int nDenominator) @@ -155,18 +157,17 @@ namespace DpiAware } UpdateDpi(); Default(); - /* if (bDynamicLayoutEnabled) { - m_rcInit = DpiAware::MulDivRect(&m_rcInit, m_dpi, olddpi); - sizeMin.cx = MulDiv(sizeMin.cx, m_dpi, olddpi); - sizeMin.cy = MulDiv(sizeMin.cy, m_dpi, olddpi); - CRect rc = m_rcInit; - AdjustWindowRectEx(&rc, GetStyle(), false, GetExStyle()); - SetWindowPos(nullptr, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER); + /* + CFont *pFont = GetFont(); + LOGFONT lfFont; + pFont->GetLogFont(&lfFont); + CSize size = Dialog_GetSizeFromTemplate(m_lpszTemplateName, lfFont.lfFaceName, MulDiv(abs(lfFont.lfHeight), 72, m_dpi)); + SetWindowPos(nullptr, 0, 0, size.cx, size.cy, SWP_NOMOVE | SWP_NOZORDER); LoadDynamicLayoutResource(m_lpszTemplateName); + */ } - */ return 0; } diff --git a/Src/Common/CMoveConstraint.cpp b/Src/Common/CMoveConstraint.cpp index 1611e2e1af0..58d203032ad 100644 --- a/Src/Common/CMoveConstraint.cpp +++ b/Src/Common/CMoveConstraint.cpp @@ -104,6 +104,11 @@ CMoveConstraint::GrabCurrentDimensionsAsOriginal(HWND hwndDlg) GetClientRect(hwndDlg, m_rectDlgOriginal); CRect rect; GetWindowRect(hwndDlg, &rect); + LOGFONT lf; + CFont* pFont = CWnd::FromHandle(hwndDlg)->GetFont(); + pFont->GetLogFont(&lf); + m_fontFace = lf.lfFaceName; + m_fontSize = MulDiv(abs(lf.lfHeight), 72, m_dpi); // (min/max code) // remember original width & heighth in case a disallow function called @@ -667,25 +672,30 @@ CMoveConstraint::WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, L const int newnonclientsx = rc.Width() - rcClient.Width(); const int newnonclientsy = rc.Height() - rcClient.Height(); const RECT* pRect = reinterpret_cast(lParam); - m_rectDlgOriginal = DpiAware::MulDivRect(&m_rectDlgOriginal, m_dpi, olddpi); + CSize sizeOld = { m_rectDlgOriginal.right, m_rectDlgOriginal.bottom }; + CSize sizeNew = DpiAware::Dialog_CalcUpdatedSize(m_fontFace.c_str(), m_fontSize, sizeOld, olddpi, m_dpi); + m_rectDlgOriginal.right = sizeNew.cx; + m_rectDlgOriginal.bottom = sizeNew.cx; for (auto& pval : { &m_nMaxX, &m_nMinX, &m_nOrigX }) { if (*pval) - *pval = MulDiv(*pval - oldnonclientsx, m_dpi, olddpi) + newnonclientsx; + *pval = MulDiv(*pval - oldnonclientsx, sizeNew.cx, sizeOld.cx) + newnonclientsx; } for (auto& pval : { &m_nMaxY, &m_nMinY, &m_nOrigY }) { if (*pval) - *pval = MulDiv(*pval - oldnonclientsy, m_dpi, olddpi) + newnonclientsy; + *pval = MulDiv(*pval - oldnonclientsy, sizeNew.cy, sizeOld.cy) + newnonclientsy; } ConstraintList & constraintList = m_ConstraintList; for (POSITION pos=constraintList.GetHeadPosition(); pos != nullptr; constraintList.GetNext(pos)) { Constraint & constraint = constraintList.GetAt(pos); for (auto& pval : - { &constraint.m_rectChildOriginal.left,&constraint.m_rectChildOriginal.top, - &constraint.m_rectChildOriginal.right, &constraint.m_rectChildOriginal.bottom }) - *pval = MulDiv(*pval, m_dpi, olddpi); + { &constraint.m_rectChildOriginal.left, &constraint.m_rectChildOriginal.right }) + *pval = MulDiv(*pval, sizeNew.cx, sizeOld.cx); + for (auto& pval : + { &constraint.m_rectChildOriginal.top, &constraint.m_rectChildOriginal.bottom }) + *pval = MulDiv(*pval, sizeNew.cy, sizeOld.cy); } } diff --git a/Src/Common/CMoveConstraint.h b/Src/Common/CMoveConstraint.h index 7e4ad93916d..26a2cad5868 100644 --- a/Src/Common/CMoveConstraint.h +++ b/Src/Common/CMoveConstraint.h @@ -213,7 +213,8 @@ class CMoveConstraint private: HWND m_hwndDlg; // parent of controls - could be FormView or PropertyPage or whatever as well CRect m_rectDlgOriginal; - CRect m_rectDlgOriginalIncludingNonClient; + String m_fontFace; + double m_fontSize; int m_nOrigX; int m_nOrigY; EGRIP m_nGrip; From cfc8bfb7f704d440e32b57671d171e0aa74ccfd9 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sat, 19 Sep 2020 21:32:08 +0900 Subject: [PATCH 14/23] WIP: Add support for per-monitor DPI awareness (14) --- Externals/crystaledit/Sample/ChildFrm.cpp | 19 ++++++++--------- Externals/crystaledit/Sample/ChildFrm.h | 2 +- Externals/crystaledit/Sample/MainFrm.cpp | 16 -------------- Externals/crystaledit/Sample/MainFrm.h | 1 - Src/MainFrm.cpp | 12 +++++------ Src/MergeEditFrm.cpp | 2 +- Src/MergeFrameCommon.cpp | 26 +++++++++++++---------- Src/MergeFrameCommon.h | 1 + 8 files changed, 33 insertions(+), 46 deletions(-) diff --git a/Externals/crystaledit/Sample/ChildFrm.cpp b/Externals/crystaledit/Sample/ChildFrm.cpp index 0a57d381224..1c1ae1088e4 100755 --- a/Externals/crystaledit/Sample/ChildFrm.cpp +++ b/Externals/crystaledit/Sample/ChildFrm.cpp @@ -19,7 +19,7 @@ IMPLEMENT_DYNCREATE(CChildFrame, DpiAware::CDpiAwareWnd) BEGIN_MESSAGE_MAP(CChildFrame, DpiAware::CDpiAwareWnd) //{{AFX_MSG_MAP(CChildFrame) - ON_WM_GETMINMAXINFO() + ON_WM_SIZE() // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG_MAP @@ -70,18 +70,17 @@ BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) return m_wndSplitter.Create(this, 2, 2, CSize(30, 30), pContext); } -void CChildFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) +void CChildFrame::OnSize(UINT nType, int cx, int cy) { - __super::OnGetMinMaxInfo(lpMMI); - if (IsDifferentDpiFromSystemDpi()) + __super::OnSize(nType, cx, cy); + if (nType == SIZE_MAXIMIZED && IsDifferentDpiFromSystemDpi()) { + // This is a workaround of the problem that the maximized MDI child window is in the wrong position when the DPI changes + // I don't think MDI-related processing inside Windows fully supports per-monitor dpi awareness CRect rc; - CFrameWnd* pFrameWnd = GetParentFrame(); - pFrameWnd->GetClientRect(rc); + GetParent()->GetClientRect(rc); AdjustWindowRectEx(&rc, GetStyle(), FALSE, GetExStyle()); - lpMMI->ptMaxPosition.x = rc.left; - lpMMI->ptMaxPosition.y = rc.top; - lpMMI->ptMaxSize.x = rc.right - rc.left; - lpMMI->ptMaxSize.y = rc.bottom - rc.top; + SetWindowPos(nullptr, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOACTIVATE); } } + diff --git a/Externals/crystaledit/Sample/ChildFrm.h b/Externals/crystaledit/Sample/ChildFrm.h index f3a7c1b35c6..155429381aa 100755 --- a/Externals/crystaledit/Sample/ChildFrm.h +++ b/Externals/crystaledit/Sample/ChildFrm.h @@ -42,7 +42,7 @@ class CChildFrame : public DpiAware::CDpiAwareWnd // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG - afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); + afx_msg void OnSize(UINT nType, int cx, int cy); DECLARE_MESSAGE_MAP() }; diff --git a/Externals/crystaledit/Sample/MainFrm.cpp b/Externals/crystaledit/Sample/MainFrm.cpp index e455fe5a269..370f593944d 100755 --- a/Externals/crystaledit/Sample/MainFrm.cpp +++ b/Externals/crystaledit/Sample/MainFrm.cpp @@ -24,7 +24,6 @@ BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::CDpiAwareWnd) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code ! ON_WM_CREATE() - ON_MESSAGE(WM_NCCALCSIZE, OnNcCalcSize) ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -89,21 +88,6 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) return 0; } -LRESULT CMainFrame::OnNcCalcSize(WPARAM wParam, LPARAM lParam) -{ - BOOL bCalcValidRects = wParam; - NCCALCSIZE_PARAMS* lpncsp = (NCCALCSIZE_PARAMS*)lParam; - RECT *lprect = (RECT *)lParam; - - LRESULT ret = Default(); - if (bCalcValidRects) - { -// lpncsp->rgrc->top -= 10; - return ret; - } - return ret; -} - LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { __super::OnDpiChanged(wParam, lParam); diff --git a/Externals/crystaledit/Sample/MainFrm.h b/Externals/crystaledit/Sample/MainFrm.h index 8263585ac7e..dcc685736a9 100755 --- a/Externals/crystaledit/Sample/MainFrm.h +++ b/Externals/crystaledit/Sample/MainFrm.h @@ -42,7 +42,6 @@ class CMainFrame : public DpiAware::CDpiAwareWnd protected: //{{AFX_MSG(CMainFrame) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); - afx_msg LRESULT OnNcCalcSize(WPARAM wParam, LPARAM lParam); // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index 946db96dbd5..a119da01cb5 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -2028,8 +2028,8 @@ void CMainFrame::LoadToolbarImages() const int toolbarOrgImgSize = toolbarNewImgSize <= 20 ? 16 : 32; CToolBarCtrl& BarCtrl = m_wndToolBar.GetToolBarCtrl(); - m_ToolbarImages[TOOLBAR_IMAGES_ENABLED].DeleteImageList(); - m_ToolbarImages[TOOLBAR_IMAGES_DISABLED].DeleteImageList(); + m_ToolbarImages[TOOLBAR_IMAGES_ENABLED].Detach(); + m_ToolbarImages[TOOLBAR_IMAGES_DISABLED].Detach(); CSize sizeButton(0, 0); LoadToolbarImageList(toolbarOrgImgSize, toolbarNewImgSize, @@ -2042,10 +2042,10 @@ void CMainFrame::LoadToolbarImages() sizeButton = CSize(toolbarNewImgSize + 8, toolbarNewImgSize + 8); BarCtrl.SetButtonSize(sizeButton); - BarCtrl.SetImageList(&m_ToolbarImages[TOOLBAR_IMAGES_ENABLED]); - BarCtrl.SetDisabledImageList(&m_ToolbarImages[TOOLBAR_IMAGES_DISABLED]); - m_ToolbarImages[TOOLBAR_IMAGES_ENABLED].Detach(); - m_ToolbarImages[TOOLBAR_IMAGES_DISABLED].Detach(); + if (CImageList *pImgList = BarCtrl.SetImageList(&m_ToolbarImages[TOOLBAR_IMAGES_ENABLED])) + pImgList->DeleteImageList(); + if (CImageList *pImgList = BarCtrl.SetDisabledImageList(&m_ToolbarImages[TOOLBAR_IMAGES_DISABLED])) + pImgList->DeleteImageList(); // resize the rebar. REBARBANDINFO rbbi = { sizeof REBARBANDINFO }; diff --git a/Src/MergeEditFrm.cpp b/Src/MergeEditFrm.cpp index 21f137493f4..4c28a62e179 100644 --- a/Src/MergeEditFrm.cpp +++ b/Src/MergeEditFrm.cpp @@ -449,7 +449,7 @@ LRESULT CMergeEditFrame::OnStorePaneSizes(WPARAM wParam, LPARAM lParam) void CMergeEditFrame::OnSize(UINT nType, int cx, int cy) { - CMDIChildWnd::OnSize(nType, cx, cy); + __super::OnSize(nType, cx, cy); UpdateHeaderSizes(); } diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index f0a22666ede..a7bd488a37d 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -17,6 +17,7 @@ IMPLEMENT_DYNCREATE(CMergeFrameCommon, CMDIChildWnd) BEGIN_MESSAGE_MAP(CMergeFrameCommon, DpiAware::CDpiAwareWnd) //{{AFX_MSG_MAP(CMergeFrameCommon) ON_WM_GETMINMAXINFO() + ON_WM_SIZE() ON_WM_DESTROY() ON_WM_MDIACTIVATE() // ON_MESSAGE(WM_GETICON, OnGetIcon) @@ -104,17 +105,6 @@ void CMergeFrameCommon::SetLastCompareResult(int nResult) void CMergeFrameCommon::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { __super::OnGetMinMaxInfo(lpMMI); - if (IsDifferentDpiFromSystemDpi()) - { - CRect rc; - CFrameWnd* pFrameWnd = GetParentFrame(); - pFrameWnd->GetClientRect(rc); - AdjustWindowRectEx(&rc, GetStyle(), FALSE, GetExStyle()); - lpMMI->ptMaxPosition.x = rc.left; - lpMMI->ptMaxPosition.y = rc.top; - lpMMI->ptMaxSize.x = rc.right - rc.left; - lpMMI->ptMaxSize.y = rc.bottom - rc.top; - } // [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista] // https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM #if _MFC_VER >= 0x0800 @@ -123,6 +113,20 @@ void CMergeFrameCommon::OnGetMinMaxInfo(MINMAXINFO* lpMMI) #endif } +void CMergeFrameCommon::OnSize(UINT nType, int cx, int cy) +{ + __super::OnSize(nType, cx, cy); + if (nType == SIZE_MAXIMIZED && IsDifferentDpiFromSystemDpi()) + { + // This is a workaround of the problem that the maximized MDI child window is in the wrong position when the DPI changes + // I don't think MDI-related processing inside Windows fully supports per-monitor dpi awareness + CRect rc; + GetParent()->GetClientRect(rc); + AdjustWindowRectEx(&rc, GetStyle(), FALSE, GetExStyle()); + SetWindowPos(nullptr, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOACTIVATE); + } +} + void CMergeFrameCommon::OnDestroy() { // https://stackoverflow.com/questions/35553955/getting-rid-of-3d-look-of-mdi-frame-window diff --git a/Src/MergeFrameCommon.h b/Src/MergeFrameCommon.h index 8f5e8b2573e..f78493e3481 100644 --- a/Src/MergeFrameCommon.h +++ b/Src/MergeFrameCommon.h @@ -36,6 +36,7 @@ class CMergeFrameCommon: public DpiAware::CDpiAwareWnd protected: //{{AFX_MSG(CMergeFrameCommon) afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); + afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnDestroy(); afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd); //}}AFX_MSG From aefc0ddad96885c3336854a15d833723eb021219 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Tue, 22 Sep 2020 18:15:40 +0900 Subject: [PATCH 15/23] WIP: Add support for per-monitor DPI awareness (15) --- Externals/crystaledit/Sample/ChildFrm.cpp | 26 +- Externals/crystaledit/Sample/ChildFrm.h | 1 + Externals/crystaledit/Sample/MainFrm.cpp | 74 ++- Externals/crystaledit/Sample/MainFrm.h | 8 + Externals/crystaledit/Sample/Sample.rc | 6 +- .../Sample/SampleStatic.vs2017.vcxproj | 3 +- .../Sample/SampleStatic.vs2019.vcxproj | 2 + .../SampleStatic.vs2019.vcxproj.filters | 6 + Externals/crystaledit/Sample/resource.h | 5 +- .../editlib/utils/MDITileLayout.cpp | 420 ++++++++++++++++++ .../crystaledit/editlib/utils/MDITileLayout.h | 85 ++++ .../src/DirectoryIteratorStrategy.cpp | 2 +- Src/DirFrame.cpp | 8 +- Src/MainFrm.cpp | 38 ++ Src/MainFrm.h | 6 + Src/Merge.vs2017.vcxproj | 2 + Src/Merge.vs2017.vcxproj.filters | 6 + Src/Merge.vs2019.vcxproj | 2 + Src/Merge.vs2019.vcxproj.filters | 6 + Src/MergeFrameCommon.cpp | 23 + Src/MergeFrameCommon.h | 1 + Src/OpenFrm.cpp | 10 +- Src/OpenView.cpp | 2 +- 23 files changed, 713 insertions(+), 29 deletions(-) create mode 100644 Externals/crystaledit/editlib/utils/MDITileLayout.cpp create mode 100644 Externals/crystaledit/editlib/utils/MDITileLayout.h diff --git a/Externals/crystaledit/Sample/ChildFrm.cpp b/Externals/crystaledit/Sample/ChildFrm.cpp index 1c1ae1088e4..256ae02639e 100755 --- a/Externals/crystaledit/Sample/ChildFrm.cpp +++ b/Externals/crystaledit/Sample/ChildFrm.cpp @@ -5,6 +5,7 @@ #include "Sample.h" #include "ChildFrm.h" +#include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -42,8 +43,21 @@ BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs - - return __super::PreCreateWindow(cs); + MDITileLayout::LayoutManager& layoutManager = static_cast(AfxGetMainWnd())->GetLayoutManager(); + if (!layoutManager.GetTileLayoutEnabled()) + return __super::PreCreateWindow(cs); + __super::PreCreateWindow(cs); + cs.style &= ~WS_CAPTION; + CRect rcMain; + CWnd* pWndMDIClient = AfxGetMainWnd()->FindWindowEx(AfxGetMainWnd()->m_hWnd, nullptr, _T("MDIClient"), nullptr); + pWndMDIClient->GetWindowRect(rcMain); + CRect rc = layoutManager.GetDefaultOpenPaneRect(); + AdjustWindowRectEx(rc, cs.style, false, cs.dwExStyle); + cs.x = rc.left - rcMain.left; + cs.y = rc.top - rcMain.top; + cs.cx = rc.Width(); + cs.cy = rc.Height(); + return true; } ///////////////////////////////////////////////////////////////////////////// @@ -67,9 +81,16 @@ void CChildFrame::Dump(CDumpContext& dc) const BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { + static_cast(AfxGetMainWnd())->GetLayoutManager().NotifyChildOpened(this); return m_wndSplitter.Create(this, 2, 2, CSize(30, 30), pContext); } +BOOL CChildFrame::DestroyWindow() +{ + static_cast(AfxGetMainWnd())->GetLayoutManager().NotifyChildClosed(this); + return __super::DestroyWindow(); +} + void CChildFrame::OnSize(UINT nType, int cx, int cy) { __super::OnSize(nType, cx, cy); @@ -82,5 +103,6 @@ void CChildFrame::OnSize(UINT nType, int cx, int cy) AdjustWindowRectEx(&rc, GetStyle(), FALSE, GetExStyle()); SetWindowPos(nullptr, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOACTIVATE); } + static_cast(AfxGetMainWnd())->GetLayoutManager().NotifyChildResized(this); } diff --git a/Externals/crystaledit/Sample/ChildFrm.h b/Externals/crystaledit/Sample/ChildFrm.h index 155429381aa..1a65a7a2756 100755 --- a/Externals/crystaledit/Sample/ChildFrm.h +++ b/Externals/crystaledit/Sample/ChildFrm.h @@ -26,6 +26,7 @@ class CChildFrame : public DpiAware::CDpiAwareWnd virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext); + virtual BOOL DestroyWindow(); //}}AFX_VIRTUAL // Implementation diff --git a/Externals/crystaledit/Sample/MainFrm.cpp b/Externals/crystaledit/Sample/MainFrm.cpp index 370f593944d..3796f21e10f 100755 --- a/Externals/crystaledit/Sample/MainFrm.cpp +++ b/Externals/crystaledit/Sample/MainFrm.cpp @@ -24,6 +24,14 @@ BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::CDpiAwareWnd) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code ! ON_WM_CREATE() + ON_WM_SIZE() + ON_COMMAND_EX(ID_WINDOW_ARRANGE, OnMDIWindowCmd) + ON_COMMAND_EX(ID_WINDOW_CASCADE, OnMDIWindowCmd) + ON_COMMAND_EX(ID_WINDOW_TILE_HORZ, OnMDIWindowCmd) + ON_COMMAND_EX(ID_WINDOW_TILE_VERT, OnMDIWindowCmd) + ON_COMMAND_EX(ID_WINDOW_SPLIT_VERTICALLY, OnWindowSplit) + ON_COMMAND_EX(ID_WINDOW_SPLIT_HORIZONTALLY, OnWindowSplit) + ON_COMMAND(ID_WINDOW_COMBINE, OnWindowCombine) ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -45,7 +53,7 @@ static UINT indicators[] = ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction -CMainFrame::CMainFrame() +CMainFrame::CMainFrame() : m_layoutManager(this) { // TODO: add member initialization code here @@ -88,19 +96,6 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) return 0; } -LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) -{ - __super::OnDpiChanged(wParam, lParam); - DpiAware::UpdateAfxDataSysMetrics(GetDpi()); - LoadToolBar(); - const RECT* pRect = reinterpret_cast(lParam); - SetWindowPos(nullptr, pRect->left, pRect->top, - pRect->right - pRect->left, - pRect->bottom - pRect->top, SWP_NOZORDER | SWP_NOACTIVATE); - Default(); - return 0; -} - BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying @@ -147,3 +142,54 @@ void CMainFrame::Dump(CDumpContext& dc) const ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers + +BOOL CMainFrame::OnMDIWindowCmd(UINT nID) +{ + switch (nID) + { + case ID_WINDOW_TILE_HORZ: + case ID_WINDOW_TILE_VERT: + { + bool bHorizontal = (nID == ID_WINDOW_TILE_HORZ); + m_layoutManager.SetTileLayoutEnabled(true); + m_layoutManager.Tile(bHorizontal); + break; + } + case ID_WINDOW_CASCADE: + m_layoutManager.SetTileLayoutEnabled(false); + __super::OnMDIWindowCmd(nID); + break; + } + return 0; +} + +BOOL CMainFrame::OnWindowSplit(UINT nID) +{ + m_layoutManager.SplitActivePane(nID == ID_WINDOW_SPLIT_HORIZONTALLY, 0.5); + return 0; +} + +void CMainFrame::OnWindowCombine() +{ + m_layoutManager.CombineActivePane(); +} + +void CMainFrame::OnSize(UINT nType, int cx, int cy) +{ + __super::OnSize(nType, cx, cy); + m_layoutManager.NotifyMainResized(); +} + +LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) +{ + __super::OnDpiChanged(wParam, lParam); + DpiAware::UpdateAfxDataSysMetrics(GetDpi()); + LoadToolBar(); + const RECT* pRect = reinterpret_cast(lParam); + SetWindowPos(nullptr, pRect->left, pRect->top, + pRect->right - pRect->left, + pRect->bottom - pRect->top, SWP_NOZORDER | SWP_NOACTIVATE); + Default(); + return 0; +} + diff --git a/Externals/crystaledit/Sample/MainFrm.h b/Externals/crystaledit/Sample/MainFrm.h index dcc685736a9..a926ba7610a 100755 --- a/Externals/crystaledit/Sample/MainFrm.h +++ b/Externals/crystaledit/Sample/MainFrm.h @@ -5,6 +5,7 @@ #pragma once #include "utils/DpiAware.h" +#include "utils/MDITileLayout.h" class CMainFrame : public DpiAware::CDpiAwareWnd { @@ -32,11 +33,14 @@ class CMainFrame : public DpiAware::CDpiAwareWnd virtual void Dump(CDumpContext& dc) const; #endif BOOL LoadToolBar(); + MDITileLayout::LayoutManager& GetLayoutManager() { return m_layoutManager; }; protected: // control bar embedded members CStatusBar m_wndStatusBar; CToolBar m_wndToolBar; CImageList m_imgListToolBar; + CSplitterWnd m_wndSplitter; + MDITileLayout::LayoutManager m_layoutManager; // Generated message map functions protected: @@ -44,6 +48,10 @@ class CMainFrame : public DpiAware::CDpiAwareWnd afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code! + afx_msg BOOL OnMDIWindowCmd(UINT nID); + afx_msg BOOL OnWindowSplit(UINT nID); + afx_msg void OnWindowCombine(); + afx_msg void OnSize(UINT nType, int cx, int cy); //}}AFX_MSG afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() diff --git a/Externals/crystaledit/Sample/Sample.rc b/Externals/crystaledit/Sample/Sample.rc index afa61bf0aef..4439dd4571c 100755 --- a/Externals/crystaledit/Sample/Sample.rc +++ b/Externals/crystaledit/Sample/Sample.rc @@ -197,8 +197,12 @@ BEGIN BEGIN MENUITEM "&New Window", ID_WINDOW_NEW MENUITEM "&Cascade", ID_WINDOW_CASCADE - MENUITEM "&Tile", ID_WINDOW_TILE_HORZ + MENUITEM "Tile &Vertically", ID_WINDOW_TILE_VERT + MENUITEM "Tile &Horizontally", ID_WINDOW_TILE_HORZ MENUITEM "&Arrange Icons", ID_WINDOW_ARRANGE + MENUITEM "Split V&ertically", ID_WINDOW_SPLIT_VERTICALLY + MENUITEM "Split H&orizontally", ID_WINDOW_SPLIT_HORIZONTALLY + MENUITEM "Com&bine", ID_WINDOW_COMBINE END POPUP "&Help" BEGIN diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj b/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj index 1102a3eb4a5..7fd708f12dd 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj +++ b/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj @@ -585,6 +585,7 @@ + @@ -647,7 +648,7 @@ - + diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj index bbf82dacea7..e14658036a5 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj +++ b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj @@ -584,6 +584,7 @@ + @@ -646,6 +647,7 @@ + diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters index 9d9f9036571..c3c3600bca6 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters +++ b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters @@ -255,6 +255,9 @@ editlib\utils + + editlib\utils + @@ -385,6 +388,9 @@ editlib\utils + + editlib\utils + diff --git a/Externals/crystaledit/Sample/resource.h b/Externals/crystaledit/Sample/resource.h index a03543d2931..af51f2ddc09 100755 --- a/Externals/crystaledit/Sample/resource.h +++ b/Externals/crystaledit/Sample/resource.h @@ -51,6 +51,9 @@ #define ID_EDIT_DISABLEDRAGANDDROP 32797 #define ID_EDIT_FIND_PREVIOUS 32799 #define ID_VIEW_WHITESPACE 32800 +#define ID_WINDOW_SPLIT_VERTICALLY 32801 +#define ID_WINDOW_SPLIT_HORIZONTALLY 32802 +#define ID_WINDOW_COMBINE 32803 #define ID_EDIT_INDICATOR_COL 37900 #define ID_READ_ONLY 37901 #define ID_INDICATOR_ENCODING 37905 @@ -62,7 +65,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_3D_CONTROLS 1 #define _APS_NEXT_RESOURCE_VALUE 135 -#define _APS_NEXT_COMMAND_VALUE 32802 +#define _APS_NEXT_COMMAND_VALUE 32804 #define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_SYMED_VALUE 101 #endif diff --git a/Externals/crystaledit/editlib/utils/MDITileLayout.cpp b/Externals/crystaledit/editlib/utils/MDITileLayout.cpp new file mode 100644 index 00000000000..4584eb92244 --- /dev/null +++ b/Externals/crystaledit/editlib/utils/MDITileLayout.cpp @@ -0,0 +1,420 @@ +// SPDX-License-Identifier: BSL-1.0 +// Copyright (c) 2020 Takashi Sawanaka +// +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "StdAfx.h" +#include "MDITileLayout.h" + +namespace MDITileLayout +{ + bool Pane::Split(bool bHorizontal, double ratio) + { + if (IsSplitted()) + return false; + m_pSplittedLayout.reset(new SplittedLayout(this, bHorizontal, ratio, m_wndList)); + m_wndList.clear(); + return true; + } + + bool Pane::Combine() + { + if (IsSplitted()) + { + if (m_pSplittedLayout->m_pPaneFirst->IsSplitted()) + m_pSplittedLayout->m_pPaneFirst->Combine(); + if (m_pSplittedLayout->m_pPaneSecond->IsSplitted()) + m_pSplittedLayout->m_pPaneSecond->Combine(); + for (auto& pWnd : m_pSplittedLayout->m_pPaneFirst->m_wndList) + m_wndList.push_back(pWnd); + for (auto& pWnd : m_pSplittedLayout->m_pPaneSecond->m_wndList) + m_wndList.push_back(pWnd); + m_pSplittedLayout.reset(); + return true; + } + if (m_pParentSplittedLayout == nullptr) + return false; + return m_pParentSplittedLayout->m_pParentPane->Combine(); + } + + void Pane::Tile(bool bHorizontal) + { + if (IsSplitted()) + Combine(); + size_t nCount = m_wndList.size(); + if (nCount <= 1) + return; + Split(bHorizontal, 1.0 / nCount); + for (size_t i = 1; i < nCount; ++i) + m_pSplittedLayout->m_pPaneFirst->MoveWindow(m_pSplittedLayout->m_pPaneSecond.get(), m_pSplittedLayout->m_pPaneFirst->m_wndList[1]); + m_pSplittedLayout->m_pPaneSecond->Tile(bHorizontal); + } + + CRect Pane::GetRect(const CRect& rcMainWnd) const + { + double left = 0, top = 0, width = 1.0, height = 1.0; + for (auto *pPane = this; + pPane->m_pParentSplittedLayout != nullptr; + pPane = pPane->m_pParentSplittedLayout->m_pParentPane) + { + SplittedLayout* pParentSplittedLayout = pPane->m_pParentSplittedLayout; + if (pParentSplittedLayout->m_pPaneFirst.get() == pPane) + { + if (pParentSplittedLayout->m_bHorizontal) + { + top *= pParentSplittedLayout->m_firstPaneSizeRatio; + height *= pParentSplittedLayout->m_firstPaneSizeRatio; + } + else + { + left *= pParentSplittedLayout->m_firstPaneSizeRatio; + width *= pParentSplittedLayout->m_firstPaneSizeRatio; + } + } + else + { + if (pParentSplittedLayout->m_bHorizontal) + { + top = pParentSplittedLayout->m_firstPaneSizeRatio + top * (1.0 - pParentSplittedLayout->m_firstPaneSizeRatio); + height *= (1.0 - pParentSplittedLayout->m_firstPaneSizeRatio); + } + else + { + left = pParentSplittedLayout->m_firstPaneSizeRatio + left * (1.0 - pParentSplittedLayout->m_firstPaneSizeRatio); + width *= (1.0 - pParentSplittedLayout->m_firstPaneSizeRatio); + } + } + + } + return CRect( + static_cast(rcMainWnd.left + rcMainWnd.Width() * left), + static_cast(rcMainWnd.top + rcMainWnd.Height() * top), + static_cast(rcMainWnd.left + rcMainWnd.Width() * (left + width)), + static_cast(rcMainWnd.top + rcMainWnd.Height() * (top + height))); + } + + void Pane::SetDefaultOpenPane() + { + for (auto *pPane = this; + pPane->m_pParentSplittedLayout != nullptr; + pPane = pPane->m_pParentSplittedLayout->m_pParentPane) + { + SplittedLayout* pParentSplittedLayout = pPane->m_pParentSplittedLayout; + pParentSplittedLayout->m_bDefaultOpenPaneIsFirst = (pParentSplittedLayout->m_pPaneFirst.get() == pPane); + } + } + + Pane* Pane::GetDefaultOpenPane() const + { + if (!IsSplitted()) + return const_cast(this); + if (m_pSplittedLayout->m_bDefaultOpenPaneIsFirst) + return m_pSplittedLayout->m_pPaneFirst->GetDefaultOpenPane(); + return m_pSplittedLayout->m_pPaneSecond->GetDefaultOpenPane(); + } + + bool Pane::AddWindow(CWnd* pWnd) + { + if (IsSplitted()) + return false; + m_wndList.push_back(pWnd); + return true; + } + + bool Pane::RemoveWindow(CWnd* pWnd) + { + auto it = std::remove(m_wndList.begin(), m_wndList.end(), pWnd); + if (it == m_wndList.end()) + return false; + m_wndList.erase(it); + return true; + } + + bool Pane::MoveWindow(Pane* pDstPane, CWnd* pWnd) + { + if (!RemoveWindow(pWnd)) + return false; + return pDstPane->AddWindow(pWnd); + } + + Pane* Pane::FindPaneByWindow(CWnd* pWnd) const + { + if (!IsSplitted()) + { + auto it = std::find(m_wndList.begin(), m_wndList.end(), pWnd); + if (it != m_wndList.end()) + return const_cast(this); + return nullptr; + } + if (Pane *pPane = m_pSplittedLayout->m_pPaneFirst->FindPaneByWindow(pWnd)) + return pPane; + return m_pSplittedLayout->m_pPaneSecond->FindPaneByWindow(pWnd); + } + + void Pane::UpdateSizeRatio(const CRect& rcMainWnd, const CRect& rcChildWnd) + { + if (m_pParentSplittedLayout == nullptr) + return; + const int None = 0, Left = 1, Top = 2, Right = 4, Bottom = 8; + int changedBorders = None; + CRect rcChildWndOld = GetRect(rcMainWnd); + if (rcChildWndOld.left != rcChildWnd.left) + changedBorders |= Left; + if (rcChildWndOld.top != rcChildWnd.top) + changedBorders |= Top; + if (rcChildWndOld.right != rcChildWnd.right) + changedBorders |= Right; + if (rcChildWndOld.bottom != rcChildWnd.bottom) + changedBorders |= Bottom; + if (changedBorders & Left) + { + for (auto* pPane = this; + pPane->m_pParentSplittedLayout != nullptr; + pPane = pPane->m_pParentSplittedLayout->m_pParentPane) + { + if (!pPane->m_pParentSplittedLayout->m_bHorizontal && pPane->m_pParentSplittedLayout->m_pPaneSecond.get() == pPane) + { + CRect rcParentWnd = pPane->m_pParentSplittedLayout->m_pParentPane->GetRect(rcMainWnd); + if (rcChildWnd.Width() <= 0 || rcChildWnd.Width() >= rcParentWnd.Width()) + { + pPane->m_pParentSplittedLayout->m_pParentPane->Combine(); + return; + } + pPane->m_pParentSplittedLayout->m_firstPaneSizeRatio = static_cast(rcChildWnd.left - rcParentWnd.left) / rcParentWnd.Width(); + break; + } + } + } + if (changedBorders & Top) + { + for (auto* pPane = this; + pPane->m_pParentSplittedLayout != nullptr; + pPane = pPane->m_pParentSplittedLayout->m_pParentPane) + { + if (pPane->m_pParentSplittedLayout->m_bHorizontal && pPane->m_pParentSplittedLayout->m_pPaneSecond.get() == pPane) + { + CRect rcParentWnd = pPane->m_pParentSplittedLayout->m_pParentPane->GetRect(rcMainWnd); + if (rcChildWnd.Height() <= 0 || rcChildWnd.Height() >= rcParentWnd.Height()) + { + pPane->m_pParentSplittedLayout->m_pParentPane->Combine(); + return; + } + pPane->m_pParentSplittedLayout->m_firstPaneSizeRatio = static_cast(rcChildWnd.top - rcParentWnd.top) / rcParentWnd.Height(); + break; + } + } + } + if (changedBorders & Right) + { + for (auto* pPane = this; + pPane->m_pParentSplittedLayout != nullptr; + pPane = pPane->m_pParentSplittedLayout->m_pParentPane) + { + if (!pPane->m_pParentSplittedLayout->m_bHorizontal && pPane->m_pParentSplittedLayout->m_pPaneFirst.get() == pPane) + { + CRect rcParentWnd = pPane->m_pParentSplittedLayout->m_pParentPane->GetRect(rcMainWnd); + if (rcChildWnd.Width() <= 0 || rcChildWnd.Width() >= rcParentWnd.Width()) + { + pPane->m_pParentSplittedLayout->m_pParentPane->Combine(); + return; + } + pPane->m_pParentSplittedLayout->m_firstPaneSizeRatio = static_cast(rcChildWnd.right - rcParentWnd.left) / rcParentWnd.Width(); + break; + } + } + } + if (changedBorders & Bottom) + { + for (auto* pPane = this; + pPane->m_pParentSplittedLayout != nullptr; + pPane = pPane->m_pParentSplittedLayout->m_pParentPane) + { + if (pPane->m_pParentSplittedLayout->m_bHorizontal && pPane->m_pParentSplittedLayout->m_pPaneFirst.get() == pPane) + { + CRect rcParentWnd = pPane->m_pParentSplittedLayout->m_pParentPane->GetRect(rcMainWnd); + if (rcChildWnd.Height() <= 0 || rcChildWnd.Height() >= rcParentWnd.Height()) + { + pPane->m_pParentSplittedLayout->m_pParentPane->Combine(); + return; + } + pPane->m_pParentSplittedLayout->m_firstPaneSizeRatio = static_cast(rcChildWnd.bottom - rcParentWnd.top) / rcParentWnd.Height(); + break; + } + } + } + } + + SplittedLayout::SplittedLayout(Pane* pParentPane, bool bHorizontal, double ratio, std::vector& wndList) + : m_pParentPane(pParentPane) + , m_bHorizontal(bHorizontal) + , m_firstPaneSizeRatio(ratio) + , m_pPaneFirst(new Pane(this)) + , m_pPaneSecond(new Pane(this)) + { + m_pPaneFirst->m_wndList = wndList; + m_pPaneSecond->SetDefaultOpenPane(); + } + + void LayoutManager::SetTileLayoutEnabled(bool bEnabled) + { + if (m_bEnabled == bEnabled) + return; + + m_bEnabled = bEnabled; + + HWND hWndMDIActive = m_pMDIFrameWnd->MDIGetActive()->GetSafeHwnd(); + if (hWndMDIActive == nullptr) + return; + + m_pMDIFrameWnd->MDICascade(); + + for (CWnd* pWnd = m_pMDIFrameWnd->MDIGetActive()->GetParent()->GetTopWindow(); pWnd; pWnd = pWnd->GetNextWindow()) + { + DWORD dwStyle = pWnd->GetStyle(); + if (m_bEnabled) + { + SetWindowLong(pWnd->m_hWnd, GWL_STYLE, dwStyle & ~(WS_CAPTION)); + } + else + { + SetWindowLong(pWnd->m_hWnd, GWL_STYLE, dwStyle | WS_CAPTION); + pWnd->ShowWindow(SW_HIDE); + pWnd->ShowWindow(SW_SHOW); + } + } + + UpdateChildWindows(); + } + + void LayoutManager::Tile(bool bHorizontal) + { + m_pPane->Tile(bHorizontal); + UpdateChildWindows(); + } + + bool LayoutManager::SplitActivePane(bool bHorizontal, double ratio) + { + bool result = false; + if (Pane* pPane = GetActivePane()) + result = pPane->Split(bHorizontal, ratio); + if (result) + UpdateChildWindows(); + return result; + } + + bool LayoutManager::CombineActivePane() + { + bool result = false; + if (Pane* pPane = GetActivePane()) + result = pPane->Combine(); + if (result) + UpdateChildWindows(); + return result; + } + + void LayoutManager::SetActivePaneAsDefaultOpenPane() + { + if (Pane* pPane = GetActivePane()) + pPane->SetDefaultOpenPane(); + } + + CRect LayoutManager::GetDefaultOpenPaneRect() const + { + CRect rc = GetMainRect(); + if (Pane* pPane = m_pPane->GetDefaultOpenPane()) + return pPane->GetRect(rc); + return rc; + } + + void LayoutManager::NotifyMainResized() + { + UpdateChildWindows(); + } + + void LayoutManager::NotifyChildOpened(CWnd* pChildWnd) + { + if (Pane* pPane = m_pPane->GetDefaultOpenPane()) + pPane->AddWindow(pChildWnd); + } + + void LayoutManager::NotifyChildClosed(CWnd* pChildWnd) + { + if (Pane* pPane = m_pPane->FindPaneByWindow(pChildWnd)) + pPane->RemoveWindow(pChildWnd); + } + + void LayoutManager::NotifyChildResized(CWnd* pChildWnd) + { + if (m_bInResizing) + return; + Pane* pPane = m_pPane->FindPaneByWindow(pChildWnd); + if (pPane == nullptr) + return; + CRect rc = GetMainRect(); + CRect rcChild = GetChildRect(pChildWnd); + pPane->UpdateSizeRatio(rc, rcChild); + + UpdateChildWindows(); + } + + Pane* LayoutManager::FindPaneByPosition(CPoint& pt) const + { + CRect rc = GetMainRect(); + for (CWnd* pWnd = m_pMDIFrameWnd->MDIGetActive()->GetParent()->GetTopWindow(); pWnd; pWnd = pWnd->GetNextWindow()) + { + if (Pane* pPane = m_pPane->FindPaneByWindow(pWnd)) + { + CRect rcChild = pPane->GetRect(rc); + if (rcChild.left <= pt.x && pt.x < rcChild.right && + rcChild.top <= pt.y && pt.y < rcChild.bottom) + return pPane; + } + } + return nullptr; + } + + Pane* LayoutManager::GetActivePane() const + { + if (CWnd* pWnd = m_pMDIFrameWnd->MDIGetActive()) + return m_pPane->FindPaneByWindow(pWnd); + return nullptr; + } + + void LayoutManager::UpdateChildWindows() + { + if (!m_bEnabled || m_pMDIFrameWnd->MDIGetActive()->GetSafeHwnd() == nullptr) + return; + m_bInResizing = true; + CRect rc = GetMainRect(); + HDWP hdwp = BeginDeferWindowPos(8); + for (CWnd* pWnd = m_pMDIFrameWnd->MDIGetActive()->GetParent()->GetTopWindow(); pWnd; pWnd = pWnd->GetNextWindow()) + { + if (Pane* pPane = m_pPane->FindPaneByWindow(pWnd)) + { + CRect rcChild = pPane->GetRect(rc); + AdjustWindowRectEx(rcChild, pWnd->GetStyle(), false, pWnd->GetExStyle()); + DeferWindowPos(hdwp, pWnd->m_hWnd, nullptr, rcChild.left - rc.left, rcChild.top - rc.top, rcChild.Width(), rcChild.Height(), SWP_NOZORDER); + } + } + EndDeferWindowPos(hdwp); + m_bInResizing = false; + } + + CRect LayoutManager::GetMainRect() const + { + CRect rc; + CWnd *pWnd = m_pMDIFrameWnd->FindWindowEx(m_pMDIFrameWnd->m_hWnd, nullptr, _T("MDIClient"), nullptr); + pWnd->GetWindowRect(rc); + return rc; + } + + CRect LayoutManager::GetChildRect(CWnd* pChildWnd) const + { + CRect rc, rcOuter; + pChildWnd->GetWindowRect(rc); + AdjustWindowRectEx(rcOuter, pChildWnd->GetStyle(), false, pChildWnd->GetExStyle()); + return { rc.left - rcOuter.left, rc.top - rcOuter.top, rc.right - rcOuter.right, rc.bottom - rcOuter.bottom }; + } +} diff --git a/Externals/crystaledit/editlib/utils/MDITileLayout.h b/Externals/crystaledit/editlib/utils/MDITileLayout.h new file mode 100644 index 00000000000..a17ca523641 --- /dev/null +++ b/Externals/crystaledit/editlib/utils/MDITileLayout.h @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: BSL-1.0 +// Copyright (c) 2020 Takashi Sawanaka +// +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#pragma once + +#include +#include +#include + +namespace MDITileLayout +{ + class SplittedLayout; + + class Pane + { + friend SplittedLayout; + public: + Pane(SplittedLayout* pParentSplittedLayout) : m_pParentSplittedLayout(pParentSplittedLayout) {} + bool Split(bool bHorizontal, double ratio); + bool Combine(); + void Tile(bool bHorizontal); + CRect GetRect(const CRect& rcMainWnd) const; + bool IsSplitted() const { return m_pSplittedLayout != nullptr; } + void SetDefaultOpenPane(); + Pane* GetDefaultOpenPane() const; + bool AddWindow(CWnd* pWnd); + bool RemoveWindow(CWnd* pWnd); + bool MoveWindow(Pane *pDstPane, CWnd* pWnd); + Pane* FindPaneByWindow(CWnd* pWnd) const; + void UpdateSizeRatio(const CRect& rcMainWnd, const CRect& rcChildWnd); + + protected: + std::vector m_wndList; + std::unique_ptr m_pSplittedLayout; + SplittedLayout* m_pParentSplittedLayout; + }; + + class SplittedLayout + { + friend Pane; + public: + SplittedLayout(Pane* pParentPane, bool bHorizontal, double ratio, std::vector& wndList); + + protected: + Pane* m_pParentPane = nullptr; + std::unique_ptr m_pPaneFirst; + std::unique_ptr m_pPaneSecond; + bool m_bDefaultOpenPaneIsFirst = false; + bool m_bHorizontal = false; + double m_firstPaneSizeRatio = 0.5; + }; + + class LayoutManager + { + public: + LayoutManager(CMDIFrameWnd* pMDIFrameWnd) : m_pMDIFrameWnd(pMDIFrameWnd), m_pPane(new Pane(nullptr)) {} + void SetTileLayoutEnabled(bool bEnabled); + bool GetTileLayoutEnabled() const { return m_bEnabled; }; + void Tile(bool bHorizontal); + bool SplitActivePane(bool bHorizontal, double ratio); + bool CombineActivePane(); + void SetActivePaneAsDefaultOpenPane(); + CRect GetDefaultOpenPaneRect() const; + void NotifyMainResized(); + void NotifyChildOpened(CWnd* pChlidWnd); + void NotifyChildClosed(CWnd* pChlidWnd); + void NotifyChildResized(CWnd* pChlidWnd); + + protected: + Pane* FindPaneByPosition(CPoint& pt) const; + Pane* GetActivePane() const; + void UpdateChildWindows(); + CRect GetMainRect() const; + CRect GetChildRect(CWnd* pChildWnd) const; + + bool m_bInResizing = false; + bool m_bEnabled = false; + std::unique_ptr m_pPane; + CMDIFrameWnd* m_pMDIFrameWnd = nullptr; + }; +} diff --git a/Externals/poco/Foundation/src/DirectoryIteratorStrategy.cpp b/Externals/poco/Foundation/src/DirectoryIteratorStrategy.cpp index 34b0da8f369..e4f152035b2 100644 --- a/Externals/poco/Foundation/src/DirectoryIteratorStrategy.cpp +++ b/Externals/poco/Foundation/src/DirectoryIteratorStrategy.cpp @@ -61,7 +61,7 @@ const std::string ChildrenFirstTraverse::next(Stack* itStack, bool* isFinished) poco_check_ptr(isFinished); poco_assert(!(*isFinished)); - std::stack it; + //std::stack it; //_depthDeterminer(it); diff --git a/Src/DirFrame.cpp b/Src/DirFrame.cpp index 7b174193e2f..c430b5363e3 100644 --- a/Src/DirFrame.cpp +++ b/Src/DirFrame.cpp @@ -160,7 +160,7 @@ void CDirFrame::ActivateFrame(int nCmdShow) CDockState dockState; dockState.LoadState(_T("Settings-DirFrame")); SetDockState(dockState); - CMergeFrameCommon::ActivateFrame(nCmdShow); + __super::ActivateFrame(nCmdShow); } /** @@ -172,7 +172,7 @@ void CDirFrame::UpdateResources() void CDirFrame::OnClose() { - CMDIChildWnd::OnClose(); + __super::OnClose(); } /** @@ -185,12 +185,12 @@ BOOL CDirFrame::DestroyWindow() GetDockState(dockState); dockState.SaveState(_T("Settings-DirFrame")); SaveWindowState(); - return CMDIChildWnd::DestroyWindow(); + return __super::DestroyWindow(); } void CDirFrame::OnSize(UINT nType, int cx, int cy) { - CMDIChildWnd::OnSize(nType, cx, cy); + __super::OnSize(nType, cx, cy); m_wndFilePathBar.Resize(); } diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index a119da01cb5..db6e95795c7 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -223,6 +223,11 @@ BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::CDpiAwareWnd) ON_UPDATE_COMMAND_UI(ID_NO_MRU, OnUpdateNoMRUs) ON_COMMAND(ID_ACCEL_QUIT, &CMainFrame::OnAccelQuit) ON_MESSAGE(WM_DPICHANGED, OnDpiChanged) + ON_COMMAND_EX(ID_WINDOW_ARRANGE, OnMDIWindowCmd) + ON_COMMAND_EX(ID_WINDOW_CASCADE, OnMDIWindowCmd) + ON_COMMAND_EX(ID_WINDOW_TILE_HORZ, OnMDIWindowCmd) + ON_COMMAND_EX(ID_WINDOW_TILE_VERT, OnMDIWindowCmd) + ON_WM_SIZE() //}}AFX_MSG_MAP ON_MESSAGE(WMU_CHILDFRAMEADDED, &CMainFrame::OnChildFrameAdded) ON_MESSAGE(WMU_CHILDFRAMEREMOVED, &CMainFrame::OnChildFrameRemoved) @@ -270,7 +275,9 @@ CMainFrame::CMainFrame() , m_bShowErrors(false) , m_lfDiff(Options::Font::Load(GetOptionsMgr(), OPT_FONT_FILECMP)) , m_lfDir(Options::Font::Load(GetOptionsMgr(), OPT_FONT_DIRCMP)) +, m_layoutManager(this) { + m_layoutManager.SetTileLayoutEnabled(true); } CMainFrame::~CMainFrame() @@ -2656,6 +2663,12 @@ void CMainFrame::OnAccelQuit() SendMessage(WM_CLOSE); } +void CMainFrame::OnSize(UINT nType, int cx, int cy) +{ + __super::OnSize(nType, cx, cy); + m_layoutManager.NotifyMainResized(); +} + LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { int olddpi = m_dpi; @@ -2683,6 +2696,8 @@ LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) LRESULT CMainFrame::OnChildFrameAdded(WPARAM wParam, LPARAM lParam) { + m_layoutManager.NotifyChildOpened(reinterpret_cast(lParam)); + for (int i = 0; i < m_arrChild.GetSize(); ++i) { if (reinterpret_cast(lParam) == m_arrChild.GetAt(i)) @@ -2698,6 +2713,8 @@ LRESULT CMainFrame::OnChildFrameAdded(WPARAM wParam, LPARAM lParam) LRESULT CMainFrame::OnChildFrameRemoved(WPARAM wParam, LPARAM lParam) { + m_layoutManager.NotifyChildClosed(reinterpret_cast(lParam)); + for (int i = 0; i < m_arrChild.GetSize(); ++i) { if (reinterpret_cast(lParam) == m_arrChild.GetAt(i)) @@ -2742,3 +2759,24 @@ LRESULT CMainFrame::OnChildFrameActivated(WPARAM wParam, LPARAM lParam) return 1; } + +BOOL CMainFrame::OnMDIWindowCmd(UINT nID) +{ + switch (nID) + { + case ID_WINDOW_TILE_HORZ: + case ID_WINDOW_TILE_VERT: + { + bool bHorizontal = (nID == ID_WINDOW_TILE_HORZ); + m_layoutManager.SetTileLayoutEnabled(true); + m_layoutManager.Tile(bHorizontal); + break; + } + case ID_WINDOW_CASCADE: + m_layoutManager.SetTileLayoutEnabled(false); + __super::OnMDIWindowCmd(nID); + break; + } + return 0; +} + diff --git a/Src/MainFrm.h b/Src/MainFrm.h index ac05304510a..8f52c425c7d 100644 --- a/Src/MainFrm.h +++ b/Src/MainFrm.h @@ -18,6 +18,7 @@ #include "OptionsDef.h" #include "OptionsMgr.h" #include "utils/DpiAware.h" +#include "utils/MDITileLayout.h" class BCMenu; class CDirView; @@ -112,6 +113,7 @@ class CMainFrame : public DpiAware::CDpiAwareWnd void ReloadMenu(); DropHandler *GetDropHandler() const { return m_pDropHandler; } const CTypedPtrArray* GetChildArray() const { return &m_arrChild; } + MDITileLayout::LayoutManager& GetLayoutManager() { return m_layoutManager; }; // Overrides virtual void GetMessageString(UINT nID, CString& rMessage) const; @@ -141,6 +143,7 @@ class CMainFrame : public DpiAware::CDpiAwareWnd CToolBar m_wndToolBar; CMDITabBar m_wndTabBar; CTypedPtrArray m_arrChild; + MDITileLayout::LayoutManager m_layoutManager; // Tweak MDI client window behavior class CMDIClient : public DpiAware::CDpiAwareWnd @@ -230,6 +233,7 @@ class CMainFrame : public DpiAware::CDpiAwareWnd std::vector m_tempFiles; /**< List of possibly needed temp files. */ DropHandler *m_pDropHandler; + // Generated message map functions protected: //{{AFX_MSG(CMainFrame) @@ -298,7 +302,9 @@ class CMainFrame : public DpiAware::CDpiAwareWnd afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnDestroy(); afx_msg void OnAccelQuit(); + afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); + afx_msg BOOL OnMDIWindowCmd(UINT nID); //}}AFX_MSG afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam); diff --git a/Src/Merge.vs2017.vcxproj b/Src/Merge.vs2017.vcxproj index d8ac2d7303e..49811d3f039 100644 --- a/Src/Merge.vs2017.vcxproj +++ b/Src/Merge.vs2017.vcxproj @@ -501,6 +501,7 @@ + @@ -1116,6 +1117,7 @@ + diff --git a/Src/Merge.vs2017.vcxproj.filters b/Src/Merge.vs2017.vcxproj.filters index aa08bb5ff8a..404f20cedc6 100644 --- a/Src/Merge.vs2017.vcxproj.filters +++ b/Src/Merge.vs2017.vcxproj.filters @@ -919,6 +919,9 @@ EditLib\Utils + + EditLib\Utils + @@ -1656,6 +1659,9 @@ EditLib\Utils + + EditLib\Utils + diff --git a/Src/Merge.vs2019.vcxproj b/Src/Merge.vs2019.vcxproj index bac44a37a55..5e8abc2a17a 100644 --- a/Src/Merge.vs2019.vcxproj +++ b/Src/Merge.vs2019.vcxproj @@ -500,6 +500,7 @@ + @@ -1115,6 +1116,7 @@ + diff --git a/Src/Merge.vs2019.vcxproj.filters b/Src/Merge.vs2019.vcxproj.filters index aa08bb5ff8a..404f20cedc6 100644 --- a/Src/Merge.vs2019.vcxproj.filters +++ b/Src/Merge.vs2019.vcxproj.filters @@ -919,6 +919,9 @@ EditLib\Utils + + EditLib\Utils + @@ -1656,6 +1659,9 @@ EditLib\Utils + + EditLib\Utils + diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index a7bd488a37d..83898b050c8 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -10,6 +10,7 @@ #include "OptionsMgr.h" #include "utils/DpiAware.h" #include "Merge.h" +#include "MainFrm.h" #include <../src/mfc/afximpl.h> IMPLEMENT_DYNCREATE(CMergeFrameCommon, CMDIChildWnd) @@ -38,6 +39,27 @@ CMergeFrameCommon::~CMergeFrameCommon() ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEREMOVED, 0, reinterpret_cast(this)); } +BOOL CMergeFrameCommon::PreCreateWindow(CREATESTRUCT& cs) +{ + // TODO: Modify the Window class or styles here by modifying + // the CREATESTRUCT cs + MDITileLayout::LayoutManager& layoutManager = static_cast(AfxGetMainWnd())->GetLayoutManager(); + if (!layoutManager.GetTileLayoutEnabled()) + return __super::PreCreateWindow(cs); + __super::PreCreateWindow(cs); + cs.style &= ~WS_CAPTION; + CRect rcMain; + CWnd* pWndMDIClient = AfxGetMainWnd()->FindWindowEx(AfxGetMainWnd()->m_hWnd, nullptr, _T("MDIClient"), nullptr); + pWndMDIClient->GetWindowRect(rcMain); + CRect rc = layoutManager.GetDefaultOpenPaneRect(); + AdjustWindowRectEx(rc, cs.style, false, cs.dwExStyle); + cs.x = rc.left - rcMain.left; + cs.y = rc.top - rcMain.top; + cs.cx = rc.Width(); + cs.cy = rc.Height(); + return true; +} + void CMergeFrameCommon::ActivateFrame(int nCmdShow) { if (!m_bActivated) @@ -125,6 +147,7 @@ void CMergeFrameCommon::OnSize(UINT nType, int cx, int cy) AdjustWindowRectEx(&rc, GetStyle(), FALSE, GetExStyle()); SetWindowPos(nullptr, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOACTIVATE); } + GetMainFrame()->GetLayoutManager().NotifyChildResized(this); } void CMergeFrameCommon::OnDestroy() diff --git a/Src/MergeFrameCommon.h b/Src/MergeFrameCommon.h index f78493e3481..b6d508ab6f0 100644 --- a/Src/MergeFrameCommon.h +++ b/Src/MergeFrameCommon.h @@ -19,6 +19,7 @@ class CMergeFrameCommon: public DpiAware::CDpiAwareWnd void SaveWindowState(); void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; } void RemoveBarBorder(); + virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual BOOL IsTabbedMDIChild() { return TRUE; // https://stackoverflow.com/questions/35553955/getting-rid-of-3d-look-of-mdi-frame-window diff --git a/Src/OpenFrm.cpp b/Src/OpenFrm.cpp index 7ef34cb6c45..ab326d55765 100644 --- a/Src/OpenFrm.cpp +++ b/Src/OpenFrm.cpp @@ -5,6 +5,7 @@ #include "OptionsDef.h" #include "OptionsMgr.h" #include "MergeFrameCommon.h" +#include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -39,7 +40,7 @@ COpenFrame::~COpenFrame() BOOL COpenFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying the CREATESTRUCT cs - if( !CMDIChildWnd::PreCreateWindow(cs) ) + if( !__super::PreCreateWindow(cs) ) return FALSE; cs.style |= WS_CLIPCHILDREN; return TRUE; @@ -74,7 +75,8 @@ LRESULT COpenFrame::OnNcHitTest(CPoint point) void COpenFrame::OnWindowPosChanging(WINDOWPOS* lpwndpos) { // Retain frame sizes during tile operations (tolerate overlapping) - if ((lpwndpos->flags & (SWP_NOSIZE | SWP_NOOWNERZORDER)) == 0 && !IsZoomed()) + if ((lpwndpos->flags & (SWP_NOSIZE | SWP_NOOWNERZORDER)) == 0 && !IsZoomed() && + !GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled()) { if (CScrollView *const pView = static_cast(GetActiveView())) { @@ -89,7 +91,7 @@ void COpenFrame::OnWindowPosChanging(WINDOWPOS* lpwndpos) void COpenFrame::ActivateFrame(int nCmdShow) { - CMergeFrameCommon::ActivateFrame(nCmdShow); + __super::ActivateFrame(nCmdShow); if (CView *const pView = GetActiveView()) { WINDOWPLACEMENT wp; @@ -118,7 +120,7 @@ void COpenFrame::UpdateResources() BOOL COpenFrame::DestroyWindow() { SaveWindowState(); - return CMDIChildWnd::DestroyWindow(); + return __super::DestroyWindow(); } // COpenFrame message handlers diff --git a/Src/OpenView.cpp b/Src/OpenView.cpp index fe1857ab08b..0c234c01a0b 100644 --- a/Src/OpenView.cpp +++ b/Src/OpenView.cpp @@ -404,7 +404,7 @@ void COpenView::OnMouseMove(UINT nFlags, CPoint point) void COpenView::OnWindowPosChanging(WINDOWPOS* lpwndpos) { - if ((lpwndpos->flags & (SWP_NOMOVE | SWP_NOSIZE)) == 0) + if ((lpwndpos->flags & (SWP_NOMOVE | SWP_NOSIZE)) == 0 && !GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled()) { CFrameWnd *const pFrameWnd = GetParentFrame(); if (pFrameWnd == GetTopLevelFrame()->GetActiveFrame()) From 3e3929c1054c75197a1605c63388fe5d2fbe589b Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Thu, 24 Sep 2020 21:02:12 +0900 Subject: [PATCH 16/23] WIP: Add support for per-monitor DPI awareness (16) --- Externals/crystaledit/Sample/ChildFrm.cpp | 13 +++++----- .../crystaledit/editlib/ccrystaltextview.cpp | 16 ++++++------ .../crystaledit/editlib/ccrystaltextview.h | 5 ++++ .../editlib/renderers/ccrystalrenderer.h | 9 +++---- .../renderers/ccrystalrendererdirectwrite.cpp | 6 ++--- .../renderers/ccrystalrendererdirectwrite.h | 2 +- .../editlib/renderers/ccrystalrenderergdi.cpp | 23 +++++++++++------- .../editlib/renderers/ccrystalrenderergdi.h | 4 +-- .../editlib/utils/MDITileLayout.cpp | 20 ++++++++++++--- Src/Merge.rc | 3 +++ Src/MergeFrameCommon.cpp | 12 ++++----- Src/res/ToolbarEnabled32.bmp | Bin 65526 -> 65526 bytes 12 files changed, 68 insertions(+), 45 deletions(-) diff --git a/Externals/crystaledit/Sample/ChildFrm.cpp b/Externals/crystaledit/Sample/ChildFrm.cpp index 256ae02639e..c070398f722 100755 --- a/Externals/crystaledit/Sample/ChildFrm.cpp +++ b/Externals/crystaledit/Sample/ChildFrm.cpp @@ -43,18 +43,19 @@ BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs - MDITileLayout::LayoutManager& layoutManager = static_cast(AfxGetMainWnd())->GetLayoutManager(); + CMainFrame* pMainFrame = static_cast(AfxGetMainWnd()); + MDITileLayout::LayoutManager& layoutManager = pMainFrame->GetLayoutManager(); if (!layoutManager.GetTileLayoutEnabled()) return __super::PreCreateWindow(cs); __super::PreCreateWindow(cs); cs.style &= ~WS_CAPTION; - CRect rcMain; - CWnd* pWndMDIClient = AfxGetMainWnd()->FindWindowEx(AfxGetMainWnd()->m_hWnd, nullptr, _T("MDIClient"), nullptr); - pWndMDIClient->GetWindowRect(rcMain); CRect rc = layoutManager.GetDefaultOpenPaneRect(); + rc.right -= rc.left; + rc.bottom -= rc.top; + rc.left = rc.top = 0; AdjustWindowRectEx(rc, cs.style, false, cs.dwExStyle); - cs.x = rc.left - rcMain.left; - cs.y = rc.top - rcMain.top; + cs.x = rc.left - rc.left; + cs.y = rc.top - rc.top; cs.cx = rc.Width(); cs.cy = rc.Height(); return true; diff --git a/Externals/crystaledit/editlib/ccrystaltextview.cpp b/Externals/crystaledit/editlib/ccrystaltextview.cpp index bb07f57e6c4..66b703f22d9 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview.cpp @@ -145,10 +145,6 @@ using CrystalLineParser::TEXTBLOCK; /** @brief Width of revision marks. */ const UINT MARGIN_REV_WIDTH = 3; -/** @brief Width of icons printed in the margin. */ -const UINT MARGIN_ICON_WIDTH = 12; -/** @brief Height of icons printed in the margin. */ -const UINT MARGIN_ICON_HEIGHT = 12; /** @brief Color of unsaved line revision mark (dark yellow). */ const COLORREF UNSAVED_REVMARK_CLR = RGB(0xD7, 0xD7, 0x00); @@ -2481,20 +2477,22 @@ DrawMargin (const CRect & rect, int nLineIndex, int nLineNumber) } if (nImageIndex >= 0) { + const int iconsize = GetMarginIconSize(); m_pCrystalRenderer->DrawMarginIcon( - rect.left + 2, rect.top + (GetLineHeight() - CCrystalRenderer::MARGIN_ICON_HEIGHT) / 2, nImageIndex); + rect.left + 2, rect.top + (GetLineHeight() - iconsize) / 2, nImageIndex, iconsize); } // draw wrapped-line-icon if (nLineNumber > 0) { + const int iconsize = GetMarginIconSize(); int nBreaks = 0; WrapLineCached( nLineIndex, GetScreenChars(), nullptr, nBreaks ); for (int i = 0; i < nBreaks; i++) { m_pCrystalRenderer->DrawMarginIcon( - rect.right - CCrystalRenderer::MARGIN_ICON_WIDTH, rect.top + (GetLineHeight() - - CCrystalRenderer::MARGIN_ICON_WIDTH) / 2 + (i+1) * GetLineHeight(), ICON_INDEX_WRAPLINE); + rect.right - iconsize, rect.top + (GetLineHeight() + - iconsize) / 2 + (i+1) * GetLineHeight(), ICON_INDEX_WRAPLINE, iconsize); } } } @@ -6263,8 +6261,8 @@ GetMarginWidth (CDC *pdc /*= nullptr*/) if (m_bSelMargin) { - if (pdc == nullptr || !pdc->IsPrinting ()) - nMarginWidth += MARGIN_ICON_WIDTH + 7; // Width for icon markers and some margin + if (pdc == nullptr || !pdc->IsPrinting()) + nMarginWidth += GetMarginIconSize() + 7; // Width for icon markers and some margin } else { diff --git a/Externals/crystaledit/editlib/ccrystaltextview.h b/Externals/crystaledit/editlib/ccrystaltextview.h index fc30d0de592..cdf8686933f 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.h +++ b/Externals/crystaledit/editlib/ccrystaltextview.h @@ -516,6 +516,11 @@ protected : #endif } + int GetMarginIconSize() const + { + return MulDiv(CCrystalRenderer::MARGIN_ICON_SIZE, m_dpi, USER_DEFAULT_SCREEN_DPI); + } + #ifdef _UNICODE bool m_bChWidthsCalculated[65536/256]; int m_iChDoubleWidthFlags[65536/32]; diff --git a/Externals/crystaledit/editlib/renderers/ccrystalrenderer.h b/Externals/crystaledit/editlib/renderers/ccrystalrenderer.h index 8d0aaab1ae6..467b260d2db 100644 --- a/Externals/crystaledit/editlib/renderers/ccrystalrenderer.h +++ b/Externals/crystaledit/editlib/renderers/ccrystalrenderer.h @@ -16,10 +16,9 @@ struct CCrystalRenderer { - /** @brief Width of icons printed in the margin. */ - static const UINT MARGIN_ICON_WIDTH = 12; - /** @brief Height of icons printed in the margin. */ - static const UINT MARGIN_ICON_HEIGHT = 12; + /** @brief size of icons printed in the margin. */ + static const UINT MARGIN_ICON_SIZE = 12; + static const UINT MARGIN_ICON_COUNT = 16; virtual ~CCrystalRenderer() {}; @@ -38,7 +37,7 @@ struct CCrystalRenderer virtual void DrawRoundRectangle(int left, int top , int right, int bottom, int width, int height) = 0; virtual void PushAxisAlignedClip(const CRect &rc) = 0; virtual void PopAxisAlignedClip() = 0; - virtual void DrawMarginIcon(int x, int y, int iconIndex) = 0; + virtual void DrawMarginIcon(int x, int y, int iconIndex, int iconsize) = 0; virtual void DrawMarginLineNumber(int x, int y, int number) = 0; virtual void DrawBoundaryLine(int left, int right, int y) = 0; virtual void DrawGridLine(int x1, int y1, int x2, int y2) = 0; diff --git a/Externals/crystaledit/editlib/renderers/ccrystalrendererdirectwrite.cpp b/Externals/crystaledit/editlib/renderers/ccrystalrendererdirectwrite.cpp index 1c44e28d8a1..67a7f8fae9d 100644 --- a/Externals/crystaledit/editlib/renderers/ccrystalrendererdirectwrite.cpp +++ b/Externals/crystaledit/editlib/renderers/ccrystalrendererdirectwrite.cpp @@ -387,7 +387,7 @@ void CCrystalRendererDirectWrite::PopAxisAlignedClip() m_renderTarget.PopAxisAlignedClip(); } -void CCrystalRendererDirectWrite::DrawMarginIcon(int x, int y, int iconIndex) +void CCrystalRendererDirectWrite::DrawMarginIcon(int x, int y, int iconIndex, int iconsize) { if (!m_pIconBitmap) { @@ -395,10 +395,10 @@ void CCrystalRendererDirectWrite::DrawMarginIcon(int x, int y, int iconIndex) m_pIconBitmap->Create(&m_renderTarget); } auto size = m_pIconBitmap->GetPixelSize(); - CD2DRectF rcSrc{static_cast(iconIndex * MARGIN_ICON_WIDTH), 0.0f, static_cast((iconIndex + 1) * MARGIN_ICON_WIDTH), static_cast(MARGIN_ICON_HEIGHT)}; + CD2DRectF rcSrc{static_cast(iconIndex * MARGIN_ICON_SIZE), 0.0f, static_cast((iconIndex + 1) * MARGIN_ICON_SIZE), static_cast(MARGIN_ICON_SIZE)}; m_renderTarget.DrawBitmap(m_pIconBitmap.get(), { static_cast(x), static_cast(y), - static_cast(x + MARGIN_ICON_WIDTH), static_cast(y + MARGIN_ICON_HEIGHT) }, + static_cast(x + iconsize), static_cast(y + iconsize) }, 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, &rcSrc); } diff --git a/Externals/crystaledit/editlib/renderers/ccrystalrendererdirectwrite.h b/Externals/crystaledit/editlib/renderers/ccrystalrendererdirectwrite.h index 297abbd520f..8deadbffcfa 100644 --- a/Externals/crystaledit/editlib/renderers/ccrystalrendererdirectwrite.h +++ b/Externals/crystaledit/editlib/renderers/ccrystalrendererdirectwrite.h @@ -38,7 +38,7 @@ class CCrystalRendererDirectWrite : public CCrystalRenderer virtual void DrawRoundRectangle(int left, int top , int right, int bottom, int width, int height) override; virtual void PushAxisAlignedClip(const CRect &rc) override; virtual void PopAxisAlignedClip() override; - virtual void DrawMarginIcon(int x, int y, int iconIndex) override; + virtual void DrawMarginIcon(int x, int y, int iconIndex, int iconsize) override; virtual void DrawMarginLineNumber(int x, int y, int number) override; virtual void DrawBoundaryLine(int left, int right, int y) override; virtual void DrawGridLine(int x1, int y1, int x2, int y2) override; diff --git a/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.cpp b/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.cpp index 2e774567260..e258f5c90a1 100644 --- a/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.cpp +++ b/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.cpp @@ -7,8 +7,9 @@ #include "StdAfx.h" #include "ccrystalrenderergdi.h" #include "resource.h" +#include -CImageList* CCrystalRendererGDI::s_pIcons = nullptr; +std::map> CCrystalRendererGDI::s_mapIcons; ///////////////////////////////////////////////////////////////////////////// // CCrystalRendererGDI construction/destruction @@ -139,21 +140,25 @@ void CCrystalRendererGDI::PopAxisAlignedClip() m_pDC->RestoreDC(-1); } -void CCrystalRendererGDI::DrawMarginIcon(int x, int y, int iconIndex) +void CCrystalRendererGDI::DrawMarginIcon(int x, int y, int iconIndex, int iconsize) { - if (s_pIcons == nullptr) + const int iconsize2 = (iconsize / MARGIN_ICON_SIZE) * MARGIN_ICON_SIZE; + CImageList* pIcons = nullptr; + if (s_mapIcons.find(iconsize2) == s_mapIcons.end()) { - s_pIcons = new CImageList; - VERIFY(s_pIcons->Create(MARGIN_ICON_WIDTH, MARGIN_ICON_HEIGHT, + s_mapIcons.emplace(iconsize2, new CImageList); + pIcons = s_mapIcons[iconsize2].get(); + VERIFY(pIcons->Create(iconsize2, iconsize2, ILC_COLOR32 | ILC_MASK, 0, 1)); CBitmap bmp; - bmp.LoadBitmap(IDR_MARGIN_ICONS); - s_pIcons->Add(&bmp, RGB(255, 255, 255)); + bmp.Attach(LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MARGIN_ICONS), IMAGE_BITMAP, + iconsize2 * MARGIN_ICON_COUNT, iconsize2, LR_CREATEDIBSECTION)); + pIcons->Add(&bmp, RGB(255, 255, 255)); } if (iconIndex >= 0) { - CPoint pt(x, y); - VERIFY(s_pIcons->Draw(m_pDC, iconIndex, pt, ILD_TRANSPARENT)); + CPoint pt(x + (iconsize - iconsize2) / 2, y + (iconsize - iconsize2) / 2); + VERIFY(s_mapIcons[iconsize2]->Draw(m_pDC, iconIndex, pt, ILD_TRANSPARENT)); } } diff --git a/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.h b/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.h index 3b51fecdd97..180de84241b 100644 --- a/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.h +++ b/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.h @@ -38,7 +38,7 @@ class CCrystalRendererGDI : public CCrystalRenderer virtual void DrawRoundRectangle(int left, int top , int right, int bottom, int width, int height) override; virtual void PushAxisAlignedClip(const CRect &rc) override; virtual void PopAxisAlignedClip() override; - virtual void DrawMarginIcon(int x, int y, int iconIndex) override; + virtual void DrawMarginIcon(int x, int y, int iconIndex,int iconsize) override; virtual void DrawMarginLineNumber(int x, int y, int number) override; virtual void DrawBoundaryLine(int left, int right, int y) override; virtual void DrawGridLine(int x1, int y1, int x2, int y2) override; @@ -50,5 +50,5 @@ class CCrystalRendererGDI : public CCrystalRenderer LOGFONT m_lfBaseFont; CPen m_gridPen; std::array, 4> m_apFonts; - static CImageList *s_pIcons; + static std::map> s_mapIcons; }; diff --git a/Externals/crystaledit/editlib/utils/MDITileLayout.cpp b/Externals/crystaledit/editlib/utils/MDITileLayout.cpp index 4584eb92244..4ac45f6e354 100644 --- a/Externals/crystaledit/editlib/utils/MDITileLayout.cpp +++ b/Externals/crystaledit/editlib/utils/MDITileLayout.cpp @@ -7,6 +7,7 @@ #include "StdAfx.h" #include "MDITileLayout.h" +#include "DpiAware.h" namespace MDITileLayout { @@ -388,14 +389,24 @@ namespace MDITileLayout return; m_bInResizing = true; CRect rc = GetMainRect(); + CWnd* pWndMDIClient = CWnd::FromHandle(m_pMDIFrameWnd->m_hWndMDIClient); + const int dpi = DpiAware::GetDpiForWindow(m_pMDIFrameWnd->m_hWndMDIClient); + CRect rcMainMargin; + DpiAware::AdjustWindowRectExForDpi(rcMainMargin, pWndMDIClient->GetStyle(), false, pWndMDIClient->GetExStyle(), dpi); HDWP hdwp = BeginDeferWindowPos(8); for (CWnd* pWnd = m_pMDIFrameWnd->MDIGetActive()->GetParent()->GetTopWindow(); pWnd; pWnd = pWnd->GetNextWindow()) { if (Pane* pPane = m_pPane->FindPaneByWindow(pWnd)) { CRect rcChild = pPane->GetRect(rc); - AdjustWindowRectEx(rcChild, pWnd->GetStyle(), false, pWnd->GetExStyle()); - DeferWindowPos(hdwp, pWnd->m_hWnd, nullptr, rcChild.left - rc.left, rcChild.top - rc.top, rcChild.Width(), rcChild.Height(), SWP_NOZORDER); + CRect rcChildOrg = rcChild; + DpiAware::AdjustWindowRectExForDpi(rcChild, pWnd->GetStyle(), false, pWnd->GetExStyle(), dpi); + rcChild.right = rcChildOrg.right; + rcChild.bottom = rcChildOrg.bottom; + DeferWindowPos(hdwp, pWnd->m_hWnd, nullptr, + rcChild.left - rc.left + rcMainMargin.left, + rcChild.top - rc.top + rcMainMargin.top, + rcChild.Width(), rcChild.Height(), SWP_NOZORDER); } } EndDeferWindowPos(hdwp); @@ -405,16 +416,17 @@ namespace MDITileLayout CRect LayoutManager::GetMainRect() const { CRect rc; - CWnd *pWnd = m_pMDIFrameWnd->FindWindowEx(m_pMDIFrameWnd->m_hWnd, nullptr, _T("MDIClient"), nullptr); + CWnd *pWnd = CWnd::FromHandle(m_pMDIFrameWnd->m_hWndMDIClient); pWnd->GetWindowRect(rc); return rc; } CRect LayoutManager::GetChildRect(CWnd* pChildWnd) const { + const int dpi = DpiAware::GetDpiForWindow(pChildWnd->m_hWnd); CRect rc, rcOuter; pChildWnd->GetWindowRect(rc); - AdjustWindowRectEx(rcOuter, pChildWnd->GetStyle(), false, pChildWnd->GetExStyle()); + DpiAware::AdjustWindowRectExForDpi(rcOuter, pChildWnd->GetStyle(), false, pChildWnd->GetExStyle(), dpi); return { rc.left - rcOuter.left, rc.top - rcOuter.top, rc.right - rcOuter.right, rc.bottom - rcOuter.bottom }; } } diff --git a/Src/Merge.rc b/Src/Merge.rc index b083f4fca1c..0071799fcd2 100644 --- a/Src/Merge.rc +++ b/Src/Merge.rc @@ -230,6 +230,7 @@ BEGIN BEGIN MENUITEM "Cl&ose", ID_FILE_CLOSE MENUITEM "Clo&se All", ID_WINDOW_CLOSEALL + MENUITEM "New Window", ID_WINDOW_NEW MENUITEM SEPARATOR MENUITEM "Change &Pane\tF6", ID_WINDOW_CHANGE_PANE MENUITEM SEPARATOR @@ -371,6 +372,7 @@ BEGIN BEGIN MENUITEM "Cl&ose", ID_FILE_CLOSE MENUITEM "Clo&se All", ID_WINDOW_CLOSEALL + MENUITEM "New Window", ID_WINDOW_NEW MENUITEM SEPARATOR MENUITEM "Change &Pane\tF6", ID_WINDOW_CHANGE_PANE MENUITEM SEPARATOR @@ -624,6 +626,7 @@ BEGIN BEGIN MENUITEM "Cl&ose", ID_FILE_CLOSE MENUITEM "Clo&se All", ID_WINDOW_CLOSEALL + MENUITEM "New Window", ID_WINDOW_NEW MENUITEM SEPARATOR MENUITEM "Change &Pane\tF6", ID_WINDOW_CHANGE_PANE MENUITEM SEPARATOR diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index 83898b050c8..6c4520bd5dc 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -43,18 +43,18 @@ BOOL CMergeFrameCommon::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs - MDITileLayout::LayoutManager& layoutManager = static_cast(AfxGetMainWnd())->GetLayoutManager(); + MDITileLayout::LayoutManager& layoutManager = GetMainFrame()->GetLayoutManager(); if (!layoutManager.GetTileLayoutEnabled()) return __super::PreCreateWindow(cs); __super::PreCreateWindow(cs); cs.style &= ~WS_CAPTION; - CRect rcMain; - CWnd* pWndMDIClient = AfxGetMainWnd()->FindWindowEx(AfxGetMainWnd()->m_hWnd, nullptr, _T("MDIClient"), nullptr); - pWndMDIClient->GetWindowRect(rcMain); CRect rc = layoutManager.GetDefaultOpenPaneRect(); + rc.right -= rc.left; + rc.bottom -= rc.top; + rc.left = rc.top = 0; AdjustWindowRectEx(rc, cs.style, false, cs.dwExStyle); - cs.x = rc.left - rcMain.left; - cs.y = rc.top - rcMain.top; + cs.x = rc.left; + cs.y = rc.top; cs.cx = rc.Width(); cs.cy = rc.Height(); return true; diff --git a/Src/res/ToolbarEnabled32.bmp b/Src/res/ToolbarEnabled32.bmp index 90aea8e7e02f394f072ee638a0ff20af1f239b26..2fe41ec1972fb1dae3d91dd44feb2ae50cbfdf38 100644 GIT binary patch delta 155 zcmezNpZVK=<_SuC2mUiK2ysI&1H|8ilN0xg@<3!hU)c&oo4MDEaj*dyw@XEVlG2<&Ngxv>E0g3`yK>nxG%Qthc7vo^QT`D>`alhQ;1=egJ_Ga(xyd0djD Date: Fri, 25 Sep 2020 23:14:56 +0900 Subject: [PATCH 17/23] WIP: Add support for per-monitor DPI awareness (17) --- Externals/crystaledit/Sample/MainFrm.cpp | 24 ++- Externals/crystaledit/Sample/Sample.cpp | 2 + Externals/crystaledit/Sample/Sample.h | 3 + .../Sample/SampleStatic.vs2017.vcxproj | 2 + .../SampleStatic.vs2017.vcxproj.filters | 11 +- .../Sample/SampleStatic.vs2019.vcxproj | 2 + .../SampleStatic.vs2019.vcxproj.filters | 6 + .../crystaledit/editlib/ccrystaltextview.cpp | 4 +- .../editlib/renderers/ccrystalrenderergdi.cpp | 21 ++- .../crystaledit/editlib/utils/hqbitmap.cpp | 159 ++++++++++++++++++ .../crystaledit/editlib/utils/hqbitmap.h | 3 + Src/MainFrm.cpp | 95 +---------- Src/Merge.vs2017.vcxproj | 2 + Src/Merge.vs2017.vcxproj.filters | 6 + Src/Merge.vs2019.vcxproj | 2 + Src/Merge.vs2019.vcxproj.filters | 6 + 16 files changed, 232 insertions(+), 116 deletions(-) create mode 100644 Externals/crystaledit/editlib/utils/hqbitmap.cpp create mode 100644 Externals/crystaledit/editlib/utils/hqbitmap.h diff --git a/Externals/crystaledit/Sample/MainFrm.cpp b/Externals/crystaledit/Sample/MainFrm.cpp index 3796f21e10f..cbc9f403ea4 100755 --- a/Externals/crystaledit/Sample/MainFrm.cpp +++ b/Externals/crystaledit/Sample/MainFrm.cpp @@ -6,7 +6,7 @@ #include "MainFrm.h" #include "ceditcmd.h" -#include +#include "utils/hqbitmap.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -106,20 +106,18 @@ BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) BOOL CMainFrame::LoadToolBar() { + const int ICON_COUNT = 17; m_wndToolBar.LoadToolBar(IDR_MAINFRAME); CToolBarCtrl& toolbarCtrl = m_wndToolBar.GetToolBarCtrl(); - int cx = 16; - int cy = 15; - m_imgListToolBar.DeleteImageList(); - m_imgListToolBar.Create(IDR_MAINFRAME, cx, 0, RGB(192, 192, 192)); - CComQIPtr pImageList2(reinterpret_cast(m_imgListToolBar.m_hImageList)); - if (pImageList2) - { - cx = MulDiv(16, m_dpi, USER_DEFAULT_SCREEN_DPI); - cy = MulDiv(15, m_dpi, USER_DEFAULT_SCREEN_DPI); - HRESULT hr = pImageList2->Resize(cx, cy); - } - toolbarCtrl.SetImageList(&m_imgListToolBar); + const int cx = MulDiv(16, m_dpi, USER_DEFAULT_SCREEN_DPI); + const int cy = MulDiv(15, m_dpi, USER_DEFAULT_SCREEN_DPI); + m_imgListToolBar.Detach(); + m_imgListToolBar.Create(cx, cy, ILC_COLOR32, ICON_COUNT, 0); + CBitmap bm; + bm.Attach(LoadBitmapAndConvertTo32bit(AfxGetInstanceHandle(), IDR_MAINFRAME, 16 * ICON_COUNT, 15, cx * ICON_COUNT, cy, false, RGB(0xc0, 0xc0, 0xc0))); + m_imgListToolBar.Add(&bm, nullptr); + if (CImageList* pImgList = toolbarCtrl.SetImageList(&m_imgListToolBar)) + pImgList->DeleteImageList(); toolbarCtrl.SetButtonSize({ cx + 8, cy + 8 }); return TRUE; } diff --git a/Externals/crystaledit/Sample/Sample.cpp b/Externals/crystaledit/Sample/Sample.cpp index e01724031be..ef74562a31f 100755 --- a/Externals/crystaledit/Sample/Sample.cpp +++ b/Externals/crystaledit/Sample/Sample.cpp @@ -56,6 +56,8 @@ BOOL CSampleApp::InitInstance() // of your final executable, you should remove from the following // the specific initialization routines you do not need. + m_imageForInitializingGdipllus.Load((IStream *)nullptr); + // initialized OLE 2.0 libraries if (!AfxOleInit()) { diff --git a/Externals/crystaledit/Sample/Sample.h b/Externals/crystaledit/Sample/Sample.h index 39b0b59eb23..b6b7101ec9b 100755 --- a/Externals/crystaledit/Sample/Sample.h +++ b/Externals/crystaledit/Sample/Sample.h @@ -8,6 +8,7 @@ #endif #include "resource.h" // main symbols +#include ///////////////////////////////////////////////////////////////////////////// // CSampleApp: @@ -34,6 +35,8 @@ class CSampleApp : public CWinApp // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG DECLARE_MESSAGE_MAP() + + ATL::CImage m_imageForInitializingGdipllus; }; diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj b/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj index 7fd708f12dd..00114435448 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj +++ b/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj @@ -568,6 +568,7 @@ + @@ -644,6 +645,7 @@ + diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj.filters b/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj.filters index 0abd6c6394b..0faf46a7128 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj.filters +++ b/Externals/crystaledit/Sample/SampleStatic.vs2017.vcxproj.filters @@ -255,6 +255,12 @@ editlib\utils + + editlib\utils + + + editlib\utils + @@ -385,7 +391,10 @@ editlib\utils - + + editlib\utils + + editlib\utils diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj index e14658036a5..9be49d0cd39 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj +++ b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj @@ -567,6 +567,7 @@ + @@ -643,6 +644,7 @@ + diff --git a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters index c3c3600bca6..7bdf5983052 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters +++ b/Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj.filters @@ -258,6 +258,9 @@ editlib\utils + + editlib\utils + @@ -391,6 +394,9 @@ editlib\utils + + editlib\utils + diff --git a/Externals/crystaledit/editlib/ccrystaltextview.cpp b/Externals/crystaledit/editlib/ccrystaltextview.cpp index 66b703f22d9..21efa5d567e 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview.cpp @@ -6261,8 +6261,8 @@ GetMarginWidth (CDC *pdc /*= nullptr*/) if (m_bSelMargin) { - if (pdc == nullptr || !pdc->IsPrinting()) - nMarginWidth += GetMarginIconSize() + 7; // Width for icon markers and some margin + if (pdc == nullptr || !pdc->IsPrinting ()) + nMarginWidth += GetMarginIconSize () + 7; // Width for icon markers and some margin } else { diff --git a/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.cpp b/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.cpp index e258f5c90a1..f79231c6940 100644 --- a/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.cpp +++ b/Externals/crystaledit/editlib/renderers/ccrystalrenderergdi.cpp @@ -6,8 +6,8 @@ #include "StdAfx.h" #include "ccrystalrenderergdi.h" +#include "utils/hqbitmap.h" #include "resource.h" -#include std::map> CCrystalRendererGDI::s_mapIcons; @@ -142,23 +142,22 @@ void CCrystalRendererGDI::PopAxisAlignedClip() void CCrystalRendererGDI::DrawMarginIcon(int x, int y, int iconIndex, int iconsize) { - const int iconsize2 = (iconsize / MARGIN_ICON_SIZE) * MARGIN_ICON_SIZE; CImageList* pIcons = nullptr; - if (s_mapIcons.find(iconsize2) == s_mapIcons.end()) + if (s_mapIcons.find(iconsize) == s_mapIcons.end()) { - s_mapIcons.emplace(iconsize2, new CImageList); - pIcons = s_mapIcons[iconsize2].get(); - VERIFY(pIcons->Create(iconsize2, iconsize2, + s_mapIcons.emplace(iconsize, new CImageList); + pIcons = s_mapIcons[iconsize].get(); + VERIFY(pIcons->Create(iconsize, iconsize, ILC_COLOR32 | ILC_MASK, 0, 1)); CBitmap bmp; - bmp.Attach(LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MARGIN_ICONS), IMAGE_BITMAP, - iconsize2 * MARGIN_ICON_COUNT, iconsize2, LR_CREATEDIBSECTION)); - pIcons->Add(&bmp, RGB(255, 255, 255)); + bmp.Attach(LoadBitmapAndConvertTo32bit(AfxGetInstanceHandle(), IDR_MARGIN_ICONS, + MARGIN_ICON_SIZE * MARGIN_ICON_COUNT, MARGIN_ICON_SIZE, iconsize * MARGIN_ICON_COUNT, iconsize, false, RGB(255, 255, 255))); + pIcons->Add(&bmp, nullptr); } if (iconIndex >= 0) { - CPoint pt(x + (iconsize - iconsize2) / 2, y + (iconsize - iconsize2) / 2); - VERIFY(s_mapIcons[iconsize2]->Draw(m_pDC, iconIndex, pt, ILD_TRANSPARENT)); + CPoint pt(x, y); + VERIFY(s_mapIcons[iconsize]->Draw(m_pDC, iconIndex, pt, ILD_TRANSPARENT)); } } diff --git a/Externals/crystaledit/editlib/utils/hqbitmap.cpp b/Externals/crystaledit/editlib/utils/hqbitmap.cpp new file mode 100644 index 00000000000..3cd4b8e64c8 --- /dev/null +++ b/Externals/crystaledit/editlib/utils/hqbitmap.cpp @@ -0,0 +1,159 @@ +#include "StdAfx.h" +#include "hqbitmap.h" +#include +#include + +static void convert24bitImageTo32bit(int width, int height, bool grayscale, COLORREF mask, const BYTE* src, BYTE* dst) +{ + BYTE maskR = GetRValue(mask); + BYTE maskG = GetGValue(mask); + BYTE maskB = GetBValue(mask); + for (int y = 0; y < height; ++y) + { + const BYTE* pSrc = src + y * ((width * 3 * 4 + 3) / 4); + BYTE* pDst = dst + (height - 1 - y) * ((width * 4 * 4 + 3) / 4); + if (!grayscale) + { + for (int x = 0; x < width; ++x) + { + if (pSrc[x * 3] == maskR && pSrc[x * 3 + 1] == maskG && pSrc[x * 3 + 2] == maskB) + { + pDst[x * 4] = 0; + pDst[x * 4 + 1] = 0; + pDst[x * 4 + 2] = 0; + pDst[x * 4 + 3] = 0; + } + else + { + pDst[x * 4 + 0] = pSrc[x * 3 + 0]; + pDst[x * 4 + 1] = pSrc[x * 3 + 1]; + pDst[x * 4 + 2] = pSrc[x * 3 + 2]; + pDst[x * 4 + 3] = 0xff; + } + } + } + else + { + for (int x = 0; x < width; ++x) + { + if (pSrc[x * 3] == 0xff && pSrc[x * 3 + 1] == 0 && pSrc[x * 3 + 2] == 0xff) // rgb(0xff, 0, 0xff) == mask color + { + pDst[x * 4] = 0; + pDst[x * 4 + 1] = 0; + pDst[x * 4 + 2] = 0; + pDst[x * 4 + 3] = 0; + } + else + { + const BYTE b = pSrc[x * 3]; + const BYTE g = pSrc[x * 3 + 1]; + const BYTE r = pSrc[x * 3 + 2]; + const BYTE gray = static_cast( + (static_cast(0.114 * 256) * (((255 - b) >> 1) + b) + + static_cast(0.587 * 256) * (((255 - g) >> 1) + g) + + static_cast(0.299 * 256) * (((255 - r) >> 1) + r)) >> 8); + pDst[x * 4 + 0] = gray; + pDst[x * 4 + 1] = gray; + pDst[x * 4 + 2] = gray; + pDst[x * 4 + 3] = 0xff; + } + } + } + } +}; + +static void convert4bitImageTo32bit(int width, int height, bool grayscale, COLORREF mask, ATL::CImage& image, BYTE* dst) +{ + BYTE* src = (BYTE* )image.GetBits(); + RGBQUAD rgbColors[16]; + RGBQUAD rgbMask{ GetRValue(mask), GetGValue(mask), GetBValue(mask), 0 }; + image.GetColorTable(0, 16, rgbColors); + for (int y = 0; y < height; ++y) + { + const BYTE* pSrc = src + y * ((width + 1) / 2); + BYTE* pDst = dst + (height - 1 - y) * ((width * 4 * 4 + 3) / 4); + if (!grayscale) + { + for (int x = 0; x < width; ++x) + { + RGBQUAD rgba = ((x % 2) == 0) ? rgbColors[pSrc[x / 2] >> 4] : rgbColors[pSrc[x / 2] & 0xf]; + if (*((DWORD *)&rgba) == *((DWORD *)&rgbMask)) + { + pDst[x * 4] = 0; + pDst[x * 4 + 1] = 0; + pDst[x * 4 + 2] = 0; + pDst[x * 4 + 3] = 0; + } + else + { + pDst[x * 4 + 0] = rgba.rgbBlue; + pDst[x * 4 + 1] = rgba.rgbGreen; + pDst[x * 4 + 2] = rgba.rgbRed; + pDst[x * 4 + 3] = 0xff; + } + } + } + else + { + for (int x = 0; x < width; ++x) + { + RGBQUAD rgba = ((x % 2) == 0) ? rgbColors[pSrc[x / 2] >> 4] : rgbColors[pSrc[x / 2] & 0xf]; + if (*((DWORD *)&rgba) == *((DWORD *)&rgbMask)) + { + pDst[x * 4] = 0; + pDst[x * 4 + 1] = 0; + pDst[x * 4 + 2] = 0; + pDst[x * 4 + 3] = 0; + } + else + { + const BYTE gray = static_cast( + (static_cast(0.114 * 256) * (((255 - rgba.rgbBlue) >> 1) + rgba.rgbBlue) + + static_cast(0.587 * 256) * (((255 - rgba.rgbGreen) >> 1) + rgba.rgbGreen) + + static_cast(0.299 * 256) * (((255 - rgba.rgbRed) >> 1) + rgba.rgbRed)) >> 8); + pDst[x * 4 + 0] = gray; + pDst[x * 4 + 1] = gray; + pDst[x * 4 + 2] = gray; + pDst[x * 4 + 3] = 0xff; + } + } + } + } +}; + +HBITMAP LoadBitmapAndConvertTo32bit(HINSTANCE hInstance, int nIDResource, int nWidth, int nHeight, int nNewWidth, int nNewHeight, bool bGrayscale, COLORREF clrMask) +{ + ATL::CImage img; + img.Attach((HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(nIDResource), IMAGE_BITMAP, nWidth, nHeight, LR_CREATEDIBSECTION), ATL::CImage::DIBOR_TOPDOWN); + const int stride = (nWidth * 4 * 4 + 3) / 4; std::vector buf(stride * nHeight); + switch (img.GetBPP()) + { + case 24: + convert24bitImageTo32bit(nWidth, nHeight, bGrayscale, clrMask, reinterpret_cast(img.GetBits()), buf.data()); + break; + case 4: + convert4bitImageTo32bit(nWidth, nHeight, bGrayscale, clrMask, img, buf.data()); + break; + default: + ASSERT(true); + break; + } + HBITMAP hBitmap = nullptr; + + if (nWidth != nNewWidth && nHeight != nNewHeight) + { + Gdiplus::Bitmap bitmapSrc(nWidth, nHeight, stride, PixelFormat32bppPARGB, buf.data()); + Gdiplus::Bitmap bitmapDst(nNewWidth, nNewHeight, PixelFormat32bppPARGB); + Gdiplus::Graphics dcDst(&bitmapDst); + dcDst.SetInterpolationMode(Gdiplus::InterpolationMode::InterpolationModeHighQualityBicubic); + dcDst.DrawImage(&bitmapSrc, 0, 0, nNewWidth, nNewHeight); + bitmapDst.GetHBITMAP(Gdiplus::Color::Transparent, &hBitmap); + } + else + { + Gdiplus::Bitmap bitmapDst(nWidth, nHeight, stride, PixelFormat32bppPARGB, buf.data()); + bitmapDst.GetHBITMAP(Gdiplus::Color::Transparent, &hBitmap); + } + return hBitmap; +} + diff --git a/Externals/crystaledit/editlib/utils/hqbitmap.h b/Externals/crystaledit/editlib/utils/hqbitmap.h new file mode 100644 index 00000000000..183c376dbab --- /dev/null +++ b/Externals/crystaledit/editlib/utils/hqbitmap.h @@ -0,0 +1,3 @@ +#include + +HBITMAP LoadBitmapAndConvertTo32bit(HINSTANCE hInstance, int nIDResource, int nWidth, int nHeight, int nNewWidth, int nNewHeight, bool bGrayscale, COLORREF clrMask); diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index db6e95795c7..63fcfcb0db9 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -59,6 +59,7 @@ #include "VersionInfo.h" #include "Bitmap.h" #include "CCrystalTextMarkers.h" +#include "utils/hqbitmap.h" #include "WindowsManagerDialog.h" @@ -2067,96 +2068,12 @@ void CMainFrame::LoadToolbarImages() */ static void LoadHiColImageList(UINT nIDResource, int nWidth, int nHeight, int nNewWidth, int nNewHeight, int nCount, bool bGrayscale, CImageList& ImgList) { - auto convert24bitImageTo32bit = [](int width, int height, bool grayscale, const BYTE* src, BYTE* dst) - { - for (int y = 0; y < height; ++y) - { - const BYTE* pSrc = src + y * ((width * 3 * 4 + 3) / 4); - BYTE* pDst = dst + (height - 1 - y) * ((width * 4 * 4 + 3) / 4); - if (!grayscale) - { - for (int x = 0; x < width; ++x) - { - if (pSrc[x * 3] == 0xff && pSrc[x * 3 + 1] == 0 && pSrc[x * 3 + 2] == 0xff) // rgb(0xff, 0, 0xff) == mask color - { - pDst[x * 4] = 0; - pDst[x * 4 + 1] = 0; - pDst[x * 4 + 2] = 0; - pDst[x * 4 + 3] = 0; - } - else - { - pDst[x * 4 + 0] = pSrc[x * 3 + 0]; - pDst[x * 4 + 1] = pSrc[x * 3 + 1]; - pDst[x * 4 + 2] = pSrc[x * 3 + 2]; - pDst[x * 4 + 3] = 0xff; - } - } - } - else - { - for (int x = 0; x < width; ++x) - { - if (pSrc[x * 3] == 0xff && pSrc[x * 3 + 1] == 0 && pSrc[x * 3 + 2] == 0xff) // rgb(0xff, 0, 0xff) == mask color - { - pDst[x * 4] = 0; - pDst[x * 4 + 1] = 0; - pDst[x * 4 + 2] = 0; - pDst[x * 4 + 3] = 0; - } - else - { - const BYTE b = pSrc[x * 3]; - const BYTE g = pSrc[x * 3 + 1]; - const BYTE r = pSrc[x * 3 + 2]; - const BYTE gray = static_cast( - (static_cast(0.114 * 256) * (((255 - b) >> 1) + b) - + static_cast(0.587 * 256) * (((255 - g) >> 1) + g) - + static_cast(0.299 * 256) * (((255 - r) >> 1) + r)) >> 8); - pDst[x * 4 + 0] = gray; - pDst[x * 4 + 1] = gray; - pDst[x * 4 + 2] = gray; - pDst[x * 4 + 3] = 0xff; - } - } - } - } - }; - - auto createImageListFromBitmap = [](CImageList& imgList, Gdiplus::Bitmap& bitmap, int width, int height, int count) - { - CBitmap bm; - HBITMAP hBitmap; - bitmap.GetHBITMAP(Gdiplus::Color::Transparent, &hBitmap); - bm.Attach(hBitmap); + CBitmap bm; + bm.Attach(LoadBitmapAndConvertTo32bit(AfxGetInstanceHandle(), nIDResource, nWidth * nCount, nHeight, nNewWidth * nCount, nNewHeight, bGrayscale, RGB(0xff, 0, 0xff))); - VERIFY(imgList.Create(width, height, ILC_COLOR32, count, 0)); - int nIndex = imgList.Add(&bm, nullptr); - ASSERT(-1 != nIndex); - }; - - ATL::CImage img; - img.Attach((HBITMAP)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(nIDResource), IMAGE_BITMAP, nWidth * nCount, nHeight, LR_CREATEDIBSECTION), ATL::CImage::DIBOR_TOPDOWN); - const int stride = (nWidth * nCount * 4 * 4 + 3) / 4; - std::vector buf(stride * nHeight); - convert24bitImageTo32bit(nWidth * nCount, nHeight, bGrayscale, reinterpret_cast(img.GetBits()), buf.data()); - - if (nWidth != nNewWidth && nHeight != nNewHeight) - { - Gdiplus::Bitmap bitmapSrc(nWidth * nCount, nHeight, stride, PixelFormat32bppPARGB, buf.data()); - Gdiplus::Bitmap bitmapDst(nNewWidth * nCount, nNewHeight, PixelFormat32bppPARGB); - Gdiplus::Graphics dcDst(&bitmapDst); - dcDst.SetInterpolationMode(Gdiplus::InterpolationMode::InterpolationModeHighQualityBicubic); - dcDst.DrawImage(&bitmapSrc, 0, 0, nNewWidth * nCount, nNewHeight); - - createImageListFromBitmap(ImgList, bitmapDst, nNewWidth, nNewHeight, nCount); - } - else - { - Gdiplus::Bitmap bitmapDst(nWidth * nCount, nHeight, stride, PixelFormat32bppPARGB, buf.data()); - - createImageListFromBitmap(ImgList, bitmapDst, nNewWidth, nNewHeight, nCount); - } + VERIFY(ImgList.Create(nNewWidth, nNewHeight, ILC_COLOR32, nCount, 0)); + int nIndex = ImgList.Add(&bm, nullptr); + ASSERT(-1 != nIndex); } /** diff --git a/Src/Merge.vs2017.vcxproj b/Src/Merge.vs2017.vcxproj index 49811d3f039..c111c281b04 100644 --- a/Src/Merge.vs2017.vcxproj +++ b/Src/Merge.vs2017.vcxproj @@ -467,6 +467,7 @@ + @@ -1100,6 +1101,7 @@ + diff --git a/Src/Merge.vs2017.vcxproj.filters b/Src/Merge.vs2017.vcxproj.filters index 404f20cedc6..47626673c0c 100644 --- a/Src/Merge.vs2017.vcxproj.filters +++ b/Src/Merge.vs2017.vcxproj.filters @@ -922,6 +922,9 @@ EditLib\Utils + + EditLib\Utils + @@ -1662,6 +1665,9 @@ EditLib\Utils + + EditLib\Utils + diff --git a/Src/Merge.vs2019.vcxproj b/Src/Merge.vs2019.vcxproj index 5e8abc2a17a..70020a5943e 100644 --- a/Src/Merge.vs2019.vcxproj +++ b/Src/Merge.vs2019.vcxproj @@ -466,6 +466,7 @@ + @@ -1099,6 +1100,7 @@ + diff --git a/Src/Merge.vs2019.vcxproj.filters b/Src/Merge.vs2019.vcxproj.filters index 404f20cedc6..47626673c0c 100644 --- a/Src/Merge.vs2019.vcxproj.filters +++ b/Src/Merge.vs2019.vcxproj.filters @@ -922,6 +922,9 @@ EditLib\Utils + + EditLib\Utils + @@ -1662,6 +1665,9 @@ EditLib\Utils + + EditLib\Utils + From fc333718c7d1092a9568f89047d118b4ab2136d9 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Thu, 1 Oct 2020 20:58:50 +0900 Subject: [PATCH 18/23] WIP: Add support for per-monitor DPI awareness (18) --- Src/OpenFrm.cpp | 29 ++++++++++++++++------------- Src/OpenView.cpp | 29 ++++++++++++++++------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Src/OpenFrm.cpp b/Src/OpenFrm.cpp index ab326d55765..33a5a82a6a5 100644 --- a/Src/OpenFrm.cpp +++ b/Src/OpenFrm.cpp @@ -75,8 +75,8 @@ LRESULT COpenFrame::OnNcHitTest(CPoint point) void COpenFrame::OnWindowPosChanging(WINDOWPOS* lpwndpos) { // Retain frame sizes during tile operations (tolerate overlapping) - if ((lpwndpos->flags & (SWP_NOSIZE | SWP_NOOWNERZORDER)) == 0 && !IsZoomed() && - !GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled()) + if ((lpwndpos->flags & (SWP_NOSIZE | SWP_NOOWNERZORDER)) == 0 && + !(IsZoomed() || GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled())) { if (CScrollView *const pView = static_cast(GetActiveView())) { @@ -92,18 +92,21 @@ void COpenFrame::OnWindowPosChanging(WINDOWPOS* lpwndpos) void COpenFrame::ActivateFrame(int nCmdShow) { __super::ActivateFrame(nCmdShow); - if (CView *const pView = GetActiveView()) + if (!GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled()) { - WINDOWPLACEMENT wp; - wp.length = sizeof wp; - GetWindowPlacement(&wp); - CRect rc; - pView->GetWindowRect(&rc); - CalcWindowRect(&rc, CWnd::adjustOutside); - wp.rcNormalPosition.right = wp.rcNormalPosition.left + rc.Width(); - wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + rc.Height(); - SetWindowPlacement(&wp); - pView->ShowWindow(SW_SHOW); + if (CView* const pView = GetActiveView()) + { + WINDOWPLACEMENT wp; + wp.length = sizeof wp; + GetWindowPlacement(&wp); + CRect rc; + pView->GetWindowRect(&rc); + CalcWindowRect(&rc, CWnd::adjustOutside); + wp.rcNormalPosition.right = wp.rcNormalPosition.left + rc.Width(); + wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + rc.Height(); + SetWindowPlacement(&wp); + pView->ShowWindow(SW_SHOW); + } } } diff --git a/Src/OpenView.cpp b/Src/OpenView.cpp index 0c234c01a0b..245264ef556 100644 --- a/Src/OpenView.cpp +++ b/Src/OpenView.cpp @@ -404,10 +404,10 @@ void COpenView::OnMouseMove(UINT nFlags, CPoint point) void COpenView::OnWindowPosChanging(WINDOWPOS* lpwndpos) { - if ((lpwndpos->flags & (SWP_NOMOVE | SWP_NOSIZE)) == 0 && !GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled()) + if ((lpwndpos->flags & (SWP_NOMOVE | SWP_NOSIZE)) == 0) { CFrameWnd *const pFrameWnd = GetParentFrame(); - if (pFrameWnd == GetTopLevelFrame()->GetActiveFrame()) + if (pFrameWnd == GetTopLevelFrame()->GetActiveFrame() || GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled()) { CRect rc; pFrameWnd->GetClientRect(&rc); @@ -421,7 +421,7 @@ void COpenView::OnWindowPosChanging(WINDOWPOS* lpwndpos) if (lpwndpos->y < 0) lpwndpos->y = 0; } - else if (pFrameWnd->IsZoomed()) + else if (pFrameWnd->IsZoomed() || GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled()) { lpwndpos->cx = m_totalLog.cx; lpwndpos->y = (rc.bottom - lpwndpos->cy) / 2; @@ -448,15 +448,18 @@ void COpenView::OnWindowPosChanged(WINDOWPOS* lpwndpos) if (pFrameWnd == GetTopLevelFrame()->GetActiveFrame()) { m_constraint.Persist(true, false); - WINDOWPLACEMENT wp; - wp.length = sizeof wp; - pFrameWnd->GetWindowPlacement(&wp); - CRect rc; - GetWindowRect(&rc); - pFrameWnd->CalcWindowRect(&rc, CWnd::adjustOutside); - wp.rcNormalPosition.right = wp.rcNormalPosition.left + rc.Width(); - wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + rc.Height(); - pFrameWnd->SetWindowPlacement(&wp); + if (!GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled()) + { + WINDOWPLACEMENT wp; + wp.length = sizeof wp; + pFrameWnd->GetWindowPlacement(&wp); + CRect rc; + GetWindowRect(&rc); + pFrameWnd->CalcWindowRect(&rc, CWnd::adjustOutside); + wp.rcNormalPosition.right = wp.rcNormalPosition.left + rc.Width(); + wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + rc.Height(); + pFrameWnd->SetWindowPlacement(&wp); + } } } __super::OnWindowPosChanged(lpwndpos); @@ -472,7 +475,7 @@ void COpenView::OnDestroy() LRESULT COpenView::OnNcHitTest(CPoint point) { - if (GetParentFrame()->IsZoomed()) + if (GetParentFrame()->IsZoomed() || GetMainFrame()->GetLayoutManager().GetTileLayoutEnabled()) { CRect rc; GetWindowRect(&rc); From 79633fc055ddcaa8a88b5ff6fe5cfa89d51959de Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Mon, 5 Oct 2020 00:06:35 +0900 Subject: [PATCH 19/23] WIP: Add support for per-monitor DPI awareness (19) --- .../crystaledit/editlib/utils/MDITileLayout.cpp | 13 +++++++++++-- Externals/crystaledit/editlib/utils/MDITileLayout.h | 1 + Src/DirView.h | 2 +- Src/MainFrm.cpp | 11 ----------- Src/MainFrm.h | 5 ++++- Src/MergeFrameCommon.cpp | 2 ++ 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Externals/crystaledit/editlib/utils/MDITileLayout.cpp b/Externals/crystaledit/editlib/utils/MDITileLayout.cpp index 4ac45f6e354..83f004598d5 100644 --- a/Externals/crystaledit/editlib/utils/MDITileLayout.cpp +++ b/Externals/crystaledit/editlib/utils/MDITileLayout.cpp @@ -343,7 +343,14 @@ namespace MDITileLayout void LayoutManager::NotifyChildClosed(CWnd* pChildWnd) { if (Pane* pPane = m_pPane->FindPaneByWindow(pChildWnd)) + { pPane->RemoveWindow(pChildWnd); + if (pPane->GetWindowCount() == 0) + { + pPane->Combine(); + UpdateChildWindows(); + } + } } void LayoutManager::NotifyChildResized(CWnd* pChildWnd) @@ -401,8 +408,10 @@ namespace MDITileLayout CRect rcChild = pPane->GetRect(rc); CRect rcChildOrg = rcChild; DpiAware::AdjustWindowRectExForDpi(rcChild, pWnd->GetStyle(), false, pWnd->GetExStyle(), dpi); - rcChild.right = rcChildOrg.right; - rcChild.bottom = rcChildOrg.bottom; + if (rcChildOrg.right < rc.right) + rcChild.right = rcChildOrg.right; + if (rcChildOrg.bottom < rc.bottom) + rcChild.bottom = rcChildOrg.bottom; DeferWindowPos(hdwp, pWnd->m_hWnd, nullptr, rcChild.left - rc.left + rcMainMargin.left, rcChild.top - rc.top + rcMainMargin.top, diff --git a/Externals/crystaledit/editlib/utils/MDITileLayout.h b/Externals/crystaledit/editlib/utils/MDITileLayout.h index a17ca523641..d5dd0a968ea 100644 --- a/Externals/crystaledit/editlib/utils/MDITileLayout.h +++ b/Externals/crystaledit/editlib/utils/MDITileLayout.h @@ -29,6 +29,7 @@ namespace MDITileLayout Pane* GetDefaultOpenPane() const; bool AddWindow(CWnd* pWnd); bool RemoveWindow(CWnd* pWnd); + size_t GetWindowCount() const { return m_wndList.size(); } bool MoveWindow(Pane *pDstPane, CWnd* pWnd); Pane* FindPaneByWindow(CWnd* pWnd) const; void UpdateSizeRatio(const CRect& rcMainWnd, const CRect& rcChildWnd); diff --git a/Src/DirView.h b/Src/DirView.h index 34a56a2c2f5..7082418744d 100644 --- a/Src/DirView.h +++ b/Src/DirView.h @@ -407,7 +407,7 @@ class CDirView : public DpiAware::CDpiAwareWnd void CollapseSubdir(int sel); void ExpandSubdir(int sel, bool bRecursive = false); void GetColors(int nRow, int nCol, COLORREF& clrBk, COLORREF& clrText) const; - int GetDefColumnWidth() const { return MulDiv(DefColumnWidth, CClientDC(const_cast(this)).GetDeviceCaps(LOGPIXELSX), 72); }; + int GetDefColumnWidth() const { return PointToPixel(DefColumnWidth); }; public: DirItemIterator Begin() const { return DirItemIterator(m_pIList.get()); } diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index 1cd25655c07..83ee660ce30 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -228,7 +228,6 @@ BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::CDpiAwareWnd) ON_COMMAND_EX(ID_WINDOW_CASCADE, OnMDIWindowCmd) ON_COMMAND_EX(ID_WINDOW_TILE_HORZ, OnMDIWindowCmd) ON_COMMAND_EX(ID_WINDOW_TILE_VERT, OnMDIWindowCmd) - ON_WM_SIZE() //}}AFX_MSG_MAP ON_MESSAGE(WMU_CHILDFRAMEADDED, &CMainFrame::OnChildFrameAdded) ON_MESSAGE(WMU_CHILDFRAMEREMOVED, &CMainFrame::OnChildFrameRemoved) @@ -2578,12 +2577,6 @@ void CMainFrame::OnAccelQuit() SendMessage(WM_CLOSE); } -void CMainFrame::OnSize(UINT nType, int cx, int cy) -{ - __super::OnSize(nType, cx, cy); - m_layoutManager.NotifyMainResized(); -} - LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) { int olddpi = m_dpi; @@ -2611,8 +2604,6 @@ LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam) LRESULT CMainFrame::OnChildFrameAdded(WPARAM wParam, LPARAM lParam) { - m_layoutManager.NotifyChildOpened(reinterpret_cast(lParam)); - for (int i = 0; i < m_arrChild.GetSize(); ++i) { if (reinterpret_cast(lParam) == m_arrChild.GetAt(i)) @@ -2628,8 +2619,6 @@ LRESULT CMainFrame::OnChildFrameAdded(WPARAM wParam, LPARAM lParam) LRESULT CMainFrame::OnChildFrameRemoved(WPARAM wParam, LPARAM lParam) { - m_layoutManager.NotifyChildClosed(reinterpret_cast(lParam)); - for (int i = 0; i < m_arrChild.GetSize(); ++i) { if (reinterpret_cast(lParam) == m_arrChild.GetAt(i)) diff --git a/Src/MainFrm.h b/Src/MainFrm.h index 70cf7db9156..4ac009d078b 100644 --- a/Src/MainFrm.h +++ b/Src/MainFrm.h @@ -174,6 +174,10 @@ class CMainFrame : public DpiAware::CDpiAwareWnd RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE); } break; + case WM_SIZE: + if (AfxGetMainWnd()) + GetMainFrame()->GetLayoutManager().NotifyMainResized(); + break; case WM_DPICHANGED_BEFOREPARENT: UpdateDpi(); break; @@ -299,7 +303,6 @@ class CMainFrame : public DpiAware::CDpiAwareWnd afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnDestroy(); afx_msg void OnAccelQuit(); - afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam); afx_msg BOOL OnMDIWindowCmd(UINT nID); //}}AFX_MSG diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index 4bfd153e6e8..2414f3cae3e 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -32,11 +32,13 @@ CMergeFrameCommon::CMergeFrameCommon(int nIdenticalIcon, int nDifferentIcon) , m_nLastSplitPos{0} { ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEADDED, 0, reinterpret_cast(this)); + GetMainFrame()->GetLayoutManager().NotifyChildOpened(this); } CMergeFrameCommon::~CMergeFrameCommon() { ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEREMOVED, 0, reinterpret_cast(this)); + GetMainFrame()->GetLayoutManager().NotifyChildClosed(this); } BOOL CMergeFrameCommon::PreCreateWindow(CREATESTRUCT& cs) From 7768cb016f7ee6e1b6f1a5ce58a8f9f6f24680e3 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Tue, 13 Oct 2020 00:37:09 +0900 Subject: [PATCH 20/23] WIP: Add support for per-monitor DPI awareness (20) --- .../editlib/utils/MDITileLayout.cpp | 35 ++++++++++++------- .../crystaledit/editlib/utils/MDITileLayout.h | 3 +- Src/Merge.rc | 3 -- Src/MergeFrameCommon.cpp | 2 +- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Externals/crystaledit/editlib/utils/MDITileLayout.cpp b/Externals/crystaledit/editlib/utils/MDITileLayout.cpp index 83f004598d5..95bb4d19803 100644 --- a/Externals/crystaledit/editlib/utils/MDITileLayout.cpp +++ b/Externals/crystaledit/editlib/utils/MDITileLayout.cpp @@ -360,9 +360,9 @@ namespace MDITileLayout Pane* pPane = m_pPane->FindPaneByWindow(pChildWnd); if (pPane == nullptr) return; - CRect rc = GetMainRect(); - CRect rcChild = GetChildRect(pChildWnd); - pPane->UpdateSizeRatio(rc, rcChild); + CRect rcMain = GetMainRect(); + CRect rcChild = GetChildRect(pChildWnd, rcMain); + pPane->UpdateSizeRatio(rcMain, rcChild); UpdateChildWindows(); } @@ -390,6 +390,18 @@ namespace MDITileLayout return nullptr; } + CRect LayoutManager::AdjustChildRect(const CRect& rcMain, const CRect& rc, DWORD dwStyle, DWORD dwExStyle, int dpi) const + { + CRect rcChild = rc; + CRect rcChildOrg = rcChild; + DpiAware::AdjustWindowRectExForDpi(rcChild, dwStyle, false, dwExStyle, dpi); + if (rcChildOrg.right < rcMain.right) + rcChild.right = rcChildOrg.right; + if (rcChildOrg.bottom < rcMain.bottom) + rcChild.bottom = rcChildOrg.bottom; + return rcChild; + } + void LayoutManager::UpdateChildWindows() { if (!m_bEnabled || m_pMDIFrameWnd->MDIGetActive()->GetSafeHwnd() == nullptr) @@ -405,13 +417,7 @@ namespace MDITileLayout { if (Pane* pPane = m_pPane->FindPaneByWindow(pWnd)) { - CRect rcChild = pPane->GetRect(rc); - CRect rcChildOrg = rcChild; - DpiAware::AdjustWindowRectExForDpi(rcChild, pWnd->GetStyle(), false, pWnd->GetExStyle(), dpi); - if (rcChildOrg.right < rc.right) - rcChild.right = rcChildOrg.right; - if (rcChildOrg.bottom < rc.bottom) - rcChild.bottom = rcChildOrg.bottom; + CRect rcChild = AdjustChildRect(rc, pPane->GetRect(rc), pWnd->GetStyle(), pWnd->GetExStyle(), dpi); DeferWindowPos(hdwp, pWnd->m_hWnd, nullptr, rcChild.left - rc.left + rcMainMargin.left, rcChild.top - rc.top + rcMainMargin.top, @@ -430,12 +436,17 @@ namespace MDITileLayout return rc; } - CRect LayoutManager::GetChildRect(CWnd* pChildWnd) const + CRect LayoutManager::GetChildRect(CWnd* pChildWnd, const CRect& rcMain) const { const int dpi = DpiAware::GetDpiForWindow(pChildWnd->m_hWnd); CRect rc, rcOuter; pChildWnd->GetWindowRect(rc); DpiAware::AdjustWindowRectExForDpi(rcOuter, pChildWnd->GetStyle(), false, pChildWnd->GetExStyle(), dpi); - return { rc.left - rcOuter.left, rc.top - rcOuter.top, rc.right - rcOuter.right, rc.bottom - rcOuter.bottom }; + CRect rcChild { rc.left - rcOuter.left, rc.top - rcOuter.top, rc.right - rcOuter.right, rc.bottom - rcOuter.bottom}; + if (rc.right < rcMain.right) + rcChild.right = rc.right; + if (rc.bottom < rcMain.bottom) + rcChild.bottom = rc.bottom; + return rcChild; } } diff --git a/Externals/crystaledit/editlib/utils/MDITileLayout.h b/Externals/crystaledit/editlib/utils/MDITileLayout.h index d5dd0a968ea..de2a276c084 100644 --- a/Externals/crystaledit/editlib/utils/MDITileLayout.h +++ b/Externals/crystaledit/editlib/utils/MDITileLayout.h @@ -70,13 +70,14 @@ namespace MDITileLayout void NotifyChildOpened(CWnd* pChlidWnd); void NotifyChildClosed(CWnd* pChlidWnd); void NotifyChildResized(CWnd* pChlidWnd); + CRect AdjustChildRect(const CRect& rcMain, const CRect& rc, DWORD dwStyle, DWORD dwExStyle, int dpi) const; protected: Pane* FindPaneByPosition(CPoint& pt) const; Pane* GetActivePane() const; void UpdateChildWindows(); CRect GetMainRect() const; - CRect GetChildRect(CWnd* pChildWnd) const; + CRect GetChildRect(CWnd* pChildWnd, const CRect& rcMain) const; bool m_bInResizing = false; bool m_bEnabled = false; diff --git a/Src/Merge.rc b/Src/Merge.rc index 175423c1a0c..54399de0596 100644 --- a/Src/Merge.rc +++ b/Src/Merge.rc @@ -230,7 +230,6 @@ BEGIN BEGIN MENUITEM "Cl&ose", ID_FILE_CLOSE MENUITEM "Clo&se All", ID_WINDOW_CLOSEALL - MENUITEM "New Window", ID_WINDOW_NEW MENUITEM SEPARATOR MENUITEM "Change &Pane\tF6", ID_WINDOW_CHANGE_PANE MENUITEM SEPARATOR @@ -372,7 +371,6 @@ BEGIN BEGIN MENUITEM "Cl&ose", ID_FILE_CLOSE MENUITEM "Clo&se All", ID_WINDOW_CLOSEALL - MENUITEM "New Window", ID_WINDOW_NEW MENUITEM SEPARATOR MENUITEM "Change &Pane\tF6", ID_WINDOW_CHANGE_PANE MENUITEM SEPARATOR @@ -627,7 +625,6 @@ BEGIN BEGIN MENUITEM "Cl&ose", ID_FILE_CLOSE MENUITEM "Clo&se All", ID_WINDOW_CLOSEALL - MENUITEM "New Window", ID_WINDOW_NEW MENUITEM SEPARATOR MENUITEM "Change &Pane\tF6", ID_WINDOW_CHANGE_PANE MENUITEM SEPARATOR diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp index 2414f3cae3e..34bc535c374 100644 --- a/Src/MergeFrameCommon.cpp +++ b/Src/MergeFrameCommon.cpp @@ -53,11 +53,11 @@ BOOL CMergeFrameCommon::PreCreateWindow(CREATESTRUCT& cs) CRect rcMain; ::GetWindowRect(GetMainFrame()->m_hWndMDIClient, rcMain); CRect rc = layoutManager.GetDefaultOpenPaneRect(); + rc = layoutManager.AdjustChildRect(rcMain, rc, cs.style, WS_EX_WINDOWEDGE | WS_EX_MDICHILD, GetMainFrame()->GetDpi()); rc.right -= rcMain.left; rc.bottom -= rcMain.top; rc.left -= rcMain.left; rc.top -= rcMain.top; - AdjustWindowRectEx(rc, cs.style, false, cs.dwExStyle); cs.x = rc.left; cs.y = rc.top; cs.cx = rc.Width(); From d04365b733f47432024a452ed3e79a4b5ce30930 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Tue, 4 Jun 2024 21:01:03 +0900 Subject: [PATCH 21/23] WIP --- Externals/freeimage | 2 +- Externals/jq | 2 +- Externals/patch | 2 +- Externals/sevenzip | 2 +- Externals/winimerge | 2 +- Externals/winwebdiff | 2 +- Testing/FolderCompare/FolderCompare.vcxproj | 1 - Testing/FolderCompare/FolderCompare.vcxproj.filters | 3 --- 8 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Externals/freeimage b/Externals/freeimage index fbc617c1390..78364ed94b4 160000 --- a/Externals/freeimage +++ b/Externals/freeimage @@ -1 +1 @@ -Subproject commit fbc617c1390425fdf39d152fd6e6411f30bd3163 +Subproject commit 78364ed94b4cb2d830805a26cb65bf5e6f523d58 diff --git a/Externals/jq b/Externals/jq index e73951f3d19..71c2ab509a8 160000 --- a/Externals/jq +++ b/Externals/jq @@ -1 +1 @@ -Subproject commit e73951f3d1928591b3a9a60de11ae975a21e621f +Subproject commit 71c2ab509a8628dbbad4bc7b3f98a64aa90d3297 diff --git a/Externals/patch b/Externals/patch index a44c7a2921d..cf653d2c37a 160000 --- a/Externals/patch +++ b/Externals/patch @@ -1 +1 @@ -Subproject commit a44c7a2921d52b274ab33900a3f49e6b02a5a95f +Subproject commit cf653d2c37afa1bcd9b9ca57547d2b4ab670f31f diff --git a/Externals/sevenzip b/Externals/sevenzip index cff58f15205..3c899393a6b 160000 --- a/Externals/sevenzip +++ b/Externals/sevenzip @@ -1 +1 @@ -Subproject commit cff58f15205a4e45343a5ed9214059162039e6c0 +Subproject commit 3c899393a6beb20e727648441bbe1b8cfc2c80ba diff --git a/Externals/winimerge b/Externals/winimerge index 1fd2ce3844d..21f69f358cc 160000 --- a/Externals/winimerge +++ b/Externals/winimerge @@ -1 +1 @@ -Subproject commit 1fd2ce3844de44e338a25d161dd98533fde7fdca +Subproject commit 21f69f358cc71e5881b7d77304961a1b76cad0b9 diff --git a/Externals/winwebdiff b/Externals/winwebdiff index 54e857c8a24..6d7cf175ccf 160000 --- a/Externals/winwebdiff +++ b/Externals/winwebdiff @@ -1 +1 @@ -Subproject commit 54e857c8a247bbb9555be47d1a91f18d6c5a15c7 +Subproject commit 6d7cf175ccf04fad387f70abeca972c1582b6121 diff --git a/Testing/FolderCompare/FolderCompare.vcxproj b/Testing/FolderCompare/FolderCompare.vcxproj index 04e3f85dfb5..d42ff599c81 100644 --- a/Testing/FolderCompare/FolderCompare.vcxproj +++ b/Testing/FolderCompare/FolderCompare.vcxproj @@ -520,7 +520,6 @@ - NotUsing diff --git a/Testing/FolderCompare/FolderCompare.vcxproj.filters b/Testing/FolderCompare/FolderCompare.vcxproj.filters index 4717a1af0ff..ba0435eb98a 100644 --- a/Testing/FolderCompare/FolderCompare.vcxproj.filters +++ b/Testing/FolderCompare/FolderCompare.vcxproj.filters @@ -174,9 +174,6 @@ Source Files - - Source Files - From d118721664be06c4ff638197d61438dadd6c86c6 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Wed, 5 Jun 2024 07:34:55 +0900 Subject: [PATCH 22/23] WIP --- Externals/freeimage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Externals/freeimage b/Externals/freeimage index 78364ed94b4..f4ffb561f3c 160000 --- a/Externals/freeimage +++ b/Externals/freeimage @@ -1 +1 @@ -Subproject commit 78364ed94b4cb2d830805a26cb65bf5e6f523d58 +Subproject commit f4ffb561f3c9da43b4bdf2f6cc552fe34bd9da23 From 8bacafa8a1a1c00908c569710b6252b97ee8502d Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Wed, 5 Jun 2024 09:01:07 +0900 Subject: [PATCH 23/23] WIP --- .../crystaledit/Sample/SampleStatic.vcxproj | 137 ------------------ Externals/crystaledit/Sample/resource.h | 3 + .../crystaledit/editlib/editlib.vcxitems | 5 + .../editlib/editlib.vcxitems.filters | 15 ++ 4 files changed, 23 insertions(+), 137 deletions(-) diff --git a/Externals/crystaledit/Sample/SampleStatic.vcxproj b/Externals/crystaledit/Sample/SampleStatic.vcxproj index a3eaeac0022..37e917e53e2 100644 --- a/Externals/crystaledit/Sample/SampleStatic.vcxproj +++ b/Externals/crystaledit/Sample/SampleStatic.vcxproj @@ -233,7 +233,6 @@ false MachineX86 - 5.01 true @@ -326,17 +325,10 @@ ..\output;%(AdditionalLibraryDirectories) true Windows -<<<<<<< HEAD:Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj - false - - MachineX86 - 5.01 -======= wWinMainCRTStartup true ->>>>>>> master:Externals/crystaledit/Sample/SampleStatic.vcxproj true @@ -434,12 +426,8 @@ false MachineX86 -<<<<<<< HEAD:Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj - 5.01 -======= true true ->>>>>>> master:Externals/crystaledit/Sample/SampleStatic.vcxproj true @@ -537,18 +525,11 @@ ..\output;%(AdditionalLibraryDirectories) Windows wWinMainCRTStartup -<<<<<<< HEAD:Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj - false - - MachineX86 - 5.01 -======= true true true ->>>>>>> master:Externals/crystaledit/Sample/SampleStatic.vcxproj true @@ -612,85 +593,6 @@ -<<<<<<< HEAD:Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj - - - - - - - NotUsing - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -======= ->>>>>>> master:Externals/crystaledit/Sample/SampleStatic.vcxproj @@ -709,45 +611,6 @@ -<<<<<<< HEAD:Externals/crystaledit/Sample/SampleStatic.vs2019.vcxproj - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -======= ->>>>>>> master:Externals/crystaledit/Sample/SampleStatic.vcxproj diff --git a/Externals/crystaledit/Sample/resource.h b/Externals/crystaledit/Sample/resource.h index 47fa0140dff..7c9c213e514 100755 --- a/Externals/crystaledit/Sample/resource.h +++ b/Externals/crystaledit/Sample/resource.h @@ -54,6 +54,9 @@ #define ID_VIEW_SELECT_FONT 32801 #define ID_VIEW_LINENUMBERS 32802 #define ID_FILE_CONVERT_TO_HTML 32803 +#define ID_WINDOW_SPLIT_VERTICALLY 32804 +#define ID_WINDOW_SPLIT_HORIZONTALLY 32805 +#define ID_WINDOW_COMBINE 32806 #define ID_EDIT_INDICATOR_COL 37900 #define ID_READ_ONLY 37901 #define ID_INDICATOR_ENCODING 37905 diff --git a/Externals/crystaledit/editlib/editlib.vcxitems b/Externals/crystaledit/editlib/editlib.vcxitems index 711dd5e7a14..d1470c66120 100644 --- a/Externals/crystaledit/editlib/editlib.vcxitems +++ b/Externals/crystaledit/editlib/editlib.vcxitems @@ -48,12 +48,14 @@ + pch.h $(IntDir)$(TargetName)2.pch + pch.h $(IntDir)$(TargetName)2.pch @@ -92,9 +94,12 @@ + + + diff --git a/Externals/crystaledit/editlib/editlib.vcxitems.filters b/Externals/crystaledit/editlib/editlib.vcxitems.filters index 8c1dd183b4b..feceb3792a1 100644 --- a/Externals/crystaledit/editlib/editlib.vcxitems.filters +++ b/Externals/crystaledit/editlib/editlib.vcxitems.filters @@ -100,6 +100,12 @@ Utils + + Utils + + + Utils + @@ -202,5 +208,14 @@ Utils + + Utils + + + Utils + + + Utils + \ No newline at end of file