【问题标题】:How enable or disable AERO Composition in Windows 8 or higher?如何在 Windows 8 或更高版本中启用或禁用 AERO 组合?
【发布时间】:2015-12-19 17:47:24
【问题描述】:

我有一个更新的代码,可以很好地在 Windows Vista 和 Windows 7 中启用或禁用 AERO 组合。但是在 Windows 8 系统中使用相同的代码时,它不起作用。我在other website 中看到,从 Windows 8 开始,AERO 组合无法再以编程方式禁用。那么,想知道这里是否有人在 Windows 8 系统或更高版本中使用 Delphi 中的某些功能或程序来实现此目标吗?

欢迎提出任何建议。

这是我在 Windows Vista 和 Windows 7 中启用或禁用 AERO 组合的代码:

    function ISAeroEnabled: boolean;
    type
      _DwmIsCompositionEnabledFunc = function(var IsEnabled: boolean)
        : HRESULT; stdcall;
    var
      Flag: boolean;
      DllHandle: thandle;
      OsVersion: TOSVersionInfo;
      DwmIsCompositionEnabledFunc: _DwmIsCompositionEnabledFunc;
    begin
      Result := false;
      ZeroMemory(@OsVersion, Sizeof(OsVersion));
      OsVersion.dwOSVersionInfoSize := Sizeof(TOSVersionInfo);

      if ((GetVersionEx(OsVersion)) and
        (OsVersion.dwPlatformId = VER_PLATFORM_WIN32_NT) and
        (OsVersion.dwMajorVersion >= 6)) then
      begin
        DllHandle := LoadLibrary('dwmapi.dll');
        try
          if DllHandle <> 0 then
          begin
            @DwmIsCompositionEnabledFunc := GetProcAddress(DllHandle,
              'DwmIsCompositionEnabled');
            if (@DwmIsCompositionEnabledFunc <> nil) then
            begin
              if DwmIsCompositionEnabledFunc(Flag) = S_OK then
                Result := Flag;
            end;
          end;
        finally
          if DllHandle <> 0 then
            FreeLibrary(DllHandle);
        end;
      end;
    end;



  procedure AeroSetEnable(enable: boolean);
    const
      DWM_EC_DISABLECOMPOSITION = 0;
      DWM_EC_ENABLECOMPOSITION = 1;
    var
      DWMlibrary: THandle;
    begin
    DWMlibrary:= LoadLibrary('DWMAPI.dll');
      if DWMlibrary <> 0 then
        begin
         if @DwmEnableComposition <> nil then
         begin
          if enable then begin
           if not ISAeroEnabled then
            begin
             DwmEnableComposition(DWM_EC_ENABLECOMPOSITION)
            end;
            end
            else begin DwmEnableComposition(DWM_EC_DISABLECOMPOSITION); end;
          end;
        end;
    end;

【问题讨论】:

  • 如果您说明了为什么它对您很重要,这个问题会更有用。例如,为什么您的应用程序需要禁用 Aero。这一切都是为了避免修复其他一些故障吗?您的应用程序是 DPI 虚拟化的,还是 DPI 感知的。您使用的是什么版本的 Delphi,是否有自定义清单?
  • 我使用远程协助,当我在我的客户的电脑上工作时,我启动了一个“表单拦截器”(带有AlphaBlend:= True),里面有一些动画(比如“加载图像”例如),以防止在我工作时与您的计算机进行任何用户交互。而且我没有使用任何清单..
  • 为什么在 aero 开启时 alpha 混合不起作用?

标签: delphi aero aero-glass


【解决方案1】:

DwmEnableComposition 的文档说:

此功能自 Windows 8 起已弃用。DWM 不能再以编程方式禁用。

从 Windows 8 开始,使用 DWM_EC_DISABLECOMPOSITION 调用此函数无效。但是,该函数仍会返回成功代码。

本文档明确指出,不能从 Windows 8 禁用该组合。

【讨论】:

    【解决方案2】:

    解决方案:

    1. 启用

      ShellExecute(0, nil, 'cmd.exe', '/C net start uxsms', nil, SW_HIDE);

    2. 禁用

      ShellExecute(0, nil, 'cmd.exe', '/C net stop uxsms', nil, SW_HIDE);

    【讨论】:

    • 独立于这里的任何意见,重要的是我上面的解决方案在 Windows Vista 中运行良好。
    • 我不赞成任何启动/停止 Windows 系统服务的程序。
    • 呃,我的 Windows 10 64 位(从 Win7 升级)系统在其引导驱动器上的任何位置都没有 uxsms.*。并且“net start uxsms”给出“服务名称无效”。
    • @martyn 服务名称不必与可执行文件名称匹配。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    相关资源
    最近更新 更多