winapi

How to restore windows theme for one control


I use the following code to disable themes on a single control:

SetWindowTheme(yourControl.Handle, "", "");

or just

SetWindowTheme(yourControl.Handle, "explorer", "");

but after a while, I need to restore the original Windows Vista/Seven theme on that control. How can do it? I looked for a "default" name without finding it, all examples cite "" or "explorer", which disable the theme.


Solution

  • From the SetWindowTheme documentation

    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.

    Note that NULL and "" are not the same thing.

    You can restore the old theme for the application by just calling SetWindowTheme again with NULL values for the last two parameters:

    SetWindowTheme(yourControl.Handle, NULL, NULL);