2

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

4

1 回答 1

6

我们需要使用的函数是Dwmapi.DwmIsCompositionEnabled,但它不包含在 Delphi 7 附带的 Windows 标头翻译中,并在 Delphi 7 之后发布的 Vista 中添加。它还在 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;
于 2013-02-06T15:28:35.030 回答