如何在Delphi 7上检测Windows Aero主题?

时间:2013-02-06 15:12:39

标签: windows delphi delphi-7 aero

如何通过Delphi 7上的代码检测用户是否在其操作系统上运行Windows Aero主题?

1 个答案:

答案 0 :(得分:6)

我们需要使用的函数是Dwmapi.DwmIsCompositionEnabled,但是它不包含在随Delphi 7一起提供的Windows头文件中,并且在Vista中添加,在Delphi 7之后发布。此外它还会崩溃Windows XP上的应用程序 - 请在检查后if Win32MajorVersion >= 6调用它。

function IsAeroEnabled: Boolean;
type
  TDwmIsCompositionEnabledFunc = function(out pfEnabled: BOOL): HRESULT; stdcall;
var
  IsEnabled: BOOL;
  ModuleHandle: HMODULE;
  DwmIsCompositionEnabledFunc: TDwmIsCompositionEnabledFunc;
begin
  Result := False;
  if Win32MajorVersion >= 6 then // Vista or Windows 7+
  begin
    ModuleHandle := LoadLibrary('dwmapi.dll');
    if ModuleHandle <> 0 then
    try
      @DwmIsCompositionEnabledFunc := GetProcAddress(ModuleHandle, 'DwmIsCompositionEnabled');
      if Assigned(DwmIsCompositionEnabledFunc) then
        if DwmIsCompositionEnabledFunc(IsEnabled) = S_OK then
          Result := IsEnabled;
    finally
      FreeLibrary(ModuleHandle);
    end;
  end;
end;