How do I revert a control back to its default theme?

A customer disabled visual styles for their control so that they could do custom rendering, but when the system switches to high contrast mode, they want to abandon their customizations and revert to the system styles.

// Disable visual styles for this control so we can
// draw it our own way.
SetWindowTheme(hwndControl, L"", L"");

But how do they undo the effect of that call and tell the system, "Um, hey, I know I told you that I didn't want the system to draw any visual styles, but I changed my mind. Can you draw visual styles for me after all?"

You can return to the default behavior by passing NULL for the last two parameters.

When pszSubAppName and pszSubIdList are NULL, the theme manager removes the previously applied associations.

// Return to default visual styles for this control.
SetWindowTheme(hwndControl, NULL, NULL);
Comments (3)
  1. kantos says:

    I have to give props to the customer for considering accessibility that said I’m surprised they didn’t ask for some way to read the theme and then do it themselves.

  2. Thumbs up to them for thinking about this case at all.

  3. RKPatrick says:

    I’m actually a bit surprised here. My normal expectation has been to pass null to unset things, but a decent number of APIs (not just MS’) like to throw up exceptions when you pass a null, even here….they insist on some special enumeration or even an entirely separate API just for unsets. Something about reusing null and/or treating it like magic. But I just like the intuitiveness of doing it, since it’s a pretty universal pattern until you start dealing with value types

Comments are closed.

Skip to main content