开发者

How to change windows color scheme using c#?

开发者 https://www.devze.com 2023-02-04 17:17 出处:网络
How to programatically change the color scheme using c开发者_如何学JAVA#? I want to change the color scheme to windows vista basic or windows 7 basic. How can I do that?

How to programatically change the color scheme using c开发者_如何学JAVA#? I want to change the color scheme to windows vista basic or windows 7 basic. How can I do that? Thanks, Nikil.


You can change the theme of the system using SetSystemVisualStyle method.

Link to pInvoke SetSystemVisualStyle.

C# Sample usage:

// This will set your Visual Style to Luna
SetSystemVisualStyle(@"C:\WINDOWS\resources\Themes\Luna\Luna.msstyles", "Metallic", "NormalSize", 0);


This is what worked best for me. With my very graphics-intensive program, Windows Vista and 7 eventually forced the system back into Windows Basic Colors. But if I minimized or maximized an MDI window before that happened, everything locked up totally. I had to hold the power button for 5 seconds to shut it down and then reboot. Here is what I found to go to Windows Basic Colors near the start of program execution:

using System.Runtime.InteropServices; 

    //1-9-2013: so we can DISABLE COMPOSITING -- forcing Windows "Aero Glass" to revert to "Aero Basic"
    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern void DwmEnableComposition(bool bEnable);

            DwmEnableComposition(false);    //DISABLE COMPOSITING -- forces Windows "Aero Glass" to revert to "Aero Basic"

The change to Aero Basic is for Windows itself, affecting all running programs. System reverts to "Aero Glass" upon exit of this app. There might be other side effects, but so far, it's running well for me.

P.S. Looks like this is deprecated in Windows 8 and does nothing except return a True. My app is a real-time monitoring program with nothing else on the machine, so I'm comfortable forcing Windows Basic Colors. So this is a work-around, until I can locate what in my app is chewing up so many machine cycles with Aero Glass.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号