在预览前使用DwmIsCompositionEnabled(JwaDwmApi)会导致错误 [英] Using DwmIsCompositionEnabled (JwaDwmApi) on pre-vista causes error

查看:257
本文介绍了在预览前使用DwmIsCompositionEnabled(JwaDwmApi)会导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用以下代码来检查是否启用了Windows Aero:

Been trying to use the following code in order to check if Windows Aero is enabled:

function AeroEnabled: boolean;
var
  enabled: bool;
begin
 // Function from the JwaDwmapi unit (JEDI Windows Api Library)
 DwmIsCompositionEnabled(enabled);
 Result := enabled;

end;

 ...

 if (CheckWin32Version(5,4)) and (AeroEnabled) then
 CampaignTabs.ColorBackground   := clBlack
 else begin
 GlassFrame.Enabled             := False;
 CampaignTabs.ColorBackground   := clWhite;
 end;

但是,在pre-vista机器上这样做会导致应用程序崩溃,因为DWMApi.dll是失踪。我也尝试过此代码但是它连续产生2个AV。我怎样才能做到这一点 ?我正在使用Delphi2010。:)

However, doing so on a pre-vista machine causes the app to crash because the DWMApi.dll is missing. I've also tried this code however it produces 2 AV's in a row. How can I do this ? I am using Delphi 2010. :)

推荐答案

您的版本有误。 Vista / 2008服务器为6.0版。您的测试应该是:

You've got your versions wrong. Vista/2008 server are version 6.0. Your test should be:

CheckWin32Version(6,0)

我相信您使用的是Delphi 2010或更高版本,在这种情况下,您只需从已构建的函数中调用 DwmCompositionEnabled 函数-在 Dwmapi 单元中。这将为您组织版本检查和延迟绑定。不需要JEDI。

I believe that you are using Delphi 2010 or later in which case you should simply call the DwmCompositionEnabled function from the built-in Dwmapi unit. This organises the version check and the delayed binding for you. No need for JEDI.

编辑:以下文字是在编辑问题之前编写的。

Text below was written before the question was edited.

可能最简单的方法是检查Windows版本。您需要 Win32MajorVersion> = 6 (即Vista或2008服务器)才能调用 DwmIsCompositionEnabled

Probably the easiest approach is to check the Windows version. You need Win32MajorVersion>=6 (i.e. Vista or 2008 server) in order to call DwmIsCompositionEnabled.

如果您要绑定自己,则可以使用 DWMApi.dll调用 LoadLibrary ,如果成功,您将调用 GetProcAddress 进行绑定。如果成功的话,你很好。但是,正如我说的那样,由于您不是自己处理绑定的,所以版本检查可能是最简单的。

If you were binding yourself then you would call LoadLibrary with DWMApi.dll and if that succeeded you would then call GetProcAddress to bind. If that succeeded you are good. But, as I said, since you aren't handling the binding yourself then a version check is probably the simplest.

所以函数应该是:

function AeroEnabled: boolean;
var
  enabled: bool;
begin
  if Win32MajorVersion>=6 then begin
    DwmIsCompositionEnabled(enabled);
    Result := enabled;
  end else begin
    Result := False;
  end;
end;

注意,我假设您的库正在进行后期绑定,即显式链接。如果没有,那么您将需要LoadLibrary / GetProcAddress,就像您链接到@RRUZ的代码一样。

Note, I'm assuming that your library is doing late binding, i.e. explicit linking. If not then you'll need LoadLibrary/GetProcAddress, exactly as is done in @RRUZ's code to which you link.

这篇关于在预览前使用DwmIsCompositionEnabled(JwaDwmApi)会导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆