I want to allow my users to toggle the current user theme between Aero and Windows Classic(1). Is there a way that I can do this programatically?
I don\'t want to po
There are certainly good reasons for wanting to change the current theme programmatically. E.g. an automated test tool may need to switch between various themes to make sure the application works correctly with all of them.
As a user, you can change the theme by double-clicking a .theme
file in Windwos Explorer and then closing the Control Panel applet that pops up. You can easily do the same from code. The steps below work just fine for me. I've only tested on Windows 7.
SHGetKnownFolderPath()
to get the "Local AppData" folder for the user. Theme files are stored in the Microsoft\Windows\Themes
subfolder. Theme files stored there are applied directly, while theme files stored elsewhere are duplicated when you execute them. So it's best to use files from that folder only.ShellExecute()
to execute the .theme
file you located in step 1.FindWindow('CabinetWClass', 'Personalization')
to get the handle of the Control Panel window that popped up when the theme was applied. The "Personalization" caption will likely be different on non-US-English versions of Windows.PostMessage(HWND, WM_CLOSE, 0, 0)
to close the Control Panel window.This isn't a very elegant solution, but it does the job.