且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Windows 8或更高版本中启用或禁用AERO Composition?

更新时间:2022-12-25 11:35:47

DwmEnableComposition 说:


从Windows 8起不推荐使用此功能。无法通过编程方式禁用DWM。


$ b从Windows 8开始,
$ b


用DWM_EC_DISABLECOMPOSITION调用此函数无效。但是,该函数仍将返回成功代码。


该文档明确指出,不能在Windows 8中禁用该组合。 / p>

I have a updated code that works fine for enable or disable AERO Composition in Windows Vista and Windows 7. But this same code don't works when is used in Windows 8 systems. I saw in other website that from of Windows 8, AERO Composition can no longer be programmatically disabled. So, want know if by chance, someone here have some function or procedure in Delphi that works for this goal in Windows 8 systems or higher?

Any suggestion are welcome.

Here is my code for enable or disable AERO Composition in Windows Vista and Windows 7:

    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;

The documentation for DwmEnableComposition says:

This function is deprecated as of Windows 8. DWM can no longer be programmatically disabled.

and

As of Windows 8, calling this function with DWM_EC_DISABLECOMPOSITION has no effect. However, the function will still return a success code.

This documentation states, unequivocally, that composition cannot be disabled from Windows 8.