aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32/PlatWin.cxx
diff options
context:
space:
mode:
authorMarkus Nißl <unknown>2022-10-29 21:05:25 +1100
committerMarkus Nißl <unknown>2022-10-29 21:05:25 +1100
commitc0371d58dfd4d055b040ba7274fb5b537532d257 (patch)
tree38d75d82fbe12ee04985f17395ac1fb715f6c411 /win32/PlatWin.cxx
parente04a2cf64168091c804bb8856db6cb5d85d3251d (diff)
downloadscintilla-mirror-c0371d58dfd4d055b040ba7274fb5b537532d257.tar.gz
Bug [#2344]. Use the top-level window to find the monitor for DirectWrite
rendering parameters. Temporarily switch DPI awareness to find correct monitor in GDI scaling mode. https://sourceforge.net/p/scintilla/code/merge-requests/34/
Diffstat (limited to 'win32/PlatWin.cxx')
-rw-r--r--win32/PlatWin.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index bb808b4e7..c97b9283b 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -157,11 +157,15 @@ GetSystemMetricsForDpiSig fnGetSystemMetricsForDpi = nullptr;
using AdjustWindowRectExForDpiSig = BOOL(WINAPI *)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
AdjustWindowRectExForDpiSig fnAdjustWindowRectExForDpi = nullptr;
+using SetThreadDpiAwarenessContextSig = DPI_AWARENESS_CONTEXT(WINAPI *)(DPI_AWARENESS_CONTEXT);
+SetThreadDpiAwarenessContextSig fnSetThreadDpiAwarenessContext = nullptr;
+
void LoadDpiForWindow() noexcept {
HMODULE user32 = ::GetModuleHandleW(L"user32.dll");
fnGetDpiForWindow = DLLFunction<GetDpiForWindowSig>(user32, "GetDpiForWindow");
fnGetSystemMetricsForDpi = DLLFunction<GetSystemMetricsForDpiSig>(user32, "GetSystemMetricsForDpi");
fnAdjustWindowRectExForDpi = DLLFunction<AdjustWindowRectExForDpiSig>(user32, "AdjustWindowRectExForDpi");
+ fnSetThreadDpiAwarenessContext = DLLFunction<SetThreadDpiAwarenessContextSig>(user32, "SetThreadDpiAwarenessContext");
using GetDpiForSystemSig = UINT(WINAPI *)(void);
GetDpiForSystemSig fnGetDpiForSystem = DLLFunction<GetDpiForSystemSig>(user32, "GetDpiForSystem");
@@ -358,6 +362,25 @@ struct FontDirectWrite : public FontWin {
}
+HMONITOR MonitorFromWindow(HWND hWnd) noexcept {
+ constexpr DWORD monitorFlags = MONITOR_DEFAULTTONEAREST;
+
+ if (!fnSetThreadDpiAwarenessContext) {
+ return ::MonitorFromWindow(hWnd, monitorFlags);
+ }
+
+ // Temporarily switching to PerMonitorV2 to retrieve correct monitor via MonitorFromRect() in case of active GDI scaling.
+ const DPI_AWARENESS_CONTEXT oldContext = fnSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
+ PLATFORM_ASSERT(oldContext != nullptr);
+
+ RECT rect;
+ ::GetWindowRect(hWnd, &rect);
+ const HMONITOR monitor = ::MonitorFromRect(&rect, monitorFlags);
+
+ fnSetThreadDpiAwarenessContext(oldContext);
+ return monitor;
+}
+
std::shared_ptr<Font> Font::Allocate(const FontParameters &fp) {
#if defined(USE_D2D)
if (fp.technology != Technology::Default) {