Allow disabling SetProcessDPIAware() call

Add Windows-specific wxMSWDisableSettingHighDPIAware() function then can
be called before startup (i.e. wxEntry() call) to disable wxWidgets'
handling of DPI awareness. This is useful for code embedded in non-wx
applications as well as for purely wx application that are not
HiDPI-ready (although the latter has the option of forcing
dpiAware=false in the manifest).

See also https://groups.google.com/d/msg/wx-dev/Z0VpgzCY34U/f1FfPqGDppMJ
and #16116.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@78406 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2015-01-24 15:00:03 +00:00
parent f4ac4fcab6
commit 14f052a768
4 changed files with 43 additions and 1 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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();
//@}

View File

@@ -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,6 +420,8 @@ 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).
// It can be disabled by calling wxMSWAllowChangingDPIAwareness().
if ( gs_allowChangingDPIAwareness )
wxSetProcessDPIAware();
if ( !wxMSWEntryCommon(hInstance, nCmdShow) )