November 15th, 2018

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);
Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.