diff --git a/include/wx/msw/init.h b/include/wx/msw/init.h index 014dedbd09..8636890aee 100644 --- a/include/wx/msw/init.h +++ b/include/wx/msw/init.h @@ -30,6 +30,10 @@ typedef char *wxCmdLineArgType; #endif +// Call this function to prevent wxMSW from calling SetProcessDPIAware(). +// Must be called before wxEntry(). +extern WXDLLIMPEXP_CORE void wxMSWDisableSettingHighDPIAware(); + // Windows-only overloads of wxEntry() and wxEntryStart() which take the // parameters passed to WinMain() instead of those passed to main() extern WXDLLIMPEXP_CORE bool diff --git a/interface/wx/app.h b/interface/wx/app.h index e7c10de408..b05db95151 100644 --- a/interface/wx/app.h +++ b/interface/wx/app.h @@ -1089,7 +1089,11 @@ int wxEntry(int& argc, wxChar** argv); } @endcode + @onlyfor{wxmsw} + @header{wx/app.h} + + @see wxMSWDisableSettingHighDPIAware() */ int wxEntry(HINSTANCE hInstance, HINSTANCE hPrevInstance = NULL, diff --git a/interface/wx/init.h b/interface/wx/init.h index 23404f6ff1..beff4c4b4d 100644 --- a/interface/wx/init.h +++ b/interface/wx/init.h @@ -107,5 +107,22 @@ bool wxInitialize(int argc = 0, wxChar **argv = NULL); */ void wxUninitialize(); +/** + Prevents wxWidgets from setting HighDPI awareness mode. + + wxEntry calls SetDPIProcessAware() early during initialization on Windows. + To prevent this (e.g. because wx is embedded in native code and disabling + DPI awareness in the manifest is not an option), call this function + *before* wxEntry() is called. + + @onlyfor{wxmsw} + + @header{wx/init.h} + + @since 3.0.3, but only available in 3.0.x, not 3.1+ which doesn't make + the SetDPIProcessAware() call anymore. +*/ +void wxMSWDisableSettingHighDPIAware(); + //@} diff --git a/src/msw/main.cpp b/src/msw/main.cpp index 65b4fc1750..c6bd7a6329 100644 --- a/src/msw/main.cpp +++ b/src/msw/main.cpp @@ -297,8 +297,23 @@ void wxSetProcessDPIAware() #endif // wxUSE_DYNLIB_CLASS } +// It is sometimes undesirable to force DPI awareness on appplications, e.g. +// when they are artwork heavy and don't have appropriately scaled bitmaps, or +// when they are using non-wx, DPI-unaware code. Allow disabling +// SetProcessDPIAware() call. +// +// Further discussion: +// http://trac.wxwidgets.org/ticket/16116 +// https://groups.google.com/d/topic/wx-dev/Z0VpgzCY34U/discussion +bool gs_allowChangingDPIAwareness = true; + } //anonymous namespace +void wxMSWDisableSettingHighDPIAware() +{ + gs_allowChangingDPIAwareness = false; +} + // ---------------------------------------------------------------------------- // Windows-specific wxEntry // ---------------------------------------------------------------------------- @@ -405,7 +420,9 @@ WXDLLEXPORT int wxEntry(HINSTANCE hInstance, // http://msdn.microsoft.com/en-us/library/dd464659%28VS.85%29.aspx). // Note that we intentionally do it here and not in wxApp, so that it // doesn't happen if wx code is hosted in another app (e.g. a plugin). - wxSetProcessDPIAware(); + // It can be disabled by calling wxMSWAllowChangingDPIAwareness(). + if ( gs_allowChangingDPIAwareness ) + wxSetProcessDPIAware(); if ( !wxMSWEntryCommon(hInstance, nCmdShow) ) return -1;