Search code examples
windowsdelphidelphi-7aero

How to detect Windows Aero theme on Delphi 7?


How do you detect that the user is running the Windows Aero theme on his operating system by code on Delphi 7?


Solution

  • The function we need to use is Dwmapi.DwmIsCompositionEnabled, but that is not included in the Windows header translations that ship with Delphi 7 and was added in Vista, released after Delphi 7. Also it crashes the application on Windows XP - so call it after check 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;