Question

Been trying to use the following code in order to check if Windows Aero is enabled:

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;

However, doing so on a pre-vista machine causes the app to crash because the DWMApi.dll is missing. I've also tried this code however it produces 2 AV's in a row. How can I do this ? I am using Delphi 2010. :)

Was it helpful?

Solution

You've got your versions wrong. Vista/2008 server are version 6.0. Your test should be:

CheckWin32Version(6,0)

I believe that you are using Delphi 2010 or later in which case you should simply call the DwmCompositionEnabled function from the built-in Dwmapi unit. This organises the version check and the delayed binding for you. No need for JEDI.


Edit: Text below was written before the question was edited.

Probably the easiest approach is to check the Windows version. You need Win32MajorVersion>=6 (i.e. Vista or 2008 server) in order to call DwmIsCompositionEnabled.

If you were binding yourself then you would call LoadLibrary with DWMApi.dll and if that succeeded you would then call GetProcAddress to bind. If that succeeded you are good. But, as I said, since you aren't handling the binding yourself then a version check is probably the simplest.

So the function would be:

function AeroEnabled: boolean;
var
  enabled: bool;
begin
  if Win32MajorVersion>=6 then begin
    DwmIsCompositionEnabled(enabled);
    Result := enabled;
  end else begin
    Result := False;
  end;
end;

Note, I'm assuming that your library is doing late binding, i.e. explicit linking. If not then you'll need LoadLibrary/GetProcAddress, exactly as is done in @RRUZ's code to which you link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top