2013-02-06 103 views
2

如何通過Delphi 7上的代碼檢測到用戶正在他的操作系統上運行Windows Aero主題?如何檢測Delphi 7上的Windows Aero主題?

+1

如果你想知道當前的應用程序是否爲主題,你可以簡單地檢查'ThemeServices.ThemesEnabled'。 –

+3

dwmapi.pas中還有'DwmCompositionEnabled'。 –

+0

>如果你想知道當前的應用程序是否爲主題,你可以簡單地檢查ThemeServices.ThemesEnabled - 但如果它的主題是Windows 7簡體樣式或Windows XP? – Dmitry

回答

6

我們需要使用的功能是Dwmapi.DwmIsCompositionEnabled,但不包括在Windows頭文件翻譯的是用Delphi 7船在Vista中加入,釋放後德爾福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; 
+0

@TLama - 我發佈的是一個VCL函數:'DwmCompositionEnabled'。它僅在Vista +上調用DwmIsCompositionEnabled,否則返回false。 –

+0

@Sertac,對不起。我的錯。我寧願停止同時做兩件事:-)收回我的評論(刪除)...並且由於問題被標記爲Delphi 7,這是正確的答案。 – TLama

+0

@TLama - 我的評論並不能證明你是錯的。我只是想有點特別。 –