Win32. Enable visual styles in dll

别等时光非礼了梦想. 提交于 2019-11-29 02:37:31
Alexey Ivanov

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!