1

我想以编程方式在 Windows 7 机器上启用桌面组合(首选 C#),并且已经尝试使用臭名昭著的DwmEnableCompositionP/Invoke 来实现。但是,如果 DWM 从未启用(并且性能测试尚未运行),这似乎不起作用。但是,我可以通过“个性化”控制面板启用 DWM,而无需运行性能测试。

因此,我的问题是:我怎样才能以编程方式做同样的事情?第二个问题:如何实现设置的更改是持久的(例如,如果我DwmEnableComposition(false)在启用了 DWM 的机器上设置,一旦应用程序退出它就会重新启用)?

4

2 回答 2

1

我找到了一个比我的第一个解决方案更糟糕的解决方案:winsat dwm一旦完成并且硬件支持它,调用将自动打开 Aero - 而且它不会改变壁纸等。

于 2011-03-29T15:04:25.907 回答
0

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.

于 2011-03-29T14:22:36.553 回答