WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Win7

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Modify Desktop Window Manager Composition

 Keywords: Modify Desktop Window Manager (DWM) Composition Aero Enable Disable DwmIsCompositionEnabled DwmEnableComposition

;***************************************************************************
;**  Modify Desktop Window Manager (DWM) composition.
;**  Enabling and Disabling Aero interface on Windows Vista and 7
;**
;***************************************************************************

; Note  As of Windows 8, calling this function with DWM_EC_DISABLECOMPOSITION has no effect. However, the function will still return a success code.
ver = WinVersion( 5 )
If ver=="2-6-0" || ver=="2-6-1" ;Only works on Windows Vista and 7

   sysdir = DirWindows(1)
   dwmapidll = StrCat(sysdir,"dwmapi.dll")
   dllhandle = DllLoad(dwmapidll)

   ;HRESULT WINAPI DwmIsCompositionEnabled(
   ;  _Out_  BOOL *pfEnabled
   ;)
   bb = BinaryAlloc(4)
   retvalue = DllCall(dllhandle,LONG:"DwmIsCompositionEnabled",lpbinary:bb)
   If retvalue != 0
      Pause("Error",DllLastError())
      Exit
   EndIf
   setting = BinaryPeek4(bb, 0 )
   BinaryFree(bb)

   ;HRESULT WINAPI DwmEnableComposition(
   ;  UINT uCompositionAction
   ;);
   ;If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
   If setting
      ret = AskYesNo( 'DWM composition is enabled', 'Would you like to disable?' )
      If ret
         ;Disable
         retvalue = DllCall(dllhandle,LONG:"DwmEnableComposition",long:0)
         If retvalue != 0
            Pause("Error",DllLastError())
            Exit
         EndIf
         Pause('DwmEnableComposition','Disabled')
      EndIf
   Else
      ret = AskYesNo( 'DWM composition is disabled', 'Would you like to enable?' )
      If ret
         ;Disable
         retvalue = DllCall(dllhandle,LONG:"DwmEnableComposition",long:1)
         If retvalue != 0
            Pause("Error",DllLastError())
            Exit
         EndIf
         Pause('DwmEnableComposition','Enabled')
      EndIf
   EndIf

Else
   Pause('Notice','Unsupported Platform')
EndIf

Article ID:   W18436
Filename:   Modify Desktop Window Manager Composition.txt
File Created: 2013:01:22:12:16:48
Last Updated: 2013:01:22:12:16:48