Add DPI Aware replacement of GetSystemMetrics

Use GetSystemMetricsForDpi when this function is available and the DPI is
known. Otherwise keep using GetSystemMetrics.
This commit is contained in:
Maarten Bent
2018-07-22 14:03:42 +02:00
parent 914e6f99f4
commit 04b99d54bd
2 changed files with 61 additions and 0 deletions

View File

@@ -300,6 +300,7 @@ extern HICON wxBitmapToHICON(const wxBitmap& bmp);
extern
HCURSOR wxBitmapToHCURSOR(const wxBitmap& bmp, int hotSpotX, int hotSpotY);
extern int wxGetSystemMetrics(int nIndex, const wxWindow* win);
#if wxUSE_OWNER_DRAWN

View File

@@ -4701,6 +4701,66 @@ wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
return false;
}
// ---------------------------------------------------------------------------
// DPI
// ---------------------------------------------------------------------------
namespace
{
static inline const wxTopLevelWindow* wxGetWinTLW(const wxWindow* win)
{
if ( win )
{
const wxWindow* tlwWin = wxGetTopLevelParent(const_cast<wxWindow*>(win));
return wxDynamicCast(tlwWin, wxTopLevelWindow);
}
else if ( wxTheApp )
{
wxWindow* window = wxTheApp->GetTopWindow();
if ( window )
{
return wxDynamicCast(wxGetTopLevelParent(window), wxTopLevelWindow);
}
}
return NULL;
}
}
/*extern*/
int wxGetSystemMetrics(int nIndex, const wxWindow* win)
{
#if wxUSE_DYNLIB_CLASS
const wxTopLevelWindow* tlw = wxGetWinTLW(win);
if ( tlw )
{
typedef int (WINAPI * GetSystemMetricsForDpi_t)(int nIndex, UINT dpi);
static GetSystemMetricsForDpi_t s_pfnGetSystemMetricsForDpi = NULL;
static bool s_initDone = false;
if ( !s_initDone )
{
wxLoadedDLL dllUser32("user32.dll");
wxDL_INIT_FUNC(s_pfn, GetSystemMetricsForDpi, dllUser32);
s_initDone = true;
}
if ( s_pfnGetSystemMetricsForDpi )
{
const int y = ::GetDeviceCaps(::GetDC(tlw->GetHWND()), LOGPIXELSY);
return s_pfnGetSystemMetricsForDpi(nIndex, (UINT)y);
}
}
#else
wxUnusedVar(win);
#endif // wxUSE_DYNLIB_CLASS
return ::GetSystemMetrics(nIndex);
}
// ---------------------------------------------------------------------------
// colours and palettes
// ---------------------------------------------------------------------------