Skip to content

Commit

Permalink
Merge pull request #724 from jdpurcell/pr-winperdisplayicc
Browse files Browse the repository at this point in the history
Windows: Fix ICC profile detection not working per-monitor
  • Loading branch information
jurplel authored Oct 19, 2024
2 parents e083114 + fcea73f commit 909e013
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/qvwin32functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,31 @@ QByteArray QVWin32Functions::getIccProfileForWindow(const QWindow *window)
{
QByteArray result;
const HWND hWnd = reinterpret_cast<HWND>(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;
}

0 comments on commit 909e013

Please sign in to comment.