Jump to content

Real Vista Aero Glass - Four functions


James
 Share

Recommended Posts

While you both are correct, it saddens me a little that you are both so unsure. It's not hard to figure these types out. They're documented.

Holy shizzle, I was right! Nah, I did try and work it out. Thinking in binary (don't ask) 0 = off 1 = on, I then worked it out somewhat using ASM muttley

Yeah, I guess I was lazy.

Here's an example on using the function on the msdn page above btw:

$hwnd=GUICreate("Sample",300,200)
 GUISetState()
 GUISetBkColor(0x000000)
 
 Global Const $DWM_BB_ENABLE=0x01
 Global Const $DWM_BB_BLURREGION=0x02
 Global Const $DWM_BB_TRANSITIONONMAXIMIZED=0x04
 $DWM_BLURBEHIND=DllStructCreate("dword dwFlags;int fEnable;int hRgnBlur;int fTransitionOnMaximized;")
 DllStructSetData($DWM_BLURBEHIND,"dwFlags",BitOR($DWM_BB_ENABLE,$DWM_BB_BLURREGION))
 DllStructSetData($DWM_BLURBEHIND,"fEnable",1)
 DllStructSetData($DWM_BLURBEHIND,"hRgnBlur",0)
 DllStructSetData($DWM_BLURBEHIND,"fTransitionOnMaximized",1)
 DllCall("dwmapi.dll","int","DwmEnableBlurBehindWindow","hwnd",$hwnd,"ptr",DllStructGetPtr($DWM_BLURBEHIND))
 
 Do
     $msg=GUIGetMsg()
 Until $msg=-3
No way, I did the same thing just as you posted it! Weird! - Mine didn't work though. The button is still weird.

Grr. Here is what I did for the function:

Global Const $DWM_BB_ENABLE = 0x01
Global Const $DWM_BB_BLURREGION = 0x02
Global Const $DWM_BB_TRANSITIONONMAXIMIZED = 0x04
Global $_DWM_BLURBEHIND = DllStructCreate("dword dwFlags;int fEnable;int hRgnBlur;int fTransitionOnMaximized;")

Func _Vista_ApplyGlassBehind($hWnd)
    If @OSVersion <> "WIN_VISTA" Then
        MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!")
        Exit
    Else
        DllStructSetData($_DWM_BLURBEHIND, "dwFlags", BitOR($DWM_BB_ENABLE, $DWM_BB_BLURREGION))
        DllStructSetData($_DWM_BLURBEHIND, "fEnable", 1)
        DllStructSetData($_DWM_BLURBEHIND, "hRgnBlur", 0)
        DllStructSetData($_DWM_BLURBEHIND, "fTransitionOnMaximized", 1)
        DllCall("dwmapi.dll", "int", "DwmEnableBlurBehindWindow", "hwnd", $hwnd, "ptr", DllStructGetPtr($_DWM_BLURBEHIND))
    EndIf
EndFunc ;==>_Vista_ApplyGlassBehind
Edited by JamesBrooks
Link to comment
Share on other sites

Shouldn't hrgnBlur be a PTR / long ? THen, create the Blur-Rgn with:

http://www.autoitscript.com/forum/index.ph...ost&p=19306

Possibly this works, can't test because -> No Vista muttley

CODE
$hwnd=GUICreate("Sample",300,200)

GUISetState()

$butt = GUICtrlCreateButton("test",10,10,100,30)

GUISetBkColor(0x000000)

Global Const $DWM_BB_ENABLE=0x01

Global Const $DWM_BB_BLURREGION=0x02

Global Const $DWM_BB_TRANSITIONONMAXIMIZED=0x04

Dim $Ctrls[1] = [$butt]

_CreateBlurBehind($hwnd,$ctrls)

Do

$msg=GUIGetMsg()

Until $msg=-3

; Parameters: $hwnd - Handle of GUI-Window

; $NotBlurControls - 1-Dim Array of CtrlIDs which should

; not be included in Blur-Rgn

; Author(s): Prog@ndy, made it from code out of the Thread :)

Func _CreateBlurBehind($hwnd,ByRef $NotBlurControls)

Local $DWM_BLURBEHIND=DllStructCreate("dword dwFlags;int fEnable;ptr hRgnBlur;int fTransitionOnMaximized;")

DllStructSetData($DWM_BLURBEHIND,"dwFlags",BitOR($DWM_BB_ENABLE,$DWM_BB_BLURREGION))

DllStructSetData($DWM_BLURBEHIND,"fEnable",1)

Local $pos = WinGetClientSize($hwnd)

Local $CompleteRgn = CreateRectRegion(0,0,$pos[0],$pos[1])

For $i = 0 To UBound($NotBlurControls)-1

$rgn = _CreateRectRgnFromControl($NotBlurControls[$i]

RemoveFromRgn($CompleteRgn,$rgn)

DeleteRgn($rgn)

Next

DllStructSetData($DWM_BLURBEHIND,"hRgnBlur",$CompleteRgn)

DllStructSetData($DWM_BLURBEHIND,"fTransitionOnMaximized",1)

DllCall("dwmapi.dll","int","DwmEnableBlurBehindWindow","hwnd",$hwnd,"ptr",DllStructGetPtr($DWM_BLURBEHIND))

EndFunc

; Author(s): Prog@ndy

Func RemoveFromRgn(ByRef $rgn1, ByRef $rgn2)

DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 4)

EndFunc

; Author(s): Prog@ndy

Func RemoveMultiFromRgn(ByRef $rgn1, ByRef $rgnarray)

For $i = 0 To UBound($a_rgns)-1

DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgnarray[$i], "int", 4)

Next

EndFunc

; Author(s): Prog@ndy

Func _CreateRectRgnFromControl($CtrlID)

Local $pos = ControlGetPos(GUICtrlGetHandle($CtrlID),"","")

Return CreateRectRgn($pos[0],$pos[1],$pos[2],$pos[3])

EndFunc

Func DeleteRgn(ByRef $rgn)

DllCall("gdi32.dll","int","DeleteObject","ptr",$rgn)

EndFunc

;===============================================================================

;

; Function Name: CreateRectRegion()

; Description:: Creates a Rectangular Region

; Parameter(s): left, top, width, height

; Requirement(s): AutoIt Beta

; Return Value(s): Region Handle

; Author(s): RazerM

;

;===============================================================================

;

Func CreateRectRgn($l, $t, $w, $h)

$ret = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h)

Return $ret[0]

EndFunc

//Edit: @JamesBrooks: You didn't remove the button from the Rgn which should be blurred :(

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

OK, Then i can't help anymore. As i sad, I have no Vista muttley

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

After I have finished all the glass effects, my next job is the Task Dialogs!

I suggest staying away from the Task Dialogs for a while, at least till you know structures, callbacks and more.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 2 weeks later...

I tried this a few months ago, but had the same problem as you with only the left side of the region working.. Thanks for finally figuring this out.

http://www.autoitscript.com/forum/index.php?showtopic=72918

Maybe you could try and create a full dwm library. I'm quite interested in being able to use the thumbnail preview windows that you see when alt-tabbing for example.. see: DwmUpdateThumbnailProperties Function.

Link to comment
Share on other sites

  • 9 months later...

No, no, no, you've got this all mixed up.

Here's how you should do it:

$hwnd=GUICreate("sample",300,300)
GUISetState()

$struct=DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
DllStructSetData($struct,"cxLeftWidth",130)
DllStructSetData($struct,"cxRightWidth",3)
DllStructSetData($struct,"cyTopHeight",0)
DllStructSetData($struct,"cyBottomHeight",25)
GUISetBkColor(0x000000)
DllCall("dwmapi.dll", "int", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($struct))

Do
    $msg=GUIGetMsg()
    
Until $msg=-3

Now play with the values in the struct until you understand what they mean :)

I'm wondering if you have to tell Vista something about the transparent color if it's not black? As you can see from the screen shots, if the background of the form is black, I get the thick glass border. If it's red, the area between the normal size border and the extend region is sort of see though pink.

post-31149-1242323332_thumb.jpg

post-31149-1242323345_thumb.jpg

Link to comment
Share on other sites

I'm wondering if you have to tell Vista something about the transparent color if it's not black? As you can see from the screen shots, if the background of the form is black, I get the thick glass border. If it's red, the area between the normal size border and the extend region is sort of see though pink.

post-31149-1242323332_thumb.jpg

post-31149-1242323345_thumb.jpg

In _Vista_ApplyGlassArea() I think it could be made to work as expected if the extended region was painted black instead of just setting the background color for the window. But I haven't figured out how to do much with Paint in AutoIt3 yet.

Func _Vista_ApplyGlassArea($hWnd, $Area, $bColor = 0x000000)
    If Not _GlassEnabled() Then Return 0

    If IsArray($Area) Then
        DllStructSetData($Struct, "cxLeftWidth", $Area[0])
        DllStructSetData($Struct, "cxRightWidth", $Area[1])
        DllStructSetData($Struct, "cyTopHeight", $Area[2])
        DllStructSetData($Struct, "cyBottomHeight", $Area[3])

;only the region of the Glass extension should be painted black.
;somehow the form should be made to only repaint inside the boundary?

        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
EndFunc  ;==>_Vista_ApplyGlassArea
Link to comment
Share on other sites

It's a hack using black labels to mask the border if background color <> black, but it works.

Edit:

(I fixed the bug in $L1 label creation line. Should work via cut & paste now.)

Func _Vista_ApplyGlassArea($hWnd, $Area, $bColor = 0x000000)
    If Not _GlassEnabled() Then Return 0 

    If IsArray($Area) Then
        If $bColor <> 0x000000 Then
            Local $clientH = _WinAPI_GetClientHeight($hWnd)
            Local $clientW = _WinAPI_GetClientWidth($hWnd)
        EndIf
        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!
        If $bColor <> 0x000000 Then
            Local $L1 = GUICtrlCreateLabel("", 0, 0, $clientW, $Area[2])
            GUICtrlSetBkColor(-1, 0x000000)
            Local $L2 = GUICtrlCreateLabel("", 0, 0, $Area[0], $clientH)
            GUICtrlSetBkColor(-1, 0x000000)
            Local $L3 = GUICtrlCreateLabel("", $clientW - $Area[1], 0, $Area[1], $clientH)
            GUICtrlSetBkColor(-1, 0x000000)
            Local $L4 = GUICtrlCreateLabel("", 0, $clientH - $Area[3], $clientW, $Area[3])
            GUICtrlSetBkColor(-1, 0x000000)
        EndIf
        $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
EndFunc ;==>_Vista_ApplyGlassArea

and the _GlassEnabled() is

Global Enum $WIN_95, $WIN_98, $WIN_ME, $WIN_NT, $WIN_2000, $WIN_XP, $WIN_2003, _
        $WIN_VISTA, $WIN_2008

Func _OsLevel()
    Local $ver = @OSVersion
    Local $winVersions[9] = ["WIN_95", "WIN_98", "WIN_ME", "WIN_NT4", "WIN_2000", _
            "WIN_XP", "WIN_2003", "WIN_VISTA", "WIN_2008"]

    For $i = $WIN_95 To UBound($winVersions) - 1
        If $winVersions[$i] = $ver Then Return $i
    Next
EndFunc ;==>_OsLevel

Func _GlassEnabled()
    If _OsLevel() < $WIN_VISTA Then Return 0
    $retValue = Dllcall("dwmapi.dll","int","DwmIsCompositionEnabled","int*","")
    If @error Then Return 0
    return $retValue[1]
EndFunc

I do OsLevel() returning an enumerated type to make comparison easier. Windows8 may not return "WIN_VISTA" but it should be >= $WIN_VISTA etc..

Edited by MilesAhead
Link to comment
Share on other sites

Cool, I'm gonna try it on one of my new scripts tomorrow.

Thanks man :)

-Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Cool, I'm gonna try it on one of my new scripts tomorrow.

Thanks man :)

-Kenny

Found a bug. When the first Label is created it should use $Area[2] not subscript 0, like this:

Local $L1 = GUICtrlCreateLabel("", 0, 0, $clientW, $Area[2])

Sorry about that. I caught it just now.

I wish when they do these rectangles they would keep the dimensions in the same order. That's why I didn't use _WinAPI_GetClientRect(). Confuses the hell out of me when the order keeps getting shuffled. :party:

Link to comment
Share on other sites

hmm mine doesn't seem to come out quite right. Any ideas?

Posted Image

I'm running W7 so maybe that's throwing it off. I don't have a Vista machine to test it on.

Thanks,

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

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...