mirror of
https://github.com/Open-Shell/Open-Shell-Menu.git
synced 2026-04-11 17:37:22 +10:00
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
This commit is contained in:
@@ -503,6 +503,17 @@ SIZE MenuSkin::ScaleSkinElement( const SIZE &size ) const
|
||||
return res;
|
||||
}
|
||||
|
||||
_Success_(return != FALSE)
|
||||
BOOL WINAPI SystemParametersInfoForDpi(_In_ UINT uiAction, _In_ UINT uiParam, _Pre_maybenull_ _Post_valid_ PVOID pvParam, _In_ UINT fWinIni, _In_ UINT dpi)
|
||||
{
|
||||
static auto p = static_cast<decltype(&SystemParametersInfoForDpi)>((void*)GetProcAddress(GetModuleHandle(L"user32.dll"), "SystemParametersInfoForDpi"));
|
||||
if (p)
|
||||
return p(uiAction, uiParam, pvParam, fWinIni, dpi);
|
||||
|
||||
// fall-back for older systems
|
||||
return SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni);
|
||||
}
|
||||
|
||||
HFONT MenuSkin::LoadSkinFont( const wchar_t *str, const wchar_t *name, int weight, float size, bool bScale ) const
|
||||
{
|
||||
DWORD quality=DEFAULT_QUALITY;
|
||||
@@ -545,9 +556,8 @@ HFONT MenuSkin::LoadSkinFont( const wchar_t *str, const wchar_t *name, int weigh
|
||||
{
|
||||
// get the default menu font
|
||||
NONCLIENTMETRICS metrics={sizeof(metrics)};
|
||||
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&metrics,0);
|
||||
SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS,sizeof(metrics),&metrics,0,Dpi);
|
||||
metrics.lfMenuFont.lfQuality=(BYTE)quality;
|
||||
metrics.lfMenuFont.lfHeight=ScaleSkinElement(metrics.lfMenuFont.lfHeight,scale);
|
||||
return CreateFontIndirect(&metrics.lfMenuFont);
|
||||
}
|
||||
size=ScaleSkinElement((int)(size*96),scale)/72.f;
|
||||
|
||||
Reference in New Issue
Block a user