0

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?

Dean
  • 6,610
  • 6
  • 40
  • 90
  • 2
    I don't think you can turn the _Themes_ system service on for your application only while it's turned off for entire system (Windows 7). You have to respect user choice :) However I have no documented evidence for that. – Ruslan Garipov Dec 15 '15 at 18:31
  • 1
    Aero is basically removed from Win8. In Win10 (and I think Win8) `IsAppThemed` is always `TRUE` but it always shows boring square edged buttons. – Barmak Shemirani Dec 15 '15 at 19:39
  • 2
    If themes are off they're off, and presumably the user wanted it that way. Just make your app work better without them. – Jonathan Potter Dec 15 '15 at 19:46
  • In W10, there are 17 visual effects listed in the Performance Options dialog. Not sure if there is a one to one correspondence with those and any of the `pszSubAppName` and `pszSubIdList` parameters used in [SetWindowTheme](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-setwindowtheme). [MS Docs](https://learn.microsoft.com/en-us/windows/win32/controls/uxctl-ref) expands on it, and perusing _uxtheme.h_ might provide further insights. – Laurie Stearn Jul 12 '20 at 15:37

1 Answers1

1

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Not entirely true, try to disable themes and start google chrome. It will start with the theme on regardless of your choice. – Dean Dec 16 '15 at 07:29
  • It's doing all the rendering itself I believe. I suspect that hope is clouding judgement. – David Heffernan Dec 16 '15 at 07:30
  • Hard to say, I'd need to inspect the sources. And right now I can't afford a decent pc to even compile it in non-biblical times. – Dean Dec 16 '15 at 07:51
  • 1
    Chrome does all its own rendering. The caption bar with tabs is not a Windows feature. The GUI widgets are all Chrome specific and not platform controls. – David Heffernan Dec 16 '15 at 07:54
  • But how can it draw the X button the same style I have applied on my system (even if I dabble with the colors for visually impaired people)? – Dean Dec 16 '15 at 08:02
  • Any program can draw anything. My guess is that it knows where to extract the icon from in the style file, but that it relies on undocumented implementation details. – David Heffernan Dec 16 '15 at 08:06