luksan
luksan

Reputation: 7767

Apply a custom Visual Style (.msstyle) to a single Winforms app

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!

Upvotes: 4

Views: 2698

Answers (2)

Ray
Ray

Reputation: 8872

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.

Upvotes: 0

Jon
Jon

Reputation: 437654

The SetWindowTheme function looks like the solution you 're looking for. You 'll have to do P/Invoke to use it.

Upvotes: 0

Related Questions