0

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;
  • This question would be more useful if you stated why it matters to you. For example, why your application needs Aero disabled. Is all this to avoid fixing some other glitch? Is your app being DPI-virtualized, or is it DPI-aware. What version of Delphi are you using and do you have a custom manifest? – Warren P Dec 19 '15 at 18:09
  • I work with remote assistence, and while I'm working on pc of my client, I rise a "Form Blocker" (with `AlphaBlend:= True`) with some animation inside (like a "loading image" for example), for prevent any user interation with your computer while I work. And I'm not using any manifest.. – Carlos Alberto Dec 19 '15 at 18:27
  • 1
    Why won't the alpha blending work when aero is on? – Warren P Dec 20 '15 at 02:30

2 Answers2

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

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

  • @KenWhite, [You're wrong about dwm.exe and Windows 8](http://zewaren.net/site/?q=node/115) and also about [dwm.exe and Windows 10.](https://www.reddit.com/r/windows/comments/3bhvi6/what_does_dwmexe_do_in_windows_10/) – Carlos Alberto Dec 19 '15 at 21:55
  • Independent of any opinion here, the important is that my solution above works fine in from of Windows Vista. – Carlos Alberto Dec 19 '15 at 23:00
  • I would frown upon any program that starts/stops windows system services. – whosrdaddy Dec 20 '15 at 09:31
  • Err, my Windows 10 64-bit (upgraded from Win7) system doesn't have a uxsms.* anywhere on its boot drive. And "net start uxsms" gives "The service name is invalid". – MartynA Dec 20 '15 at 10:59
  • @martyn the service name doesn't have to match the executable name. – David Heffernan Dec 20 '15 at 12:24
  • @DavidHeffernan: Sure, I was just meaning that uxsms seems to be a "no show" either way on my system. – MartynA Dec 20 '15 at 12:27
  • This is a pretty bizarre answer to the question that was asked. There's no explanation whatsoever as to what this does. It's a rubbish way to programatically stop and start services. There is an API for that. It requires admin rights, which is not stated. And the question asked to disable composition. Stopping this service disables a lot more than that. – David Heffernan Dec 20 '15 at 12:41
  • And for what it is worth, I cannot find a service of that name on any of my systems. I think you are not engaging with the problem in a meaningful way. – David Heffernan Dec 20 '15 at 13:42