#include <GUIConstants.au3>
#include-once

Global Const $sStructMargins = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
Global Const $sStructDWM_BLURBEHIND = DllStructCreate("dword;int;ptr;int")

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ApplyGlass
; Description ...: Applys glass effect to a window
; Syntax.........: _Vista_ApplyGlass($hWnd, [$bColor)
; Parameters ....: $hWnd - Window handle:
;                 $bColor  - Background color
; Return values .: Success - No return
;                 Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to weaponx!
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _Vista_ApplyGlass($hWnd, $bColor = 0x000000)
	GUISetBkColor($bColor); Must be here!
	$Ret = DllCall("dwmapi.dll", "long", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "long*", DllStructGetPtr($sStructMargins))
	If @error Then
		Return 0
		SetError(1)
	Else
		Return $Ret
	EndIf
EndFunc   ;==>_Vista_ApplyGlass

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ApplyGlassArea
; Description ...: Applys glass effect to a window area
; Syntax.........: _Vista_ApplyGlassArea($hWnd, $Area, [$bColor)
; Parameters ....: $hWnd - Window handle:
;                  $Area - Array containing area points
;                 $bColor  - Background color
; Return values .: Success - No return
;                 Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to monoceres!
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _Vista_ApplyGlassArea($hWnd, $Area, $bColor = 0x000000)
	If IsArray($Area) Then
		DllStructSetData($sStructMargins, "cxLeftWidth", $Area[0])
		DllStructSetData($sStructMargins, "cxRightWidth", $Area[1])
		DllStructSetData($sStructMargins, "cyTopHeight", $Area[2])
		DllStructSetData($sStructMargins, "cyBottomHeight", $Area[3])
		GUISetBkColor($bColor); Must be here!
		$Ret = DllCall("dwmapi.dll", "long*", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($sStructMargins))
		If @error Then
			Return 0
		Else
			Return $Ret
		EndIf
	Else
		MsgBox(16, "_Vista_ApplyGlassArea", "Area specified is not an array!")
	EndIf
EndFunc   ;==>_Vista_ApplyGlassArea

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_EnableBlurBehind
; Description ...: Enables the blur effect on the provided window handle.
; Syntax.........: _Vista_EnableBlurBehind($hWnd)
; Parameters ....: $hWnd - Window handle:
; Return values .: Success - No return
;                 Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to komalo
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _Vista_EnableBlurBehind($hWnd, $bColor = 0x000000)
	Const $DWM_BB_ENABLE = 0x00000001

	DllStructSetData($sStructDWM_BLURBEHIND, 1, $DWM_BB_ENABLE)
	DllStructSetData($sStructDWM_BLURBEHIND, 2, "1")
	DllStructSetData($sStructDWM_BLURBEHIND, 4, "1")

	GUISetBkColor($bColor); Must be here!
	$Ret = DllCall("dwmapi.dll", "int", "DwmEnableBlurBehindWindow", "hwnd", $hWnd, "ptr", DllStructGetPtr($sStructDWM_BLURBEHIND))
	If @error Then
		Return 0
	Else
		Return $Ret
	EndIf
EndFunc   ;==>_Vista_EnableBlurBehind

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ICE
; Description ...: Returns 1 if DWM is enabled or 0 if not
; Syntax.........: _Vista_ICE()
; Parameters ....:
; Return values .: Success - Returns 1
;                 Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to BrettF
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _Vista_ICE()
	$ICEStruct = DllStructCreate("int;")
	$Ret = DllCall("dwmapi.dll", "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($ICEStruct))
	If @error Then
		Return 0
	Else
		Return DllStructGetData($ICEStruct, 1)
	EndIf
EndFunc   ;==>_Vista_ICE