How enable or disable AERO Composition in Windows 8 or higher?

风流意气都作罢 提交于 2019-12-12 02:23:02

问题


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;

回答1:


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.




回答2:


SOLUTION:

  1. Enable

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

  2. Disable

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



来源:https://stackoverflow.com/questions/34373638/how-enable-or-disable-aero-composition-in-windows-8-or-higher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!