How do you detect that the user is running the Windows Aero theme on his operating system by code on Delphi 7?
Asked
Active
Viewed 1,984 times
2
-
1If you want to know if the current application is themed, you can simply check `ThemeServices.ThemesEnabled`. – Andreas Rejbrand Feb 06 '13 at 15:18
-
3There's also `DwmCompositionEnabled` in dwmapi.pas. – Sertac Akyuz Feb 06 '13 at 15:20
-
> If you want to know if the current application is themed, you can simply check ThemeServices.ThemesEnabled - But if it is themed by Windows 7 Simplified Style or by Windows XP? – Dmitry Feb 06 '13 at 15:25
-
2Yeah, your Delphi version was quite relevant. – Sertac Akyuz Feb 06 '13 at 15:49
-
http://stackoverflow.com/questions/7539812/using-dwmiscompositionenabled-jwadwmapi-on-pre-vista-causes-error – Dmitry Feb 06 '13 at 19:27
1 Answers
6
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;

Dmitry
- 14,306
- 23
- 105
- 189
-
@TLama - What I posted is a VCL function: `DwmCompositionEnabled`. It calls DwmIsCompositionEnabled only on Vista+, returns false otherwise. – Sertac Akyuz Feb 06 '13 at 15:51
-
@Sertac, sorry. My mistake. I'll rather stop doing two things at once :-) Taking back my comment (deleting)... And since the question become tagged as Delphi 7, this is the right answer. – TLama Feb 06 '13 at 15:52
-
@TLama - My comment doesn't prove you wrong. I just wanted to be a little specific. – Sertac Akyuz Feb 06 '13 at 15:55
-
2
-
2Otherwise FreeLibrary will fail with 'specified module could not be found', but no one is checking the return so doesn't matter much. – Sertac Akyuz Feb 06 '13 at 16:38