Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How To] Animate a GUI Window


  • Please log in to reply
16 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

How to Animate a GUI Window ?
http://www.autohotke...p?p=65596#65596

Foreword: The post is all about DllCall to AnimateWindow function in User32.dll.

MSDN Reference: AnimateWindow Function
Additional Reference: Animate a Window - Real's PB How-to


AnimateWindow() : The Wrapper for User32.dll\AnimateWindow function.

AnimateWindow(hWnd,Duration,Flag) {
Return DllCall("AnimateWindow","UInt",hWnd,"Int",Duration,"UInt",Flag)
}

AnimateWindow() requires three parameters :
[*:1c7sutcr]Handle to the GUI Window
[*:1c7sutcr]Duration of the Animation (in milliseconds)
[*:1c7sutcr]Animation flag which may be any (or proper combination) of the following :

/*

Note: Following integers have to be converted to Hex
      before passing as a parameter to AnimateWindow

1       = Left to Right 
2       = Right to Left 
4       = Top to Bottom 
8       = Bottom to Top 
16      = Center            
65536   = Hide 
131072  = Show
262144  = Slide
524288  = Fade

*/
[/list]How to Fade-In / Fade-Out a GUI ? How To Fade In Fade Out a GUI ?

Copy / Paste / Try example:
FADE       := 524288
SHOW       := 131072
HIDE       := 65536

FADE_SHOW  := FADE+SHOW
FADE_HIDE  := FADE+HIDE

;Converting the above to Hexdecimal value

SetFormat, Integer, Hex
FADE_SHOW+=0 ; Converts to 0xa0000
FADE_HIDE+=0 ; Converts to 0x90000
SetFormat, Integer, d

Duration = 500 ; Duration of Animation in milliseconds

Gui, Margin, 0,0
Gui +LastFound
GUI_ID:=WinExist() ; Handle to the GUI
Gui,Show,w400 h300 Hide, Animated Window ( Fade-In / Fade-Out )
AnimateWindow(GUI_ID, Duration, FADE_SHOW)
Return

GuiEscape:
GuiClose:
  AnimateWindow(GUI_ID, Duration, FADE_HIDE)
  ExitApp
Return

AnimateWindow(hWnd,Duration,Flag) {
Return DllCall("AnimateWindow","UInt",hWnd,"Int",Duration,"UInt",Flag)
}
Optimised version of above code:
Gui, Margin, 0,0
Gui +LastFound
GUI_ID:=WinExist() 
Gui,Show,w400 h300 Hide, Animated Window ( Fade-In / Fade-Out )
DllCall("AnimateWindow","UInt",GUI_ID,"Int",500,"UInt","0xa0000")
Return

GuiEscape:
GuiClose:
  DllCall("AnimateWindow","UInt",GUI_ID,"Int",500,"UInt","0x90000")
  ExitApp
Return

We can modify the wrapper's DllCall to be:
DllCall("AnimateWindow", "UInt", hWnd, "Int", Duration, "Int", Flag)
so that we do not have to convert integers into hexdecimal values.

BUT!.. For reasons unknown to me, many transitions are not smooth (or noticeably jittery!) for me.
Please try both and use what suits you.

In case you need one, here is a simple Integer to Hexadecimal convertor
I made for myself to understand this stuff! I calculated the following effects:

ROLL_LEFT_TO_RIGHT = 0x20001
ROLL_RIGHT_TO_LEFT = 0x20002
ROLL_TOP_TO_BOTTOM = 0x20004
ROLL_BOTTOM_TO_TOP = 0x20008
ROLL_DIAG_TL_TO_BR = 0x20005
ROLL_DIAG_TR_TO_BL = 0x20006
ROLL_DIAG_BL_TO_TR = 0x20009
ROLL_DIAG_BR_TO_TL = 0x2000a
SLIDE_LEFT_TO_RIGHT= 0x40001
SLIDE_RIGHT_TO_LEFT= 0x40002
SLIDE_TOP_TO_BOTTOM= 0x40004
SLIDE_BOTTOM_TO_TOP= 0x40008
SLIDE_DIAG_TL_TO_BR= 0x40005
SLIDE_DIAG_TR_TO_BL= 0x40006
SLIDE_DIAG_BL_TO_TR= 0x40009
SLIDE_DIAG_BR_TO_TL= 0x40010
ZOOM_IN            = 0x16
ZOOM_OUT           = 0x10010
FADE_IN            = 0xa0000
FADE_OUT           = 0x90000

Visit the following post to download & try SlideShow.exe which extensively and effectively
uses the AnimateWindow function:

Posted Image



Edit:

Animated SplashImage !

Copy / Paste / Try example: Fade-In / Fade-Out

IfNotExist, asplash1.gif
 URLDownloadToFile
 , http://autohotkey.net/goyyah/CrazyScripts/SlideShow/asplash1.gif
 , asplash1.gif

Gui, Margin, 0,0
Gui +LastFound
GUI_ID:=WinExist() 
Gui, -Caption +AlwaysOnTop +Border
Gui, Add, Picture, , asplash1.gif
Gui,Show, AutoSize Hide, Animated Splash Window - Demo
DllCall("AnimateWindow","UInt",GUI_ID,"Int",500,"UInt","0xa0000")
Sleep 3000
DllCall("AnimateWindow","UInt",GUI_ID,"Int",500,"UInt","0x90000")
ExitApp

Copy / Paste / Try example: Slide-In from left / Slide-Out to right

IfNotExist, asplash1.gif
 URLDownloadToFile
 , http://autohotkey.net/goyyah/CrazyScripts/SlideShow/asplash1.gif
 , asplash1.gif

Gui, Margin, 0,0
Gui +LastFound
GUI_ID:=WinExist() 
Gui, -Caption +AlwaysOnTop +Border
Gui, Add, Picture, , asplash1.gif
Gui,Show, AutoSize Hide, Animated Splash Window - Demo
DllCall("AnimateWindow","UInt",GUI_ID,"Int",1000,"UInt","0x40001")
Sleep 3000
DllCall("AnimateWindow","UInt",GUI_ID,"Int",1000,"UInt","0x50001")
ExitApp


Edit:

Animated SplashText!

Copy / Paste / Try example: Slow Scrolling Text

ScrollText =
(


AutoHotkey is a free, open-source utility for Windows. 

With it, you can:

Automate almost anything by sending keystrokes and mouse
clicks. You can write macros by hand or use the macro recorder. 

Create hotkeys for keyboard, joystick, and mouse. Virtually any
key, button, or combination can become a hotkey. 

Expand abbreviations as you type them. For example, typing "btw" 
can automatically produce "by the way". 

Create custom data entry forms, user interfaces, and menu bars. 

Remap keys and buttons on your keyboard, joystick, and mouse. 

Respond to signals from hand-held remote controls via the WinLIRC
client script. 

Run existing AutoIt v2 scripts and enhance them with new capabilities. 

Convert any script into an EXE file that can be run on computers 
that don't have AutoHotkey installed. 



)

Gui, Margin, 0,0 
Gui +LastFound 
GUI_ID:=WinExist() 
Gui, -Caption +AlwaysOnTop +Border
Gui, Color, FFFFFF
Gui, Margin, 40, 40
Gui, Font, s12 Bold, Verdana

Gui, Add, Text, x41 y41 c808080 BackGroundTrans, % ScrollText
Gui, Add, Text, x40 y40 c000000 BackGroundTrans, % ScrollText

Gui,Show, AutoSize Hide, Animated Splash Window - Demo 

DllCall("AnimateWindow","UInt",GUI_ID,"Int",20000,"UInt","0x40008") 
DllCall("AnimateWindow","UInt",GUI_ID,"Int",20000,"UInt","0x50008") 
ExitApp



wOxxOm
  • Members
  • 371 posts
  • Last active: Feb 20 2015 12:10 PM
  • Joined: 09 Feb 2006
As to jerky transition in AnimateWindow, MSDN says that it is possible when "Shadows under menus" are enabled in Display effects options. Also "Drag full windows" may interfere I think

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Very nice effects! Thanks!

we do not have to convert integers into hexadecimal values.
BUT!.. For reasons unknown to me, many transitions are not smooth (or noticeably jittery!) for me.

Since at dll calls AHK passes on integers in binary form, there should be no difference. In my laptop I have not seen any, as expected. Are you sure, there was no other change? You don't need many of your quotation marks, either.
Gui +LastFound 
WinGet GUI_ID, ID
Gui Show, w400 h300 Hide, Animated Window
DllCall("AnimateWindow",UInt,GUI_ID,UInt,750,UInt,0xa0000)
Return 

GuiEscape: 
GuiClose: 
  DllCall("AnimateWindow",UInt,GUI_ID,UInt,750,UInt,0x90000) 
ExitApp


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Laszlo, :)

Since at dll calls AHK passes on integers in binary form, there should be no difference. In my laptop I have not seen any, as expected. Are you sure, there was no other change?


You are right! The jiterring was due to processor load by other running programs. Thank you.

You don't need many of your quotation marks, either.


It has become a habit :( ... I will change it :).

Thanks again for posting. :)

Regards, :)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Post Updated: Added an example for Slow Scrolling SplashText.

Regards, :)
kWo4Lk1.png

Fuco
  • Members
  • 49 posts
  • Last active: Oct 24 2008 06:21 PM
  • Joined: 21 Mar 2006
1)
hey i just want ask if i can animate also another then gui windows ( ie notepad etc )

i made code like this
o::
{
WinActivate , a - Notepad
WinGet, GUI_ID , ID , a - Notepad
AnimateWindow(GUI_ID, 5000 , 0x90000 )
winclose , a - Notepad
}

AnimateWindow(hWnd,Duration,Flag) {
Return DllCall("AnimateWindow","UInt",hWnd,"Int",Duration,"UInt",Flag)
}

but it only remove notepad button from taskbar and hide window. ( no fade out ).. pls help :))


2)
also is there a way to hide single button from taskbar ????

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Friend, :)

i just want ask if i can animate also another then gui windows ( ie notepad etc )


I am afraid you cannot! Atleast not with AnimateWindow function.
MSDN states that the calling thread (script) should own the window.. (in other words: You may not use WindowsAnimate with a GUI create by an another program!)

also is there a way to hide single button from taskbar ????


I see that you have also posted it in Ask-for-Help section.. Allow me sometime .. I will try to answer it in that post

Regards, :)
kWo4Lk1.png

BoBo¨
  • Guests
  • Last active:
  • Joined: --

How to Animate a GUI Window ?

Have found that marvelous piece of code. A life saver!
Thanks, Skan (I owe you a लस्सी) 8)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I owe you a लस्सी


:D

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006

I owe you a लस्सी


:D


yogurt drink?????????
(googled it)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Lassi is a Curd-shake ( like milk-shake ) with added flavour. :)

Precise
  • Members
  • 31 posts
  • Last active: May 23 2011 01:55 AM
  • Joined: 30 Dec 2007
Looks like if you have previously set a transcolor in the gui the animation dll calls do not work. I tested several versions of code posted in this topic. All samples work fine until you try to winset, transcolor, somecolor and then dllcall to animate. Is there a way around this that I'm unaware of?

jk7800
  • Members
  • 39 posts
  • Last active: Jul 28 2009 08:41 PM
  • Joined: 06 Jan 2008
The gui animation (from dll) doesn't work for transparent windows. Try using a loop and a transparency/transcolor function, like this:

Loop 255
    WinSet, TransColor, FFFFFF %A_Index%, Title


Precise
  • Members
  • 31 posts
  • Last active: May 23 2011 01:55 AM
  • Joined: 30 Dec 2007

The gui animation (from dll) doesn't work for transparent windows. Try using a loop and a transparency/transcolor function, like this:

Loop 255
    WinSet, TransColor, FFFFFF %A_Index%, Title


Try using ^ for what? The above code makes no sense to me logically. The window is not transparent, part of it is. I have set a transcolor and made a certain part of a gui transparent. It's obvious the dll animation doesnt work for a window with a transcolor set, that was the point in my first post.

What I'm trying to do is show the window from left to right, not fade it. To fade it there's no reason to use dllcall. The above code may be refering to fade I'm not sure. Fade in and out can easily be accomplished with winset transparent, no need to make all colors within the window transparent.

jk7800
  • Members
  • 39 posts
  • Last active: Jul 28 2009 08:41 PM
  • Joined: 06 Jan 2008

Is there a way around (...)

You asked for a workaround, so I wrote it. You didn't mention what type of animation you wanted, so I wrote a workaround for fading in the gui. If you know that it won't work, than why are posting?... My script makes sense, because it works and it simply uses the transparency to fade the window (I see nothing "illogical" here). You should post a better question next time and don't criticize attempts of help...