Revision: 9968 https://osdn.net/projects/ttssh2/scm/svn/commits/9968 Author: zmatsuo Date: 2022-05-28 03:07:54 +0900 (Sat, 28 May 2022) Log Message: ----------- GetMonitorDpiFromWindow() で Primary Monitor の DPI を取得できるようにした Modified Paths: -------------- branches/adjust_icon/teraterm/common/ttlib_static.c -------------- next part -------------- Modified: branches/adjust_icon/teraterm/common/ttlib_static.c =================================================================== --- branches/adjust_icon/teraterm/common/ttlib_static.c 2022-05-27 18:07:44 UTC (rev 9967) +++ branches/adjust_icon/teraterm/common/ttlib_static.c 2022-05-27 18:07:54 UTC (rev 9968) @@ -321,6 +321,7 @@ * hWnd\x82̕\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82郂\x83j\x83^\x82\xCCDPI\x82\xF0\x8E擾\x82\xB7\x82\xE9 * Per-monitor DPI awareness\x91Ή\x9E * + * @param hWnd (NULL\x82̂Ƃ\xABPrimary monitor) * @retval DPI\x92l(\x92ʏ\xED\x82\xCCDPI\x82\xCD96) */ int GetMonitorDpiFromWindow(HWND hWnd) @@ -336,7 +337,15 @@ } else { UINT dpiX; UINT dpiY; - HMONITOR hMonitor = pMonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); + HMONITOR hMonitor; + if (hWnd == NULL) { + // https://devblogs.microsoft.com/oldnewthing/20070809-00/?p=25643 + const POINT ptZero = { 0, 0 }; + hMonitor = pMonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY); + } + else { + hMonitor = pMonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); + } pGetDpiForMonitor(hMonitor, 0 /*0=MDT_EFFECTIVE_DPI*/, &dpiX, &dpiY); return (int)dpiY; }