-2

Is there any information available to the running program about which Win10 theme is being used?

I am looking primarily to get more debug information, as I have a user with a reported "scrambled GUI".

Is there any way to kill themes, or force to a default theme, from within the running program?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Henry Crun
  • 235
  • 1
  • 11

1 Answers1

2

If I understood your question correctly I would recommend to you to use SetWindowTheme.

You should check out information provided with link above to see what docs.microsoft (former msdn) tells us in Remark section:

When pszSubAppName and pszSubIdList are NULL, the theme manager removes the previously applied associations. You can prevent visual styles from being applied to a specified window by specifying an empty string, (L" "), which does not match any section entries.

So, having this in your mind you can easily restrict theming for any window those Handle is known by calling SetWindowTheme with both arguments set to "there should be whitespace between braces".

By the way I wouldn't highly recommend to kill themes for entire OS from your application. Personally, I delete any soft that has such a useful feature.

Important addendum!

I've read your question again after some time passed and I can answer to the first part of your question.
You can obtain theme's info via UXTheme unit.

Primarily you must use this two functions:

  1. GetCurrentThemeName
  2. GetThemeDocumentationProperty

Here is some code that shows how to do this.

uses
  ..., UXTheme;

var
  ThemeName: Array[0..512] of Char;
  ThemeColorScheme: Array[0..512] of Char;
  ThemeSizeName: Array[0..512] of Char;
  PropertyName: Array[0..512] of Char;
begin
  UXTheme.GetCurrentThemeName(@ThemeName, SizeOf(ThemeName), @ThemeColorScheme, SizeOf(ThemeColorScheme), @ThemeSizeName, SizeOf(ThemeSizeName));
  UXTheme.GetThemeDocumentationProperty(@ThemeName, SZ_THDOCPROP_CANONICALNAME, @PropertyName, SizeOf(PropertyName));
end;  

Please read about GetThemeDocumentationProperty attentively - this function takes one of arguments that is in a charge of what property of OS theme will be return. According to docs.microsoft, the flag SZ_THDOCPROP_CANONICALNAME in the code above will return string property for

Retrieves the name of the theme.

So you will be able to check what theme is being using at the moment.
But you still can just disable themes for your own application.

Josef Švejk
  • 1,047
  • 2
  • 12
  • 23
  • Thanks Dima, that gives me the information I wanted. SetWindowTheme had no visible effect on the window (I was faintly hoping it might let the color property of groupboxes and panels work again in win10) – Henry Crun Aug 29 '18 at 11:52
  • @HenryCrun, `SetWindowTheme` may not be useful when it is used along with components which aren't wrappers around Window's classes. F.e., Windows has no class that could be wrapped into `TPanel`. Component `TPanel` is a component written "from scratch" by Embarcadero. So only developer of such a component is in a charge of how its component will react to `SetWindowTheme` call. Component TButton is a wrapper for Window's `BUTTON` class, that's why I believe it will have properly reaction to `SetWindowTheme` function, called with correct handle of a button and "empty" arguments. – Josef Švejk Aug 29 '18 at 14:51
  • @HenryCrun I should mention one else thing: **in a case you have a problem with colors of `TGroupBox` and `TPanel` instances under Win10 you always able to ask a new, detailed question**. It would be nice if you can attach some screenshots of your problem (with components) because it will let people there give you really fast help. Perhaps, your problem lies not in Win10's theme. – Josef Švejk Aug 29 '18 at 14:57