Jump to content

Real Vista Aero Glass - Four functions


James
 Share

Recommended Posts

Hi all,

With lots of thanks to weaponx who showed me, StructureConstants.au3 and realised that I had my DllCall mixed up and monoceres for showing me how to create a structure, I present to you AutoIt3 and Aero Glass! Komalo for the original DWMEnableBlurBehind and BrettF for another structure issue.

Posted ImagePosted Image

Four functions:

  • _Vista_ApplyGlass($hWnd) - Applies the glass effect to the whole GUI
  • _Vista_ApplyGlassArea($hWnd, $Area) - Applies glass to an area (array) on the GUI
  • _Vista_EnableBlurBehind - Blurs the background of a GUI (still effects controls, need to fix)
  • _Vista_ICE - Returns 1 if DWM is enabled, otherwise 0
#include <GUIConstants.au3>
 
 $Struct = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
 $sStruct = DllStructCreate("dword;int;ptr;int")
 
 Global $MyArea[4] = [50, 50, 50, 50]
 
 $GUI = GUICreate("Windows Vista DWM", 243, 243)
 $Apply = GUICtrlCreateButton("Apply", 80, 104, 83, 25, 0)
 $ICE = GUICtrlCreateButton("DWM Check", 80, 134, 83, 25, 0)
 GUISetState()
 
 While 1
     $iMsg = GUIGetMsg()
     Switch $iMsg
         Case $GUI_EVENT_CLOSE
             Exit
         Case $Apply
        ;_Vista_ApplyGlass($GUI)
        ;_Vista_EnableBlurBehind($GUI)
             _Vista_EnableBlurBehind($GUI)
         Case $ICE
             If _Vista_ICE() Then
                 MsgBox(0, "_Vista_ICE", "DWM is enabled!")
             Else
                 MsgBox(0, "_Vista_ICE", "DWM is NOT enabled!")
             EndIf
     EndSwitch
 WEnd
 
; #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)
     If @OSVersion <> "WIN_VISTA" Then
         MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!")
         Exit
     Else
         GUISetBkColor($bColor); Must be here!
         $Ret = DllCall("dwmapi.dll", "long", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "long*", DllStructGetPtr($Struct))
         If @error Then
             Return 0
             SetError(1)
         Else
             Return $Ret
         EndIf
     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 @OSVersion <> "WIN_VISTA" Then
         MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!")
         Exit
     Else
         If IsArray($Area) Then
             DllStructSetData($Struct, "cxLeftWidth", $Area[0])
             DllStructSetData($Struct, "cxRightWidth", $Area[1])
             DllStructSetData($Struct, "cyTopHeight", $Area[2])
             DllStructSetData($Struct, "cyBottomHeight", $Area[3])
             GUISetBkColor($bColor); Must be here!
             $Ret = DllCall("dwmapi.dll", "long*", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($Struct))
             If @error Then
                 Return 0
             Else
                 Return $Ret
             EndIf
         Else
             MsgBox(16, "_Vista_ApplyGlassArea", "Area specified is not an array!")
         EndIf
     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)
     If @OSVersion <> "WIN_VISTA" Then
         MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!")
         Exit
     Else
         Const $DWM_BB_ENABLE = 0x00000001
 
         DllStructSetData($sStruct, 1, $DWM_BB_ENABLE)
         DllStructSetData($sStruct, 2, "1")
         DllStructSetData($sStruct, 4, "1")
 
         GUISetBkColor($bColor); Must be here!
         $Ret = DllCall("dwmapi.dll", "int", "DwmEnableBlurBehindWindow", "hwnd", $hWnd, "ptr", DllStructGetPtr($sStruct))
         If @error Then
             Return 0
         Else
             Return $Ret
         EndIf
     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

James

Edited by JamesBrooks
Link to comment
Share on other sites

this line

If @OSTYPE < "WIN_VISTA" Then

should be

If @OSTYPE <> "WIN_VISTA" Then

not a big deal but i figured i would let you know muttley

Edited by MerkurAlex

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

I am on XP so this will not work..can we get a higher quality image preview, please?

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

this line

If @OSTYPE < "WIN_VISTA" Then

should be

If @OSTYPE <> "WIN_VISTA" Then

not a big deal but i figured i would let you know :P

When I originally had that it wouldn't work full stop.

Very nice muttley

I had no idea that this was possible :)

Heh, I have had the idea for a while, I just found how to do it :(

I am on XP so this will not work..can we get a higher quality image preview, please?

I only have Paint at the moment, the button comes out like that either way.
Link to comment
Share on other sites

I have never used Vista, but how is this different from the default look of your gui? Is it just plain by default?

If you look at his DllCall it should be obvious

Return DllCall($dll, "long", "DwmExtendFrameIntoClientArea", "hwnd",$hWnd , "long*", DllStructGetPtr($tMargins))

Link to comment
Share on other sites

do you guys know this doesnt work on vista home basic?

i think it needs premium or ultimate for that guys, but on my pc it looks cool muttley

Damian666

Ofcourse it DOESN'T work, whoever told you otherwise is either ignorant or stupid. (or both)

Edit: And it's Home Premium that is the minimum requirement. Link1, Link2

Edited by AdmiralAlkex
Link to comment
Share on other sites

Did you bother to think about this line of code?

If Not @OSTYPE = "WIN_VISTA" Then

@OSTYPE returns a string which you force to bool with the Not keyword. Since it was a non-empty string it's converted to boolean True which is then inverted producing boolean False. You then compare boolean False to the string "WIN_VISTA".

As was mentioned, the correct operator is <>. Or if you're going to use Not then you need to use parenthesis to group it, although using Not is just extra code that doesn't need to exist.

Link to comment
Share on other sites

Did you bother to think about this line of code?

If Not @OSTYPE = "WIN_VISTA" Then

@OSTYPE returns a string which you force to bool with the Not keyword. Since it was a non-empty string it's converted to boolean True which is then inverted producing boolean False. You then compare boolean False to the string "WIN_VISTA".

As was mentioned, the correct operator is <>. Or if you're going to use Not then you need to use parenthesis to group it, although using Not is just extra code that doesn't need to exist.

OK, well I can change the way it checks in a snap, I just didn't think about doing it before.
Link to comment
Share on other sites

I just found that for me @OS_TYPE returns WIN32_NT, I am running Vista Home Premium.

That is because @OS_TYPE returns the windows family the user is running, not the current version of windows.

Try @OS_Version instead muttley

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...