Remove static reference to NONCLIENTMETRICS

These metrics can change when the DPI of a Window changes, so we can not keep a
static reference.

According to documentation, the second parameter (uiParam) should be set to the
size of the NONCLIENTMETRICS object.
This commit is contained in:
Maarten Bent
2019-07-14 17:15:03 +02:00
parent 0a79c48631
commit b87a599f07

View File

@@ -22,10 +22,14 @@ namespace wxMSWImpl
// in the future
//
// MT-safety: this function is only meant to be called from the main thread
inline const NONCLIENTMETRICS& GetNonClientMetrics(const wxWindow* win)
inline const NONCLIENTMETRICS GetNonClientMetrics(const wxWindow* win)
{
static WinStruct<NONCLIENTMETRICS> nm;
if ( !wxSystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &nm, 0 , win) )
WinStruct<NONCLIENTMETRICS> nm;
if ( !wxSystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS),
&nm,
0,
win) )
{
#if WINVER >= 0x0600
// a new field has been added to NONCLIENTMETRICS under Vista, so
@@ -33,7 +37,11 @@ inline const NONCLIENTMETRICS& GetNonClientMetrics(const wxWindow* win)
// size incorporating this new value on an older system -- retry
// without it
nm.cbSize -= sizeof(int);
if ( !wxSystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &nm, 0, win) )
if ( !wxSystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS),
&nm,
0,
win) )
#endif // WINVER >= 0x0600
{
// maybe we should initialize the struct with some defaults?