简体   繁体   中英

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

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM