我期待有vista / win7使用Aero风格的窗口,而XP用户使用正常的窗口风格(如何得到Windows XP stlye而不是win95风格btw?)
这个想法是这样的:
OSVERSIONINFOEX osvi; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); GetVersionEx((OSVERSIONINFO*)&osvi); if (osvi.dwMajorVersion > 5) { #pragma comment(linker,"/manifestdependency:\"type='win32' "\ "name='Microsoft.Windows.Common-Controls' "\ "version='6.0.0.0' "\ "processorArchitecture='x86' "\ "publicKeyToken='6595b64144ccf1df' "\ "language='*' "\ "\"") }
现在,不pipeif语句是真还是假,#pragma都会被执行,我猜这就是#pragma的工作方式。 当然还有一些其他的方式来得到这个工作(像#ifndef #define … #endif我猜)
干杯
您正在编译时间评估杂注与运行时代码的执行。 显然这是行不通的。
可以在“PutYourProgramNameHere.exe.manifest”文件中保留应用程序的清单。 因此,如果您需要XP和Vista / Win7的不同清单,则可以在目标计算机上安装应用程序时安装不同的清单文件。 即您的安装程序检查操作系统版本并安装匹配清单。
您可以使用Activation Context API函数来执行此操作。 要求是:
LoadLibrary
& GetProcAddress
实际加载有问题的API函数,因为它们在NT 5.1之前不存在 此示例代码假定清单被嵌入为RT_MANIFEST资源,其ID为17.TestOSVersion()是您决定是否要使用蒙版窗口的函数。
ACTCTX actx = {0}; actx.cbSize = sizeof(ACTCTX); actx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID; actx.lpResourceName = MAKEINTRESOURCE(17); actx.hmodulee = GetmoduleeHandle(NULL); // assumes the manifest is exe embedded. HANDLE hactx = INVALID_HANDLE_VALUE; if(TestOsVersion()) hactx = CreateActCtx(&actx); ULONG_PTR actxCookie = NULL; if (hactx != INVALID_HANDLE_VALUE) ActivateActCtx(hactx,&actxCookie); // Now, with the activation context active, create the dialog box // or window or whatever. HWND hwndDialog = CreateDialogBoxParam(...); // and pop the context. It doesn't matter if the dialog still exists, the // ctl6 dll is now loaded and serving requests. if (hactx != INVALID_HANDLE_VALUE) DeactivateActCtx(0,actxCookie);
显然,为了使这个工作,v6公共控制不能在进程默认清单。