c++windowswinapiwindows-themes

Activate theme for a window if disabled system-wide


I'm writing a Windows (no MFC or Qt) win32 app on a Windows 7 system targeting 7, 8 and 10.

My app detects if Aero is enabled and handles both aero and non-aero correctly, but it renders awfully when there is no visual style in the OS (i.e. the "Apply visual styles for windows and buttons" check box is turned off in the Performance Options dialog of the Control Panel).

I can detect if my application is started with no themes with IsAppThemed but I can't seem to figure out how to directly create the window with the style enabled or to force-enable the style.. this is what I tried and it's not working:

  case WM_CREATE: {
    if (IsAppThemed() == FALSE) {
      // No visual style is applied
      SetThemeAppProperties(STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS);
      SendMessage(hWnd, WM_THEMECHANGED, 0, 0);
      RedrawWindow(hWnd, 0, 0, RDW_UPDATENOW);
    }
  } break;

Not even

SetWindowTheme(hWnd, 0, 0);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

worked.

How can I force-enable styles if I detect they're disabled?


Solution

  • If the user decides to disable themes you cannot over turn that decision. You'll just have to cope with it. The obvious way forward is to improve your application's behaviour in this scenario.