There's actually a third way with no manifests whatsoever, though it's rather 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('');
ActivateActCtx(CreateActCtx(&actCtx), &ulpActivationCookie);
return ulpActivationCookie;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…