在pre-vista上使用DwmIsCompositionEnabled(JwaDwmApi)会导致错误

时间:2011-09-24 15:04:53

标签: delphi aero dwm jedi-code-library

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

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。我也尝试了this code但它连续产生2个AV。我怎样才能做到这一点 ?我正在使用Delphi 2010. :)

1 个答案:

答案 0 :(得分:4)

你的版本错了。 Vista / 2008服务器版本为6.0。你的测试应该是:

CheckWin32Version(6,0)

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


修改:下面的文字是在编辑问题之前编写的。

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

如果您自己绑定,那么您可以使用LoadLibrary调用DWMApi.dll,如果成功,则会调用GetProcAddress进行绑定。如果成功,你就是好人。但是,正如我所说,由于您没有自己处理绑定,因此版本检查可能是最简单的。

所以函数将是:

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代码一样。