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
Constexpr Function Parameters as Template Arguments
Write and Read String to Binary File C++
Link .So File to .Cpp File via G++ Compiling
How to Download a File with Winhttp in C/C++
C++:Friend Declaration 'Declares a Non-Template Function
Operator Overload Which Permits Capturing with Rvalue But Not Assigning To
Paint a Rect on Qglwidget at Specifit Times
Define Constant Variables in C++ Header
How to Estimate the Thread Context Switching Overhead
Cmake: Failed to Run Msbuild Command: Msbuild.Exe
How to Declare Variables of Different Types in the Initialization of a for Loop
If Temporaries Are Implicitly Non-Modifiable, How Does This Work
How to Write to Middle of a File in C++
Infinite Loops - Top or Bottom
I Want to Generate the Nth Term of the Sequence 1,3,8,22,60 ,164 in Order(1) or Order of (Nlogn)