@@ -429,7 +429,14 @@ namespace QWK {
429429 if (apis.pGetSystemMetricsForDpi ) {
430430 return apis.pGetSystemMetricsForDpi (index, dpi);
431431 }
432- return ::GetSystemMetrics (index);
432+ const int result = ::GetSystemMetrics (index);
433+ // GetSystemMetrics() always give you scaled value.
434+ if (dpi != USER_DEFAULT_SCREEN_DPI) {
435+ return result;
436+ }
437+ const qreal dpr = qreal (dpi) / qreal (USER_DEFAULT_SCREEN_DPI);
438+ // ### Not sure how Windows itself rounds non-integer value.
439+ return qFloor (qreal (result) * dpr);
433440 }
434441
435442 inline quint32 getWindowFrameBorderThickness (HWND hwnd) {
@@ -442,19 +449,28 @@ namespace QWK {
442449 }
443450 }
444451 if (isWin10OrGreater ()) {
445- return static_cast <quint32>(qreal (1 ) * qreal (getDpiForWindow (hwnd)) / qreal (USER_DEFAULT_SCREEN_DPI));
452+ const quint32 dpi = getDpiForWindow (hwnd);
453+ // When DPI is 96, it should be 1px.
454+ return getSystemMetricsForDpi (SM_CXBORDER, dpi);
446455 }
456+ // There's no such thing (a visible frame border line) before Win10.
447457 return 0 ;
448458 }
449459
450460 inline quint32 getResizeBorderThickness (HWND hwnd) {
451461 const quint32 dpi = getDpiForWindow (hwnd);
462+ // When DPI is 96, SM_CXSIZEFRAME is 4px, SM_CXPADDEDBORDER is also 4px,
463+ // so the result should be 8px. This result won't be affected by OS version,
464+ // it's 8px in Win7, and so in Win11.
452465 return getSystemMetricsForDpi (SM_CXSIZEFRAME, dpi) +
453466 getSystemMetricsForDpi (SM_CXPADDEDBORDER, dpi);
454467 }
455468
456469 inline quint32 getTitleBarHeight (HWND hwnd) {
457470 const quint32 dpi = getDpiForWindow (hwnd);
471+ // When DPI is 96, SM_CYCAPTION is 23px, so the result should be 31px.
472+ // However, according to latest MS design manual, the title bar height
473+ // should be 32px, maybe there's some rounding issue.
458474 return getSystemMetricsForDpi (SM_CYCAPTION, dpi) +
459475 getSystemMetricsForDpi (SM_CYSIZEFRAME, dpi) +
460476 getSystemMetricsForDpi (SM_CXPADDEDBORDER, dpi);
0 commit comments