Sign in to follow this  
Followers 0
insignia96

GUI Fade In / Fade out

12 posts in this topic

#1 ·  Posted (edited)

This is a simple little UDF I made that fades your GUI in with pure AutoIt.

To show your GUI simply call the _FadeGUIIn() function, the only parameter is a handle to the GUI, and it will fade in. here is the UDF:

#include-once

; #INDEX# =======================================================================================================================
; Title .........: GUI Fading Script
; Description ...: This module contains functions used to fade a GUI in and out with pure AutoIt code.
; AutoIt Version.: 3.3.0.0 (Current Release)
; Author ........: Insignia96 (iWoW Programming)
; ===============================================================================================================================


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

; #NO_DOC_FUNCTION# =============================================================================================================
; Not working/documented/implimented at this time
; ===============================================================================================================================
; NONE
; ===============================================================================================================================

; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
;_FadeGUIIn
;_FadeGUIOut
; ===============================================================================================================================


; #DECLARES# ;===============================================================================
;
Global $GUIFADE_MAXTRANS = 255 ; the current max transparency level
;
; ;==========================================================================================

; #FUNCTION# ;===============================================================================
;
; Name...........: _FadeGUIIn
; Description ...: Gradually shows a GUI.
; Syntax.........: _FadeGUIIn( $hWnd )
; Parameters ....: $hWnd - Handle to GUI you wish to fade in.
;                  $iMax - The transparency level to stop at. (0-255, 0 = hidden, 255 = fully shown)
; Return values .: None
; Author ........: Insignia96 (iWoW Programming)
; Modified.......: Saturday, December 12, 2009
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; Yes
;
; ;==========================================================================================

Func _FadeGUIIn($hWnd,$iMax=255)

    $GUIFADE_MAXTRANS = $iMax

    WinSetTrans($hWnd, "", 0)

    GUISetState(@SW_SHOW)

    Local $delay = 0

    For $i = 1 To $iMax Step 1
        WinSetTrans($hWnd, "", $i)
        Sleep($delay)
    Next

EndFunc   ;==>_FadeGUIIn

; #FUNCTION# ;===============================================================================
;
; Name...........: _FadeGUIOut
; Description ...: Gradually fades a GUI out.
; Syntax.........: _FadeGUIOut( $hWnd )
; Parameters ....: $hWnd - Handle to GUI you wish to fade out.
; Return values .: None
; Author ........: Insignia96 (iWoW Programming)
; Modified.......: Saturday, December 12, 2009
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; Yes
;
; ;==========================================================================================

Func _FadeGUIOut($hWnd)
    Local $delay = 0

    For $i = $GUIFADE_MAXTRANS To 0 Step -1
        WinSetTrans($hWnd, "", $i)
        Sleep($delay)
    Next

    GUISetState(@SW_HIDE)
EndFunc   ;==>_FadeGUIOut

And I also provided an example script:

; ~~~~~~~~~~~ INCLUDES ~~~~~~~~~~

#include "GUIFade.au3"

; ~~~~~~~~~~~ END INCLUDES ~~~~~~~~~~~

; ~~~~~~~~~~~ INTERNAL CONFIGURATION ~~~~~~~~~~

Global $width = 350 ; Width of GUI to be created.

Global $height = 350 ; Height of GUI to be created.

Global $title = "Test GUI" ; Title of GUI to be created.

Global $max_trans = 255 ; How transparent do you want the window, 0 = hidden, 255 = fully shown

; ~~~~~~~~~~~ END CONF ~~~~~~~~~~~

Global $pos[2]
$pos[0] = @DesktopWidth / 2 - $width / 2 ; X (left) position of window
$pos[1] = @DesktopHeight / 2 - $height / 2 ; Y (top) Position of window

Global $hGUI = GUICreate($title & " - w/ Fade in/out", $width, $height, $pos[0], $pos[1])
_FadeGUIIn($hGUI,$max_trans)

While 1
    Local $nMsg = GUIGetMsg()

    Switch $nMsg
        Case -3
            _FadeGUIOut($hGUI)
            Exit
    EndSwitch
WEnd

I also made a zip file for download here: GUIFade.zip

Enjoy! (and please comment!)

EDIT: Fixed title

EDIT2: added $iMax parameter (GEOSoft's idea)

WARNING: The $iMax Parameter may cause problems when using the _GUIFadeOut() function on multiple GUI's

Edited by insignia96

Visit my website to see all my finished releases!Releases here:UDFs:GUI ResizingColor List (Web Colors)GUIFade_NearestPower

Share this post


Link to post
Share on other sites



That works.

I just find it easier to use the DLL method.

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hWnd, "int", $tFade, "long", $Fade)

Where $tFade is the fade in/out time And $Fade is 0x80000 for fade in and 0x90000 for fade out


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

No problem with that but can I suggest a minor change in them? Just to allow for those windows where someone wants semi-transparency, add a parameter to replace the 255 and another to control $delay ($iDelay below) so people can choose the transition rate.

Func _FadeGUIIn($hWnd, $iMax = 255, $iDelay = 0)

    WinSetTrans($hWnd, "", 0)

    GUISetState(@SW_SHOW)

    For $i = 1 To $iMax Step 1
        WinSetTrans($hWnd, "", $i)
        Sleep($iDelay)
    Next

EndFunc   ;==>_FadeGUIIn

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

No problem with that but can I suggest a minor change in them? Just to allow for those windows where someone wants semi-transparency, add a parameter to replace the 255 and another to control $delay ($iDelay below) so people can choose the transition rate.

Func _FadeGUIIn($hWnd, $iMax = 255, $iDelay = 0)

    WinSetTrans($hWnd, "", 0)

    GUISetState(@SW_SHOW)

    For $i = 1 To $iMax Step 1
        WinSetTrans($hWnd, "", $i)
        Sleep($iDelay)
    Next

EndFunc   ;==>_FadeGUIIn

Actually, it had a delay parameter at first, however the sleep function could only do 10ms between increments, that meant that it was really slow, so i deleted it. I will add the semi-transparency option.

Visit my website to see all my finished releases!Releases here:UDFs:GUI ResizingColor List (Web Colors)GUIFade_NearestPower

Share this post


Link to post
Share on other sites

I just wanted it in "Pure AutoIt", also im pretty sure this way works faster.

What?

That works.

I just find it easier to use the DLL method.

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hWnd, "int", $tFade, "long", $Fade)

Where $tFade is the fade in/out time And $Fade is 0x80000 for fade in and 0x90000 for fade out

Share this post


Link to post
Share on other sites

What?

I also forgot to mention that $tFade is in milliseconds

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

I did that long time ago !!!

see my sign "Ending Script Nicely" ;)

Cramaboule !!!

Share this post


Link to post
Share on other sites

I did that long time ago !!!

see my sign "Ending Script Nicely" ;)

Cramaboule !!!

So have several others. People have been writing that since WinSetTrans() was first added to AutoIt, none the less, he made it work which was good practice.

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

No problem with that but can I suggest a minor change in them? Just to allow for those windows where someone wants semi-transparency, add a parameter to replace the 255 and another to control $delay ($iDelay below) so people can choose the transition rate.

Func _FadeGUIIn($hWnd, $iMax = 255, $iDelay = 0)

    WinSetTrans($hWnd, "", 0)

    GUISetState(@SW_SHOW)

    For $i = 1 To $iMax Step 1
        WinSetTrans($hWnd, "", $i)
        Sleep($iDelay)
    Next

EndFunc   ;==>_FadeGUIIn

I put in the delay. good thing to do. I agree with the dll concept. DLL is more stable to less frequent changes. I did a major autoit automation for client. when it came to update for more features, had to update autoit on each site which should be done anyhow. Just like to change one for all sites. My two cents worth. thanks. I will use this one you did.

Dr SherlockAlways a way

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Hi!

Difference between Autoit_trans method and DLL method:

- DLL method delete shadow of the window before fadein (and re-set after fadeout).

- Autoit_trans keep shadow during run.

(under Win 7-32 + Aero + shadow)

Edited by Michel Claveau

Share this post


Link to post
Share on other sites

Also you should change GUISetState(xxx) to GUISetState(xxx, $hWnd), otherwise the function always refers to the last gui handle used.

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