[入门] Win32应用程序界面本地化问题
fanyard
2007-10-19
各位老大,我刚刚接触D语言没多久,DMD自带例子中有一个winsamp.d的程序,编译后能够正常运行,想让界面看起来跟XP一样,就创建了一个winsamp.exe.manifest文件,再次运行这个示例程序,按钮就不见了,各位前辈们能帮忙看看是什么问题么?
winsamp.exe.manifest如下 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity name="winsamp.exe" processorArchitecture="x86" version="5.1.0.0" type="win32"/> <description>Windows Shell</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly> |
|
ant-man
2007-10-19
摘自DFL,为了让wxD有本地的Feel and look
在所有UI构建之前调用 void main() { enableVisualStyles() ; ..... } module Pigersing.aUI.abase ; import tango.sys.win32.Types ; import tango.sys.win32.UserGdi ; // Should be called before creating any controls. // This is typically the first function called in main(). // Does nothing if not supported. static void enableVisualStyles() { HMODULE kernel32; kernel32 = GetModuleHandleA("kernel32.dll"); const char[] MANIFEST = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>` \r\n `<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">` \r\n `<description>DFL manifest</description>` \r\n `<dependency>` \r\n `<dependentAssembly>` \r\n `<assemblyIdentity ` `type="win32" ` `name="Microsoft.Windows.Common-Controls" ` `version="6.0.0.0" ` `processorArchitecture="X86" ` `publicKeyToken="6595b64144ccf1df" ` `language="*" ` `/>` \r\n `</dependentAssembly>` \r\n `</dependency>` \r\n `</assembly>` \r\n; assert(kernel32); { CreateActCtxWProc createActCtxW; createActCtxW = cast(CreateActCtxWProc)GetProcAddress(kernel32, "CreateActCtxW"); if (createActCtxW) { GetTempPathWProc getTempPathW; GetTempFileNameWProc getTempFileNameW; ActivateActCtxProc activateActCtx; getTempPathW = cast(GetTempPathWProc)GetProcAddress(kernel32, "GetTempPathW"); assert(getTempPathW !is null); getTempFileNameW = cast(GetTempFileNameWProc)GetProcAddress(kernel32, "GetTempFileNameW"); assert(getTempFileNameW !is null); activateActCtx = cast(ActivateActCtxProc)GetProcAddress(kernel32, "ActivateActCtx"); assert(activateActCtx !is null); DWORD pathlen; wchar[MAX_PATH] pathbuf = void; //if(pathbuf) { pathlen = getTempPathW(pathbuf.length, pathbuf.ptr); if (pathlen) { DWORD manifestlen; wchar[MAX_PATH] manifestbuf = void; //if(manifestbuf) { manifestlen = getTempFileNameW(pathbuf.ptr, "dmf", 0, manifestbuf.ptr); if (manifestlen) { HANDLE hf; hf = CreateFileW(manifestbuf.ptr, GENERIC_WRITE, 0, null, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, HANDLE.init); if (hf != INVALID_HANDLE_VALUE) { DWORD written; if (WriteFile(hf, MANIFEST.ptr, MANIFEST.length, &written, null)) { CloseHandle(hf); ACTCTXW ac; HANDLE hac; ac.cbSize = ACTCTXW.sizeof; ac.dwFlags = 0; ac.lpSource = manifestbuf.ptr; hac = createActCtxW(&ac); if (hac != INVALID_HANDLE_VALUE) { ULONG_PTR ul; activateActCtx(hac, &ul); _initCommonControls(ICC_STANDARD_CLASSES); // ? } else { debug(APP_PRINT) printf("CreateActCtxW failed.\n"); } } else { CloseHandle(hf); } } DeleteFileW(manifestbuf.ptr); } } } } } } } // For this to work properly on Windows 95, Internet Explorer 4.0 must be installed. private void _initCommonControls(DWORD dwControls) { version(SUPPORTS_COMMON_CONTROLS_EX) { pragma(msg, "DFL: extended common controls supported at compile time"); alias InitCommonControlsEx initProc; } else { // Make sure InitCommonControlsEx() is in comctl32.dll, // otherwise use the old InitCommonControls(). HMODULE hmodCommonControls; InitCommonControlsExProc initProc; hmodCommonControls = LoadLibraryA("comctl32.dll"); if (!hmodCommonControls) // throw new DflException("Unable to load 'comctl32.dll'"); goto no_comctl32; initProc = cast(InitCommonControlsExProc)GetProcAddress(hmodCommonControls, "InitCommonControlsEx"); if (!initProc) { //FreeLibrary(hmodCommonControls); no_comctl32: InitCommonControls(); return; } } INITCOMMONCONTROLSEX icce; icce.dwSize = INITCOMMONCONTROLSEX.sizeof; icce.dwICC = dwControls; initProc(&icce); } private extern(Windows) { alias UINT function(LPCWSTR lpPathName, LPCWSTR lpPrefixString, UINT uUnique, LPWSTR lpTempFileName) GetTempFileNameWProc; alias DWORD function(DWORD nBufferLength, LPWSTR lpBuffer) GetTempPathWProc; alias HANDLE function(PACTCTXW pActCtx) CreateActCtxWProc; alias BOOL function(HANDLE hActCtx, ULONG_PTR* lpCookie) ActivateActCtxProc; alias BOOL function(LPINITCOMMONCONTROLSEX lpInitCtrls) InitCommonControlsExProc; } private struct INITCOMMONCONTROLSEX { DWORD dwSize; DWORD dwICC; } alias INITCOMMONCONTROLSEX* LPINITCOMMONCONTROLSEX ; private struct ACTCTXW { ULONG cbSize; DWORD dwFlags; LPCWSTR lpSource; USHORT wProcessorArchitecture; LANGID wLangId; LPCWSTR lpAssemblyDirectory; LPCWSTR lpResourceName; LPCWSTR lpApplicationName; HMODULE hModule; } alias ACTCTXW* PACTCTXW; private const ICC_STANDARD_CLASSES = 0x00004000 ; |
|
fanyard
2007-10-24
谢谢,我研究一下。
|