From fcea73f9d9bef8a9e1763c31f115d452a5e7ef73 Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Mon, 14 Oct 2024 19:11:06 -0400 Subject: [PATCH] Windows: Fix ICC profile detection not working per-monitor --- src/qvwin32functions.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/qvwin32functions.cpp b/src/qvwin32functions.cpp index 056651e1..94af70d2 100644 --- a/src/qvwin32functions.cpp +++ b/src/qvwin32functions.cpp @@ -165,22 +165,31 @@ QByteArray QVWin32Functions::getIccProfileForWindow(const QWindow *window) { QByteArray result; const HWND hWnd = reinterpret_cast(window->winId()); - const HDC hDC = GetDC(hWnd); - if (hDC) + const HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); + if (hMonitor) { - WCHAR profilePathBuff[MAX_PATH]; - DWORD profilePathSize = MAX_PATH; - if (GetICMProfileW(hDC, &profilePathSize, profilePathBuff)) + MONITORINFOEXW monitorInfo; + monitorInfo.cbSize = sizeof(MONITORINFOEXW); + if (GetMonitorInfoW(hMonitor, &monitorInfo)) { - QString profilePath = QString::fromWCharArray(profilePathBuff); - QFile file(profilePath); - if (file.open(QIODevice::ReadOnly)) + const HDC hDC = CreateICW(monitorInfo.szDevice, monitorInfo.szDevice, NULL, NULL); + if (hDC) { - result = file.readAll(); - file.close(); + WCHAR profilePathBuff[MAX_PATH]; + DWORD profilePathSize = MAX_PATH; + if (GetICMProfileW(hDC, &profilePathSize, profilePathBuff)) + { + QString profilePath = QString::fromWCharArray(profilePathBuff); + QFile file(profilePath); + if (file.open(QIODevice::ReadOnly)) + { + result = file.readAll(); + file.close(); + } + } + ReleaseDC(hWnd, hDC); } } - ReleaseDC(hWnd, hDC); } return result; }