From 88031d7ae618779268d5b07b3aaea4eefabcaf08 Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Thu, 1 Mar 2012 02:44:44 +0000 Subject: [PATCH] Add pre-initialization code, which on Windows will initialize the activation context, giving us proper themed drawing. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70762 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- etg/_core.py | 4 +++ src/app_ex.cpp | 56 -------------------------------------- src/core_ex.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 71 insertions(+), 61 deletions(-) diff --git a/etg/_core.py b/etg/_core.py index e3e884d9..f693ca91 100644 --- a/etg/_core.py +++ b/etg/_core.py @@ -345,6 +345,10 @@ def run(): ]) + module.addPreInitializerCode("""\ + wxPyPreInit(sipModuleDict); + """) + # This code is inserted into the module initialization function module.addPostInitializerCode("""\ wxPyCoreModuleInject(sipModuleDict); diff --git a/src/app_ex.cpp b/src/app_ex.cpp index f5f38b5a..fb677138 100644 --- a/src/app_ex.cpp +++ b/src/app_ex.cpp @@ -17,62 +17,6 @@ #ifdef __WXMSW__ // If building for Windows... -//---------------------------------------------------------------------- -// Use an ActivationContext to ensure that the new (themed) version of -// the comctl32 DLL is loaded. -//---------------------------------------------------------------------- - -// Note that the use of the ISOLATION_AWARE_ENABLED define replaces the -// activation context APIs with wrappers that dynamically load the API -// pointers from the kernel32 DLL so we don't have to do that ourselves. -// Using ISOLATION_AWARE_ENABLED also causes the manifest resource to be put -// in slot #2 as expected for DLLs. (See wx/msw/wx.rc) - -#if 0 //#ifdef ISOLATION_AWARE_ENABLED - -static ULONG_PTR wxPySetActivationContext() -{ - - OSVERSIONINFO info; - wxZeroMemory(info); - info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&info); - if (info.dwMajorVersion < 5) - return 0; - - ULONG_PTR cookie = 0; - HANDLE h; - ACTCTX actctx; - TCHAR modulename[MAX_PATH]; - - GetModuleFileName(wxGetInstance(), modulename, MAX_PATH); - wxZeroMemory(actctx); - actctx.cbSize = sizeof(actctx); - actctx.lpSource = modulename; - actctx.lpResourceName = MAKEINTRESOURCE(2); - actctx.hModule = wxGetInstance(); - actctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID; - - h = CreateActCtx(&actctx); - if (h == INVALID_HANDLE_VALUE) { - wxLogLastError(wxT("CreateActCtx")); - return 0; - } - - if (! ActivateActCtx(h, &cookie)) - wxLogLastError(wxT("ActivateActCtx")); - - return cookie; -} - -static void wxPyClearActivationContext(ULONG_PTR cookie) -{ - if (! DeactivateActCtx(0, cookie)) - wxLogLastError(wxT("DeactivateActCtx")); -} - -#endif // ISOLATION_AWARE_ENABLED - //---------------------------------------------------------------------- // This gets run when the DLL is loaded. We just need to save the // instance handle. diff --git a/src/core_ex.cpp b/src/core_ex.cpp index 1c63e833..dff721c9 100644 --- a/src/core_ex.cpp +++ b/src/core_ex.cpp @@ -1,9 +1,73 @@ +#ifdef __WXMSW__ // If building for Windows... + +#include +#include +#include + +//---------------------------------------------------------------------- +// Use an ActivationContext to ensure that the new (themed) version of +// the comctl32 DLL is loaded. +//---------------------------------------------------------------------- + +// Note that the use of the ISOLATION_AWARE_ENABLED define replaces the +// activation context APIs with wrappers that dynamically load the API +// pointers from the kernel32 DLL so we don't have to do that ourselves. +// Using ISOLATION_AWARE_ENABLED also causes the manifest resource to be put +// in slot #2 as expected for DLLs. (See wx/msw/wx.rc) + +#ifdef ISOLATION_AWARE_ENABLED + +static ULONG_PTR wxPySetActivationContext() +{ + + OSVERSIONINFO info; + wxZeroMemory(info); + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&info); + if (info.dwMajorVersion < 5) + return 0; + + ULONG_PTR cookie = 0; + HANDLE h; + ACTCTX actctx; + TCHAR modulename[MAX_PATH]; + + GetModuleFileName(wxGetInstance(), modulename, MAX_PATH); + wxZeroMemory(actctx); + actctx.cbSize = sizeof(actctx); + actctx.lpSource = modulename; + actctx.lpResourceName = MAKEINTRESOURCE(2); + actctx.hModule = wxGetInstance(); + actctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID; + + h = CreateActCtx(&actctx); + if (h == INVALID_HANDLE_VALUE) { + wxLogLastError(wxT("CreateActCtx")); + return 0; + } + + if (! ActivateActCtx(h, &cookie)) + wxLogLastError(wxT("ActivateActCtx")); + + return cookie; +} + +static void wxPyClearActivationContext(ULONG_PTR cookie) +{ + if (! DeactivateActCtx(0, cookie)) + wxLogLastError(wxT("DeactivateActCtx")); +} + +#endif // ISOLATION_AWARE_ENABLED + +#endif // __WXMSW__ + void wxPyPreInit(PyObject* moduleDict) { -//#ifdef ISOLATION_AWARE_ENABLED -// wxPySetActivationContext(); -//#endif +#ifdef ISOLATION_AWARE_ENABLED + wxPySetActivationContext(); +#endif //#ifdef __WXMSW__ //// wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF //// | _CRTDBG_CHECK_ALWAYS_DF @@ -27,8 +91,6 @@ void wxPyPreInit(PyObject* moduleDict) // Ensure that the build options in the DLL (or whatever) match this build wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "wxPython"); - - wxInitAllImageHandlers(); }