【问题标题】:How to detect Windows Aero theme on Delphi 7?如何在 Delphi 7 上检测 Windows Aero 主题?
【发布时间】:2013-02-06 15:12:38
【问题描述】:

如何通过 Delphi 7 上的代码检测到用户在其操作系统上运行 Windows Aero 主题?

【问题讨论】:

  • 如果想知道当前应用是否为主题,可以直接查看ThemeServices.ThemesEnabled
  • dwmapi.pas 中还有DwmCompositionEnabled
  • > 如果你想知道当前应用程序是否是主题,你可以简单地检查 ThemeServices.ThemesEnabled - 但是如果它是 Windows 7 Simplified Style 或 Windows XP 的主题?
  • 是的,你的 Delphi 版本非常相关。

标签: windows delphi delphi-7 aero


【解决方案1】:

我们需要使用的函数是Dwmapi.DwmIsCompositionEnabled,但它不包含在Delphi 7 附带的Windows 标头翻译中,它是在Delphi 7 之后发布的Vista 中添加的。它还在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;

【讨论】:

  • @TLama - 我发布的是一个 VCL 函数:DwmCompositionEnabled。它只在 Vista+ 上调用 DwmIsCompositionEnabled,否则返回 false。
  • @Sertac,对不起。我的错。我宁愿停止同时做两件事 :-) 收回我的评论(删除)......由于问题被标记为 Delphi 7,这是正确的答案。
  • @TLama - 我的评论并不能证明你错了。我只是想具体一点。
  • aDllHandle &lt;&gt; 0时需要FreeLibrary
  • 否则 FreeLibrary 将因“找不到指定的模块”而失败,但没有人检查返回,所以没关系。
猜你喜欢
  • 2012-08-23
  • 2023-03-23
  • 2011-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-30
  • 2010-11-13
  • 1970-01-01
  • 2020-01-11
相关资源
最近更新 更多