# HG changeset patch # User John Reimer # Date 1203269411 28800 # Node ID d6bf6a720cde578bb1a3d240a15bd1d52f4f83fe # Parent c290741fbb6b40a8cc448fe24b54bd024277a927 Minor cleanup and organization of Activation Context Code diff -r c290741fbb6b -r d6bf6a720cde dwt/internal/win32/OS.d --- a/dwt/internal/win32/OS.d Fri Feb 15 03:29:01 2008 +0100 +++ b/dwt/internal/win32/OS.d Sun Feb 17 09:30:11 2008 -0800 @@ -154,7 +154,7 @@ public static const int COMCTL32_MAJOR, COMCTL32_MINOR, COMCTL32_VERSION; public static const int SHELL32_MAJOR, SHELL32_MINOR, SHELL32_VERSION; - public static const char[] NO_MANIFEST = "org.eclipse.swt.internal.win32.OS.NO_MANIFEST"; + public static const char[] NO_MANIFEST = "dwt.internal.win32.OS.NO_MANIFEST"; /* @@ -269,73 +269,9 @@ //IsUnicode = !IsWin32s && !IsWin95; /* Load the manifest to force the XP Theme */ - if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { - - const char[] manifest = ` - - - D Widget Toolkit - - - - - -`; - - scope temp = new tango.io.TempFile.TempFile(tango.io.TempFile.TempFile.Permanent); - temp.write(manifest); - temp.detach(); - - ACTCTX actctx; - actctx.cbSize = actctx.sizeof; - actctx.lpSource = StrToTCHARz( 0, temp.toString ); - - // Create the activation context - HANDLE hActCtx = OS.CreateActCtx(&actctx); - - // Did we fail creating the activation context? - if (hActCtx is INVALID_HANDLE_VALUE){ - Trace.formatln("The Activation Context could not be created"); - goto LActCtxError; - } - - // Activate the context and make use of it - ULONG_PTR ulpActivationCookie; - if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){ - Trace.formatln("The Activation Context failed to load"); - goto LActCtxError; - } - - LActCtxError: - temp.path.remove(); - -/+ //if (System.getProperty (NO_MANIFEST) is null) { - TCHAR[] buffer = new TCHAR[ MAX_PATH ]; - HANDLE hModule = OS.GetLibraryHandle (); - while (OS.GetModuleFileName (hModule, buffer.ptr, buffer.length ) is buffer.length ) { - buffer.length = buffer.length + MAX_PATH; - } - auto hHeap = OS.GetProcessHeap (); - int byteCount = buffer.length * TCHAR.sizeof; - TCHAR* pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (pszText, buffer.ptr, byteCount); - ACTCTX pActCtx; - pActCtx.cbSize = ACTCTX.sizeof; - pActCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT; - pActCtx.lpSource = pszText; - pActCtx.lpResourceName = cast(TCHAR*)MANIFEST_RESOURCE_ID; - HANDLE hActCtx = OS.CreateActCtx (&pActCtx); - if (pszText !is null) OS.HeapFree (hHeap, 0, pszText); - uint lpCookie; - OS.ActivateActCtx (hActCtx, &lpCookie); - /* - * NOTE: A single activation context is created and activated - * for the entire lifetime of the program. It is deactivated - * and released by Windows when the program exits. - */ - //} -+/ - } + + enableVisualStyles(); + /* Make the process DPI aware for Windows Vista */ if (OS.WIN32_VERSION >= OS.VERSION (6, 0)) OS.SetProcessDPIAware (); @@ -410,8 +346,95 @@ SHELL32_MINOR = dvi.dwMinorVersion; SHELL32_VERSION = VERSION (SHELL32_MAJOR, SHELL32_MINOR); } - + + /************************************************************************** + + **************************************************************************/ + + public static void enableVisualStyles() + { + if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { + const char[] manifest = + ` + + + D Widget Toolkit + + + + + + `; + + scope temp = new tango.io.TempFile.TempFile(tango.io.TempFile.TempFile.Permanent); + temp.write(manifest); + temp.detach(); + + ACTCTX actctx; + actctx.cbSize = actctx.sizeof; + actctx.dwFlags = 0; + actctx.lpSource = StrToTCHARz( 0, temp.toString ); + + // Create the activation context + HANDLE hActCtx = OS.CreateActCtx(&actctx); + + // Did we fail creating the activation context? + if (hActCtx is INVALID_HANDLE_VALUE){ + Trace.formatln("The Activation Context could not be created"); + } else { + // Activate the context and make use of it + ULONG_PTR ulpActivationCookie; + if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){ + Trace.formatln("The Activation Context failed to load"); + } + } + + temp.path.remove(); + +/+ + //if (System.getProperty (NO_MANIFEST) is null) { + TCHAR[] buffer = new TCHAR[ MAX_PATH ]; + HANDLE hModule = OS.GetLibraryHandle (); + while (OS.GetModuleFileName (hModule, buffer.ptr, buffer.length ) is buffer.length ) { + buffer.length = buffer.length + MAX_PATH; + } + auto hHeap = OS.GetProcessHeap (); + int byteCount = buffer.length * TCHAR.sizeof; + TCHAR* pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount); + OS.MoveMemory (pszText, buffer.ptr, byteCount); + ACTCTX pActCtx; + pActCtx.cbSize = ACTCTX.sizeof; + pActCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT; + pActCtx.lpSource = pszText; + pActCtx.lpResourceName = cast(TCHAR*)MANIFEST_RESOURCE_ID; + HANDLE hActCtx = OS.CreateActCtx (&pActCtx); + if (pszText !is null) OS.HeapFree (hHeap, 0, pszText); + uint lpCookie; + OS.ActivateActCtx (hActCtx, &lpCookie); + /* + * NOTE: A single activation context is created and activated + * for the entire lifetime of the program. It is deactivated + * and released by Windows when the program exits. + */ + //} ++/ + } + } + + /************************************************************************** + + **************************************************************************/ + /* Flag used on WinCE */ + static const int SYS_COLOR_INDEX_FLAG = OS.IsWinCE ? 0x40000000 : 0x0; /*