Sign in to follow this  
Followers 0
Alek

Gui Close effect

15 posts in this topic

a nice close effect for your GUIs :)

in the example it shows all the effect with different 'suction' points

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 400, 400)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            $Pos = WinGetPos($Form1)
            For $x = 0 to 14
                _GUIClose($Form1,  50,$x)
                Sleep(100)
                WinMove($Form1,"",$Pos[0],$Pos[1],$Pos[2],$Pos[3])
                WinSetTrans($Form1,"",255)
                Sleep(100)
            Next
            Exit
    EndSwitch
WEnd

;#############################################################
;Parameters:
;   $Hwnd:      the window handel
;   $fSpeed:    the speed of the fading and shrinking
;   $sCase:     Where the 'suction' point is
;       0  = Center
;       1  = Center-Left
;       2  = Center-right
;       3  = Center-Top
;       4  = Center-Bottom
;       5  = Bottom-Left
;       6  = Bottom-Right
;       7  = Top-Left
;       8  = Top- Right
;       9  = Center-Middle-Vertical 
;       10 = Center-Middle-Horizontal
;       11 = Roll-up
;       12 = Roll-down
;       13 = Roll-left
;       14 = Roll-right
;Author: Alek
;#############################################################
Func _GUIClose($HWnd, $fSpeed=30, $scase=0)
    ;Create some needed local $vars
    ;$s_PosnSize is needed to check what the transparency should be
    ;$s_PosnSize2 is needed to move and resize the gui.
    Local $s_PosnSize, $s_PosnSize2
    
    ;$s_Step is needed to store how much the size should shrink according to the speed
    Local $s_Step[2]
    
    ;We need $s_Trans to reduce the transparency of the GUI according to its size
    Local $s_Trans = 254
    
    ;Check and reset the case
    ;if the case isent a number then set it to 0
    ;if will also set it to 0 the you write "3"
    If Not IsInt($scase) Or $scase= -1 Or $scase = Default Then $scase = 0
    
    ;if case is less then 0 then set it to 0
    If $scase < 0 Then $scase = 0
    
    ;if case is more then 8 then set it to 8
    If $scase > 14 Then $scase = 14
    
    ;Now check the speed
    ;if its not a integer or speed = -1 or speed is default then set the speed to default (30)
    If Not IsInt($fSpeed) or $fSpeed = -1 Or $fSpeed = Default Then $fSpeed = 30
    
    ;if speed is less then 1 then set it to 1
    If $fSpeed < 1 Then $fSpeed = 1
    
    ;create a top limit, 500 should be high enough
    If $fSpeed > 500 Then $fSpeed = 500
    
    ;Now get the orginal pos and size of the GUI
    $s_PosnSize = WinGetPos($HWnd)
    
    ;Set the reduction size according to the speed
    $s_Step[0] = $s_PosnSize[2]/$fSpeed
    $s_Step[1] = $s_PosnSize[3]/$fSpeed
    
    ;enter a loop
    While 1
        ;Get the current pos of the GUI
        $s_PosnSize2 = WinGetPos($HWnd)
        
        ;check if the size is less then the reduction size or that the tranparency is less then 1
        If $s_PosnSize2[2] < $s_Step[0] Or $s_PosnSize2[3] < $s_Step[1]Or $s_Trans < 1 Then ExitLoop
        
        ;move and reduce the size of the GUI according to the case
        Switch $scase
            Case 0 ;Center
                WinMove( $HWnd, "", $s_PosnSize2[0]+($s_Step[0]/2), $s_PosnSize2[1]+($s_Step[1]/2), $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3]-$s_Step[1])
            Case 1 ;Center-Left
                WinMove( $HWnd, "", $s_PosnSize2[0], $s_PosnSize2[1]+($s_Step[1]/2), $s_PosnSize2[2]-$s_Step[0],$s_PosnSize2[3]-$s_Step[1])
            Case 2 ;Center-Right
                WinMove( $HWnd, "", $s_PosnSize2[0]+$s_Step[0], $s_PosnSize2[1]+($s_Step[1]/2), $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3]-$s_Step[1])
            Case 3 ;Center-Bottom
                WinMove( $HWnd, "", $s_PosnSize2[0]+($s_Step[0]/2), $s_PosnSize2[1], $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3]-$s_Step[1])
            Case 4 ;Center-Top
                WinMove( $HWnd, "", $s_PosnSize2[0]+($s_Step[0]/2), $s_PosnSize2[1]+$s_Step[1], $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3]-$s_Step[1])
            Case 5 ;Bottom-Left
                WinMove( $HWnd, "", $s_PosnSize2[0], $s_PosnSize2[1]+$s_Step[1], $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3]-$s_Step[1])
            Case 6 ;Bottom-Right
                WinMove( $HWnd, "", $s_PosnSize2[0]+$s_Step[0], $s_PosnSize2[1]+$s_Step[1], $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3]-$s_Step[1])
            Case 7 ;Top-Left
                WinMove( $HWnd, "", $s_PosnSize2[0] , $s_PosnSize2[1], $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3]-$s_Step[1])
            Case 8 ;Top-Right
                WinMove( $HWnd, "", $s_PosnSize2[0]+$s_Step[0], $s_PosnSize2[1], $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3]-$s_Step[1])
            Case 9 ;Center-Middle-Vertical  
                WinMove( $HWnd, "", $s_PosnSize2[0]+($s_Step[0]/2), $s_PosnSize2[1], $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3])
            Case 10 ;Center-Middle-Horizontal
                WinMove( $HWnd, "", $s_PosnSize2[0], $s_PosnSize2[1]+($s_Step[1]/2), $s_PosnSize2[2], $s_PosnSize2[3]-$s_Step[1])
            Case 11 ;Roll-up
                WinMove( $HWnd, "", $s_PosnSize2[0], $s_PosnSize2[1], $s_PosnSize2[2], $s_PosnSize2[3]-$s_Step[1])
            Case 12 ;Roll-down
                WinMove( $HWnd, "", $s_PosnSize2[0], $s_PosnSize2[1]+$s_Step[1], $s_PosnSize2[2], $s_PosnSize2[3]-$s_Step[1])
            Case 13 ;Roll-left
                WinMove( $HWnd, "", $s_PosnSize2[0], $s_PosnSize2[1], $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3])
            Case 14 ;Roll-right
                WinMove( $HWnd, "", $s_PosnSize2[0]+$s_Step[0], $s_PosnSize2[1], $s_PosnSize2[2]-$s_Step[0], $s_PosnSize2[3])
        EndSwitch
        
        ;check what size to use to calculate the transparency
        If $s_PosnSize2[2]<> $s_PosnSize[2] Then
            
            ;Calculate what the transparency should be.
            $s_Trans = 254/100*(($s_PosnSize2[2]/$s_PosnSize[2])*100)
        ElseIf $s_PosnSize2[3]<> $s_PosnSize[3] Then
            
            
            ;Calculate what the transparency should be.
            $s_Trans = 254/100*(($s_PosnSize2[3]/$s_PosnSize[3])*100)
        EndIf
        
        ;Set the transparency of the window
        WinSetTrans($HWnd,"",$s_Trans)
        
        ;Sleep to slow down the process so you can see the window shrinking and fadeing
        Sleep(1)
    WEnd
    
    Return 1
EndFunc

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites



Oh, I'm going to use this. Very cool. :)

Share this post


Link to post
Share on other sites

Yeah...Choppy...But Cool Actually...Thanks For This!

Share this post


Link to post
Share on other sites

looks nice, and it is very quick and not at all choppy on my computer... Ive got the weakest NVIDIA 8-series there is... but that's probably all it takes. (It's actually such a weak GPU that I can't find it on there website, its the 8300 GS)

anyway, this effect doesn't look good unless the GUI is blank, since things aren't scaled with the window. Now find a way to add that, and it would be useful.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

smooth as silk on my home PC. I tried it at work on some slower machines and it went a bit slower and I guess slightly choppy.

Edited by simusphere

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

smooth as silk on my home PC. I tried it at work on some slower machines and it went a bit slower and I guess slightly choppy.

And I thought my computer was descent... Maybe some components of it are old... Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Kinda Cool :)

A new idea..Make A _GUIOpen() effect. make them create the gui...the function sets the gui to 0 trans..and go up to 255! that would be sweet!

Edited by Swift

Share this post


Link to post
Share on other sites

Good Effect for close windows, but ....

There is a little bug. Some windows don't close. muttley

It seem to the calculate some result because the exit infinite loop does not work always.

A window with 1002x529 size never close with a speed of 30,40 or 50, but with 10 ms delai it works !!!!

Can you fix it ?

Share this post


Link to post
Share on other sites

That`s very nice. I like transparent effect. muttley


When the words fail... music speaks

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Hi.

I fixed:

bug of infinity loop

I updated:

Hide the window at the end of loop

I rewrited code of _GuiClose with less comparaison test:

;#############################################################
;Parameters:
;   $Hwnd:       the window handel
;   $fSpeed:   the speed of the fading and shrinking
;   $sCase:     Where the 'suction' point is
;     0  = Center
;     1  = Center-Left
;     2  = Center-right
;     3  = Center-Top
;     4  = Center-Bottom
;     5  = Bottom-Left
;     6  = Bottom-Right
;     7  = Top-Left
;     8  = Top- Right
;     9  = Center-Middle-Vertical   
;     10 = Center-Middle-Horizontal
;     11 = Roll-up
;     12 = Roll-down
;     13 = Roll-left
;     14 = Roll-right
;Original Author: Alek (http://www.autoitscript.com/forum/index.php?showtopic=63989)
;updated by: Dmoniac
;#############################################################
Func _GUIClose(byref $HWnd, $fSpeed=30, $scase=0)
   ;Create some needed local $vars
    
   ;$s_Step is needed to store how much the size should shrink according to the speed
    Local $step_x, $step_y
    
;Size of the window
    Local $size
    
;Number of iteration for completly hide the window
    Local $nb_iter
   
   ;We need $s_Trans to reduce the transparency of the GUI according to its size
    Local $s_Trans = 254
    
;Step to decrease transparency 
    Local $step_trans
    
    Local $ret
    Local $size_x,$size_y,$size_width,$size_height
   
   ;Check and reset the case
   ;if the case isent a number then set it to 0
   ;if will also set it to 0 the you write "3"
    If Not IsInt($scase) Or $scase= -1 Or $scase = Default Then $scase = 0
   
   ;if case is less then 0 then set it to 0
    If $scase < 0 Then $scase = 0
   
   ;if case is more then 8 then set it to 8
    If $scase > 14 Then $scase = 14
   
   ;Now check the speed
   ;if its not a integer or speed = -1 or speed is default then set the speed to default (30)
    If Not IsInt($fSpeed) or $fSpeed = -1 Or $fSpeed = Default Then $fSpeed = 30
   
   ;if speed is less then 1 then set it to 1
    If $fSpeed < 1 Then $fSpeed = 1
   
   ;create a top limit, 500 should be high enough
    If $fSpeed > 500 Then $fSpeed = 500
   
   ;Now get the orginal pos and size of the GUI
    $size=WinGetPos($HWnd)
    $size_x=$size[0]
    $size_y=$size[1]
    $size_width=$size[2]
    $size_height=$size[3]
   
   ;Set the reduction size according to the speed
    $step_x = int($size_width/$fSpeed)
    $step_y = int($size_height/$fSpeed)
    
;Number of iteration for resizing
    $nb_iter=int($size_width/$step_x)
    
;Number of step for decrease the transparency 
    $step_trans=int(254/$nb_iter)
    
;enter a loop
    For $i = 0 to $nb_iter - 1
    ;move and reduce the size of the GUI according to the case
        Switch $scase
            Case 0;Center
                $size_x=int($size_x+($step_x/2))
                $size_y=int($size_y+($step_y/2))
                $size_width=$size_width-$step_x
                $size_height=$size_height-$step_y
            Case 1;Center-Left
                $size_y=int($size_y+($step_x/2))
                $size_width=$size_width-$step_y
                $size_height=$size_height-$step_x
            Case 2;Center-Right
                $size_x=$size_x+$step_x
                $size_y=int($size_y+($step_y/2))
                $size_width=$size_width-$step_x
                $size_height=$size_height-$step_y
            Case 3;Center-Bottom
                $size_x=int($size_x+($step_x/2))
                $size_width=$size_width-$step_x
                $size_height=$size_height-$step_y
            Case 4;Center-Top
                $size_x=int($size_x+($step_x/2))
                $size_y=$size_y+$step_y
                $size_width=$size_width-$step_x
                $size_height=$size_height-$step_y
            Case 5;Bottom-Left
                $size_y=$size_y+$step_y
                $size_width=$size_width-$step_x
                $size_height=$size_height-$step_y
            Case 6;Bottom-Right
                $size_x=$size_x+$step_x
                $size_y=$size_y+$step_y
                $size_width=$size_width-$step_x
                $size_height=$size_height-$step_y
            Case 7;Top-Left
                $size_width=$size_width-$step_x
                $size_height=$size_height-$step_y
            Case 8;Top-Right
                $size_x=$size_x+$step_x
                $size_width=$size_width-$step_x
                $size_height=$size_height-$step_y
            Case 9;Center-Middle-Vertical 
                $size_x=int($size_x+($step_x/2))
                $size_width=$size_width-($step_x)
            Case 10;Center-Middle-Horizontal
                $size_y=int($size_y+($step_y/2))
                $size_height=$size_height-($step_y)
            Case 11;Roll-up
                $size_height=$size_height-$step_y
            Case 12;Roll-down
                $size_y=$size_y+$step_y
                $size_height=$size_height-$step_y
            Case 13;Roll-left
                $size_width=$size_width-$step_x
            Case 14;Roll-right
                $size_x = $size_x + $step_x
                $size_width=$size_width-$step_x
        EndSwitch
            
    ;Resize the Window
        $ret=WinMove( $HWnd, "", $size_x, $size_y, $size_width, $size_height)
        
    ;Decrease the value of transparency 
        $s_Trans = $s_Trans - $step_trans
        
    ;FileWriteLine(@ScriptDir & "\_GUIClose.log", "$ret=WinMove( $HWnd, '', "&$size_x&", "&$size_y&", "&$size_height&", "&$size_width&"):"&$s_Trans)
        
    ;Set the transparency of the window
        WinSetTrans($HWnd,"",$s_Trans)
       
       ;Sleep to slow down the process so you can see the window shrinking and fadeing
        Sleep(1)
    Next
    
;Finaly, hide the window
    GUISetState(@SW_HIDE,$HWnd)
    Return 1
EndFunc
Edited by dmoniac

Share this post


Link to post
Share on other sites

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hWnd, "int", 300, "long", 0x00040008)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hWnd, "int", 300, "long", 0x00050004)

Share this post


Link to post
Share on other sites

Isn't there a DLL which does exactly this for you, only a lot more smooth?

User32.dll

The effects are all available in this UDF


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
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
Sign in to follow this  
Followers 0