以编程方式(第一次!)启用航空主题/桌面合成

发布于 2024-10-28 09:50:22 字数 315 浏览 7 评论 0原文

我想以编程方式(最好是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只是一片海 2024-11-04 09:50:22

我发现了一个比第一个解决方案更简单的解决方案:调用 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.

听不够的曲调 2024-11-04 09:50:22

答案是:你不能那样做。


Microsoft 没有公开程序以编程方式在用户计算机上启用或禁用桌面组合的方法。

他们不提供 API 的原因是程序可能会使用它。
过去,微软相信开发人员不会做错事。这已经改变了

因为程序员被信任会做正确的事情< /a>


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.

The reason they don't provide an API is that programs might use it.
In the past Microsoft trusted developers not to do the wrong thing. That has changed

Because programmers were trusted to do the right thing

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:

  • the user turned it off
  • another application is running that doesn't support composition

In either case: you should not (and therefor cannot) turn it on.

You cannot do that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文