Changeset 188:03f179597782

Show
Ignore:
Timestamp:
03/14/08 19:33:19 (7 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Make WinXP themes work with windows resources

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • README.txt

    r176 r188  
    4141Without this option, DWT renderes some controls not correctly. Eg. table headers are not shown. 
    4242 
     43 
     44WinXP Theming and Controls 
     45========================== 
     46With WinXP it is required to make windows use a manifest. 
     47There are several ways to make this manifest available. 
     481.) Place the manifest file in the same directory where the .exe is. 
     49    E.g. 
     50        application.exe 
     51        application.exe.manifest 
     522.) Link the content of the manifest to the application as a windows resource. 
     533.) Have another program that uses resource injection to put the manifest into the application 
     544.) Let the application write the manifest to a an external file and load it. 
     55    This had problems in the past, some applications on some machines did not load images. 
     56 
     571. .. 3.) Seems to work reliable. 
     58 
     59 * Using 2. 
     60   compile the dwt.rc/dwt.exe.manifest files with rcc.exe from the digitalmars to create the dwt.res. 
     61     rcc dwt.rc 
     62   link the resulting dwt.res with the -L/rc:dwt.res 
     63 
    4364Changes/Additions to SWT 
    4465======================== 
  • dwt/internal/win32/OS.d

    r181 r188  
    2020import dwt.internal.Library; 
    2121import tango.sys.SharedLib : SharedLib; 
     22import tango.sys.Common : SysError; 
    2223static import tango.stdc.stdlib; 
    2324 
     
    168169    /* Forward references */ 
    169170    public static const int HEAP_ZERO_MEMORY = 0x8; 
    170     public static const int ACTCTX_FLAG_RESOURCE_NAME_VALID = 0x00000008; 
    171     public static const int ACTCTX_FLAG_SET_PROCESS_DEFAULT = 0x00000010; 
    172     public static const int MANIFEST_RESOURCE_ID = 2; 
     171    public static const int ACTCTX_FLAG_RESOURCE_NAME_VALID    = 0x00000008; 
     172    public static const int ACTCTX_FLAG_SET_PROCESS_DEFAULT    = 0x00000010; 
     173    public static const int ACTCTX_FLAG_APPLICATION_NAME_VALID = 0x00000020; 
     174    public static const int ACTCTX_FLAG_OVERRIDEMANIFEST_VALID = 0x00000100; 
     175    public static const TCHAR* MANIFEST_RESOURCE_ID = cast(TCHAR*)2; 
    173176    public static const int SM_DBCSENABLED = 0x2A; 
    174177    public static const int SM_IMMENABLED = 0x52; 
     
    249252        WIN32_VERSION = VERSION (WIN32_MAJOR, WIN32_MINOR); 
    250253 
     254        if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { 
     255            loadLib( Symbols_Kernel32, `Kernel32.dll` ); 
     256        } 
     257 
     258        //PORTING_CHANGE: made by version 
     259        //IsUnicode = !IsWin32s && !IsWin95; 
     260 
     261        /* Load the manifest to force the XP Theme */ 
     262        enableVisualStyles(); 
     263 
    251264        // when to load uxtheme 
    252265        if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { 
     
    262275            loadLib( Symbols_Imm32, `Imm32.dll` ); 
    263276        } 
    264         if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { 
    265             loadLib( Symbols_Kernel32, `Kernel32.dll` ); 
    266         } 
    267  
    268         //PORTING_CHANGE: made by version 
    269         //IsUnicode = !IsWin32s && !IsWin95; 
    270  
    271         /* Load the manifest to force the XP Theme */ 
    272          
    273         enableVisualStyles(); 
    274277 
    275278        /* Make the process DPI aware for Windows Vista */ 
     
    347350        SHELL32_VERSION = VERSION (SHELL32_MAJOR, SHELL32_MINOR); 
    348351    } 
    349      
     352 
    350353    /************************************************************************** 
    351      
     354 
    352355    **************************************************************************/ 
    353      
    354     public static void enableVisualStyles() 
    355     { 
    356         if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { 
    357             const char[] manifest =  
    358             `<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    359             <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
    360                 <assemblyIdentity  
    361                     version="1.0.0.0"  
    362                     processorArchitecture="X86"  
    363                     name="dwt"  
    364                     type="win32"/> 
    365                 <description>D Widget Toolkit</description> 
    366                 <dependency> 
    367                     <dependentAssembly> 
    368                         <assemblyIdentity type="win32"  
    369                             name="Microsoft.Windows.Common-Controls"  
    370                             version="6.0.0.0" processorArchitecture="X86"  
    371                             publicKeyToken="6595b64144ccf1df"  
    372                             language="*"/> 
    373                     </dependentAssembly> 
    374                 </dependency> 
    375             </assembly>`; 
    376  
    377             scope temp = new tango.io.TempFile.TempFile(tango.io.TempFile.TempFile.Permanent); 
    378             temp.write(manifest); 
    379             temp.detach(); 
    380  
    381             ACTCTX actctx; 
    382             actctx.cbSize = actctx.sizeof; 
    383             actctx.dwFlags = 0; 
    384             actctx.lpSource = StrToTCHARz( 0, temp.toString ); 
    385  
    386             // Create the activation context 
    387             HANDLE hActCtx = OS.CreateActCtx(&actctx); 
    388  
    389             // Did we fail creating the activation context? 
    390             if (hActCtx is INVALID_HANDLE_VALUE){ 
    391                 Trace.formatln("The Activation Context could not be created"); 
    392             } else { 
    393                 // Activate the context and make use of it 
    394                 ULONG_PTR ulpActivationCookie; 
    395                 if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){ 
    396                     Trace.formatln("The Activation Context failed to load"); 
    397                 } 
     356 
     357    public static void enableVisualStyles() { 
     358        void printError( char[] msg ){ 
     359            char[] winMsg = SysError.lastMsg(); 
     360            char[2000] buf; 
     361            Trace.formatln("{}: {}", msg, CodePage.from( winMsg, buf ) ); 
     362        } 
     363        TCHAR[] buffer = new TCHAR[ MAX_PATH ]; 
     364        buffer[] = 0; 
     365        HANDLE hModule = OS.GetLibraryHandle (); 
     366        while (OS.GetModuleFileName (hModule, buffer.ptr, buffer.length ) is buffer.length ) { 
     367            buffer.length = buffer.length + MAX_PATH; 
     368            buffer[] = 0; 
     369        } 
     370        auto hHeap = OS.GetProcessHeap (); 
     371        int byteCount = buffer.length * TCHAR.sizeof; 
     372        TCHAR* pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount); 
     373        OS.MoveMemory (pszText, buffer.ptr, byteCount); 
     374 
     375        ACTCTX pActCtx; 
     376        pActCtx.cbSize = ACTCTX.sizeof; 
     377        pActCtx.dwFlags = 0 
     378            | ACTCTX_FLAG_RESOURCE_NAME_VALID 
     379            | ACTCTX_FLAG_SET_PROCESS_DEFAULT 
     380            ; 
     381        pActCtx.lpSource = pszText; 
     382        pActCtx.lpApplicationName = pszText; 
     383        pActCtx.lpResourceName = MANIFEST_RESOURCE_ID; 
     384        HANDLE hActCtx = OS.CreateActCtx (&pActCtx); 
     385        if (hActCtx is INVALID_HANDLE_VALUE){ 
     386            printError("CreateActCtx failed" ); 
     387        } 
     388        else{ 
     389            ULONG_PTR ulpActivationCookie; 
     390            if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){ 
     391                printError("ActivateActCtx failed" ); 
    398392            } 
    399  
    400             temp.path.remove(); 
    401  
    402 /+          
    403             //if (System.getProperty (NO_MANIFEST) is null) { 
    404                 TCHAR[] buffer = new TCHAR[ MAX_PATH ]; 
    405                 HANDLE hModule = OS.GetLibraryHandle (); 
    406                 while (OS.GetModuleFileName (hModule, buffer.ptr, buffer.length ) is buffer.length ) { 
    407                     buffer.length = buffer.length + MAX_PATH; 
    408                 } 
    409                 auto hHeap = OS.GetProcessHeap (); 
    410                 int byteCount = buffer.length * TCHAR.sizeof; 
    411                 TCHAR* pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount); 
    412                 OS.MoveMemory (pszText, buffer.ptr, byteCount); 
    413                 ACTCTX pActCtx; 
    414                 pActCtx.cbSize = ACTCTX.sizeof; 
    415                 pActCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT; 
    416                 pActCtx.lpSource = pszText; 
    417                 pActCtx.lpResourceName = cast(TCHAR*)MANIFEST_RESOURCE_ID; 
    418                 HANDLE hActCtx = OS.CreateActCtx (&pActCtx); 
    419                 if (pszText !is null) OS.HeapFree (hHeap, 0, pszText); 
    420                 uint lpCookie; 
    421                 OS.ActivateActCtx (hActCtx, &lpCookie); 
    422                 /* 
    423                 * NOTE:  A single activation context is created and activated 
    424                 * for the entire lifetime of the program.  It is deactivated 
    425                 * and released by Windows when the program exits. 
    426                 */ 
    427         //} 
    428 +/ 
    429393        } 
    430     } 
    431      
     394 
     395        if (pszText !is null){ 
     396            OS.HeapFree (hHeap, 0, pszText); 
     397        } 
     398 
     399        /* 
     400        * NOTE:  A single activation context is created and activated 
     401        * for the entire lifetime of the program.  It is deactivated 
     402        * and released by Windows when the program exits. 
     403        */ 
     404    } 
     405 
    432406    /************************************************************************** 
    433      
     407 
    434408    **************************************************************************/ 
    435           
     409 
    436410    /* Flag used on WinCE */ 
    437      
     411 
    438412    static const int SYS_COLOR_INDEX_FLAG = OS.IsWinCE ? 0x40000000 : 0x0; 
    439413