How to Enable Visual Styles Without a Manifest

How to enable visual styles without a manifest

If you're using Visual Studio, you can add this line to your stdafx.cpp for example:

#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

Win32: enabling visual styles in MinGW without manifest

Well, it seems as if writing a resource/manifest is the only way forward here, so I have to proceed that way.

How to enable visual styles without a manifest

Use mt.exe to embed the manifest into the executable as a resource. This is a standard part of the build since VS2005, use a project template if you have trouble setting it up properly.

Win32. Enable visual styles in dll

If you want your DLL to use visual style aware controls, i.e. comctl32 v6, even if your host application does not use it, you have to use Activation Context API. Here's an example on how to use it:

 HANDLE hActCtx;
ACTCTX actCtx;
ZeroMemory(&actCtx, sizeof(actCtx));
actCtx.cbSize = sizeof(actCtx);
actCtx.hModule = hInst;
actCtx.lpResourceName = MAKEINTRESOURCE(2);
actCtx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID;

hActCtx = CreateActCtx(&actCtx);
if (hActCtx != INVALID_HANDLE_VALUE) {
ULONG_PTR cookie;
ActivateActCtx(hActCtx, &cookie);

// Do some UI stuff here; just show a message for example
MessageBox(NULL, TEXT("Styled message box"), NULL, MB_OK);

DeactivateActCtx(0, cookie);
ReleaseActCtx(hActCtx);
}

Here hInst is the module handle of your DLL, you can save it in a global variable in DllMain or use GetModuleHandle function to get it. This sample implies your DLL stores Common Controls version 6.0 manifest in its resources with ID 2.

You can call CreateActCtx only once when your DLL initializes, and ReleaseActCtx when it's not needed any more. Call ActivateActCtx before creating any windows and call DeactivateActCtx before returning control to application.

Disabling visual styles in manifest while retaining Common Controls functionality

To disable visual styles for all controls, call SetThemeAppProperties(STAP_ALLOW_NONCLIENT) or SetThemeAppProperties(0) before you create your main window.

To disable visual styles per HWND you can call SetWindowTheme(hwndControl,L"",L"")

If you need to support systems without v6 common controls you can probably figure out which system metrics (or hardcoded values) are used in the toolbar control by playing with the system metric values and system DPI.

Selectively Enable Visual Styles on Dialogs/Windows

The answer is mentioned on the page you referenced. http://msdn.microsoft.com/en-us/library/bb773175.aspx#turnoff



Related Topics



Leave a reply



Submit