如何通过Delphi 7上的代码检测用户是否在其操作系统上运行Windows Aero主题?
答案 0 :(得分: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;