以编程方式(第一次!)启用航空主题/桌面合成
我想以编程方式(最好是 C#)在 Windows 7 计算机上启用桌面合成,并且已经尝试使用臭名昭著的 DwmEnableComposition
P/Invoke 来实现这一点。但是,如果从未启用 DWM(并且未运行性能测试),这似乎不起作用。不过,我可以通过“个性化”控制面板启用 DWM,而无需运行性能测试。
因此我的问题是:我怎样才能以编程方式做同样的事情?第二个问题:如何实现设置中的更改是持久的(例如,如果我在启用了 DWM 的计算机上设置 DwmEnableComposition(false)
,则一旦应用程序退出,它就会重新启用)?
I want to enable desktop composition on a Windows 7 machine programmatically (preferrable C#) and already tried to do it with the infamous DwmEnableComposition
P/Invoke. However, this does not seem to work if DWM has never been enabled (and the performance test has not run). I can, however, enable DWM via the "Personalization" control panel w/o running the performance test.
My question therefore is: how can I do the same programmatically? And a second question: how can I achieve that a change in the setting is persistent (e. g. if I set DwmEnableComposition(false)
on a machine that has DWM enabled, it is re-enabled once the application exits)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了一个比第一个解决方案更简单的解决方案:调用
winsat dwm
将在完成后自动打开 Aero,如果硬件支持它 - 并且它不会更改壁纸等。I found a less nasty solution than my first one: Invoking
winsat dwm
will turn on Aero automatically once it finishes and if the hardware supports it - and it does not change the wallpaper etc.答案是:你不能那样做。
Microsoft 没有公开程序以编程方式在用户计算机上启用或禁用桌面组合的方法。
DwmEnableComposition
仅适用于您的应用程序在与组合不兼容时暂时禁用 DWM。当用户已经将其关闭时,它不能用于打开合成。过去 5 年销售的任何计算机都能够以图形方式使用合成,如果支持,Windows 会默认打开它。它被关闭的唯一原因是:
在任何一种情况下:您不应该(因此不能)打开它。
你不能那样做。
The answer is: You cannot do that.
Microsoft does not expose a programmatic way for programs to enable or disable desktop composition on the user's machine.
DwmEnableComposition
is only for your application to temporarily disable DWM if you aren't compatible with composition. It cannot be used to turn on composition, when the user has already turned it off.Any computer sold in the last 5 years is graphically capable of using composition, and Windows turns it on by default if its supported. The only reason it would be turned off is:
In either case: you should not (and therefor cannot) turn it on.
You cannot do that.