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

Dmi*_*try 2 windows delphi delphi-7 aero

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

Dmi*_*try 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;
Run Code Online (Sandbox Code Playgroud)

  • 当`aDllHandle <> 0`时,你需要`FreeLibrary` (2认同)
  • 否则FreeLibrary将失败并且"找不到指定的模块",但没有人检查返回,所以无关紧要. (2认同)