Ter*_*ver 11 c++ winapi comctl32 visual-styles
根据文件:
"如果您希望应用程序使用ComCtl32.dll版本6,则必须添加应用程序清单或编译器指令,以指定如果版本6可用,则应使用该版本."
注意上面的逻辑OR?那么这个神秘的编译器指令是什么?
我有一个原生的Win32 C++应用程序,它完全包含在一个.cpp文件中.没有资源文件,清单文件等.我想保持这种方式,但我也想使用视觉样式.
Meh*_*dad 27
实际上还有第三种方式,没有任何明显的表现,尽管它相当hacky:
#include <windows.h>
// NOTE: It is recommended that you delay-load ComCtl32.dll (/DelayLoad:ComCtl32.dll)
// and that you ensure this code runs before GUI components are loaded.
// Otherwise, you may get weird issues, like black backgrounds in icons in image lists.
ULONG_PTR EnableVisualStyles(VOID)
{
TCHAR dir[MAX_PATH];
ULONG_PTR ulpActivationCookie = FALSE;
ACTCTX actCtx =
{
sizeof(actCtx),
ACTCTX_FLAG_RESOURCE_NAME_VALID
| ACTCTX_FLAG_SET_PROCESS_DEFAULT
| ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID,
TEXT("shell32.dll"), 0, 0, dir, (LPCTSTR)124
};
UINT cch = GetSystemDirectory(dir, sizeof(dir) / sizeof(*dir));
if (cch >= sizeof(dir) / sizeof(*dir)) { return FALSE; /*shouldn't happen*/ }
dir[cch] = TEXT('\0');
ActivateActCtx(CreateActCtx(&actCtx), &ulpActivationCookie);
return ulpActivationCookie;
}
Run Code Online (Sandbox Code Playgroud)
Sim*_*ier 13
如果您使用的是Visual Studio,则可以将此行添加到stdafx.cpp中,例如:
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
Run Code Online (Sandbox Code Playgroud)
如果你一直在阅读,你会找到答案:
如果您使用的是Microsoft Visual C++ 2005或更高版本,则可以将以下编译器指令添加到源代码中,而不是手动创建清单.为了便于阅读,该指令在这里分为两行.
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls'
version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11144 次 |
| 最近记录: |