Skip to content

Commit 21eea53

Browse files
committed
Properly scale default skin font according to DPI (#1110)
Original fix introduced in 528d15 was not correct. The problem is that `SystemParametersInfo` uses DPI that current session started with. We should use `SystemParametersInfoForDpi` (available since Win10 1607) that returns properly scaled font size. Fixes #1110
1 parent 2d6fb1f commit 21eea53

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Src/StartMenu/StartMenuDLL/SkinManager.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,17 @@ SIZE MenuSkin::ScaleSkinElement( const SIZE &size ) const
503503
return res;
504504
}
505505

506+
_Success_(return != FALSE)
507+
BOOL WINAPI SystemParametersInfoForDpi(_In_ UINT uiAction, _In_ UINT uiParam, _Pre_maybenull_ _Post_valid_ PVOID pvParam, _In_ UINT fWinIni, _In_ UINT dpi)
508+
{
509+
static auto p = static_cast<decltype(&SystemParametersInfoForDpi)>((void*)GetProcAddress(GetModuleHandle(L"user32.dll"), "SystemParametersInfoForDpi"));
510+
if (p)
511+
return p(uiAction, uiParam, pvParam, fWinIni, dpi);
512+
513+
// fall-back for older systems
514+
return SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni);
515+
}
516+
506517
HFONT MenuSkin::LoadSkinFont( const wchar_t *str, const wchar_t *name, int weight, float size, bool bScale ) const
507518
{
508519
DWORD quality=DEFAULT_QUALITY;
@@ -545,9 +556,8 @@ HFONT MenuSkin::LoadSkinFont( const wchar_t *str, const wchar_t *name, int weigh
545556
{
546557
// get the default menu font
547558
NONCLIENTMETRICS metrics={sizeof(metrics)};
548-
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&metrics,0);
559+
SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS,sizeof(metrics),&metrics,0,Dpi);
549560
metrics.lfMenuFont.lfQuality=(BYTE)quality;
550-
metrics.lfMenuFont.lfHeight=ScaleSkinElement(metrics.lfMenuFont.lfHeight,scale);
551561
return CreateFontIndirect(&metrics.lfMenuFont);
552562
}
553563
size=ScaleSkinElement((int)(size*96),scale)/72.f;

0 commit comments

Comments
 (0)