Is there any way to apply a custom Visual Style (.msstyle) to a Windows Forms application without changing the theme of the entire system? Basically we want our application to maintain the same theme regardless of what has been set in Control Panel. Please don't tell me whether you think this is a good idea. I am wondering if there is any way to do this that doesn't involve a proprietary library, like a series of native API calls. Thanks!
-
1Did you solve your problem? I need that too – Thiago Suchorski Dec 26 '16 at 13:08
-
@ThiagoSuchorski I left an answer about why this is possibly not a good idea to do. I hope it can give you some guidance. – Ray Feb 23 '17 at 19:04
2 Answers
This sadly requires a lot of hooking and not just simple P/Invoke.
You're probably faster and better off overriding / creating new controls with managed code. Otherwise you'll need to hook theming calls, with the help of a native DLL, and be very careful in what you do.
In fact, I don't know how to implement it myself exactly, I'm afraid. I would've given a more helpful answer then. The whole progress seems overly complicated by looking into the code of a now abandoned tool called "VisualStyler" by Style Soft (the company seems dead since 2014) which nicely supported all of this.
Plus if you really decide to use uxtheme, you'll be stuck with what the Windows theming engine provides, limited to its visual style file format and hickups (do you even have a good editor nowadays?).
I wish Microsoft would've done nails with heads when they created the theming engine for XP, allowing application developers to utilize it for their own application identity. But they never seem to do that when it comes to theming / Windows product identity (another example is DWM not exposing any 3D transformational features, but it's probably a good idea to prevent applications doing insane things by abusing such stuff).
Options?
- Create your own controls in managed code, handling drawing by yourself.
- Buy a product offering that for Win32 applications.
- Start to get into WPF which provides modern and sane ways to create application themes.

- 7,940
- 7
- 58
- 90
The SetWindowTheme
function looks like the solution you 're looking for. You 'll have to do P/Invoke to use it.

- 428,835
- 81
- 738
- 806
-
I found SetWindowTheme, but I don't think it does what I want. This function seems to only allow me to change the class of the window for styling purposes. I don't think it actually allows me to specify a path to an entirely different .msstyles file, as far as I can tell. – luksan Mar 31 '11 at 15:32
-
I can force it to not use styles at all (AKA Windows Classic) by passing an empty string into that function for the window class, but this is not what I want either. – luksan Mar 31 '11 at 15:34
-
I'm accepting this answer even though it didn't answer my question because I'm tried of people not accepting answers on here. In truth the requirement was pretty ridiculous; I'm pretty sure it could only be done with a very complex interception of windows API calls, basically reimplementing the style library handling code. – luksan Sep 21 '11 at 17:32
-
1@luksan: Since the question was not really answered I think you have reason not accept it; I 'm sure that any problems here are not due to people rationally deciding whether to accept a solution and which one. In any case, thank you for the thought. – Jon Sep 21 '11 at 18:13