Dialog Animation : Libfunc>user32.dll,AnimateWindow

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Dialog Animation : Libfunc>user32.dll,AnimateWindow

Post by JRL » Mon Aug 25, 2008 9:40 pm

Dialog "animation" through Windows API. Sounds good but like many things Microsoft, its not as straight forward as it might seem to be. Following is a demo script that allows you to demo open and close dialog "animations". When you have the demo working as you like, you can save the settings to the clipboard formatted to be used in a Macro Scheduler script.

Be aware that closing a dialog through animation is one thing, opening a dialog with animation may give strange results. You may need to open the dialog, close the dialog, then open the dialog using animation. Or... open individual objects within the dialog.

When it works, its fun to watch. So far, I've seen no issues with the following script. Notice it does not animate open, it only animates for the animation demo and when it closes. You can select multiple directions and get the dialog to slide in and out of corners also.

Here's the toy. Try it. Good luck.

Edit 01/20/2011:
There was an extra OnEvent line at the top of this code that was apparently ignored in older versions of Macro Scheduler but caused version 12 to halt. It has been removed. Thank you to jpuziano for pointing this out.

Code: Select all

OnEvent>KEY_DOWN,VK112,0,Help
OnEvent>KEY_DOWN,VK27,0,Restore

SRT>Restore
  LibFunc>User32,AnimateWindow,swres,dialog1.handle,1,327696
  LibFunc>User32,ShowWindow,swres,dialog1.handle,1
  ResetDialogAction>dialog1
  Press tab*7
END>Restore


Let>AW_HOR_POSITIVE=1
Let>AW_HOR_NEGATIVE=2
Let>AW_VER_POSITIVE=4
Let>AW_VER_NEGATIVE=8
Let>AW_CENTER=16
Let>AW_HIDE=65536
Let>AW_ACTIVATE=131072
Let>AW_SLIDE=262144
Let>AW_BLEND=524288
Let>value_hor_0=0
Let>value_hor_1=%AW_HOR_POSITIVE%
Let>value_hor_2=%AW_HOR_NEGATIVE%
Let>value_ver_0=0
Let>value_ver_1=%AW_VER_POSITIVE%
Let>value_ver_2=%AW_VER_NEGATIVE%
Let>value_ver_3=%AW_CENTER%

Let>milliseconds=1000

Dialog>Dialog7
   Caption=AnimateWindow Help
   Width=480
   Height=680
   Top=CENTER
   Left=CENTER
   Label=msLabel1,16,8
   Image=,16,8,280,12,,3
EndDialog>Dialog7

Dialog>Dialog5
   Caption=To Clipboard
   Width=179
   Height=134
   Top=CENTER
   Left=CENTER
   Label=Name of dialog to be animated,8,8
   Label=For example:   Dialog1,32,24
   Edit=msEdit1,24,40,121,Dialog1
   Button=Ok,48,72,75,25,3
   Default=Ok
EndDialog>Dialog5

Dialog>Dialog1
   Caption=Animate Dialog Builder
   Width=365
   Height=367
   Top=CENTER
   Left=CENTER
   Label=Time in Milliseconds,34,8
   Edit=msEdit1,48,24,73,%milliseconds%
   Label=Time in Milliseconds,218,8
   Edit=msEdit2,232,24,73,%milliseconds%
   Button=Test,176,304,75,25,3
   Button=Copy to%CRLF%Clipboard,272,296,75,35,4
   RadioGroup=msRadioGroup1,Close,8,48,153,65,None%CRLF%AW_HOR_POSITIVE%CRLF%AW_HOR_NEGATIVE,0
   RadioGroup=msRadioGroup2,Open,192,48,153,65,None%CRLF%AW_HOR_POSITIVE%CRLF%AW_HOR_NEGATIVE,0
   RadioGroup=msRadioGroup3, ,8,120,153,89,None%CRLF%AW_VER_POSITIVE%CRLF%AW_VER_NEGATIVE%CRLF%AW_CENTER,0
   RadioGroup=msRadioGroup4, ,192,120,153,89,None%CRLF%AW_VER_POSITIVE%CRLF%AW_VER_NEGATIVE%CRLF%AW_CENTER,0
   RadioGroup=msRadioGroup5, ,8,216,153,73,SLIDE%CRLF%ROLL%CRLF%BLEND,0
   RadioGroup=msRadioGroup6, ,192,216,153,73,SLIDE%CRLF%ROLL%CRLF%BLEND,0
   Label=Press F1 for AnimateWindow help,3,316
   Default=Test
EndDialog>Dialog1

Show>dialog1

Label>Loop
  GetDialogAction>dialog1,res1
  If>res1=2,EOF
  If>res1=3,Process
  If>res1=4
    GoSub>Process,save
  EndIf

  If>%dialog1.msradiogroup3.itemindex%<>3
    If>dialog1.msradiogroup5=BLEND
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup1.handle,200,327696
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup3.handle,200,327696
    Else
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup1.handle,200,262160
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup3.handle,200,262160
    EndIf
  EndIf

  If>%DIALOG1.MSRADIOGROUP4.itemindex%<>3
    If>dialog1.msradiogroup6=BLEND
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup2.handle,200,327696
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup4.handle,200,327696
    Else
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup2.handle,200,262160
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup4.handle,200,262160
    EndIf
  EndIf
  If>%dialog1.msradiogroup5%<>BLEND
    If>dialog1.msradiogroup3.itemindex=3
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup1.handle,200,327696
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup5.handle,200,327696
    Else
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup1.handle,200,262160
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup5.handle,200,262160
    EndIf
  EndIf
  If>%dialog1.msradiogroup6%<>BLEND
    If>dialog1.msradiogroup4.itemindex=3
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup2.handle,200,327696
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup6.handle,200,327696
    Else
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup2.handle,200,262160
	  Libfunc>user32.dll,AnimateWindow,Result,dialog1.msradiogroup6.handle,200,262160
    EndIf
  EndIf
  Wait>0.01
Goto>Loop

SRT>EOF
  Show>dialog1
  Let>close={%AW_HIDE% OR %AW_CENTER%}
  Libfunc>user32.dll,AnimateWindow,Ok,dialog1.handle,milliseconds,close
  Exit>0
END>EOF

SRT>Process
  If>{(%dialog1.msedit1%="")or(%dialog1.msedit2%="")}
    MDL>Time cannot be blank
    Goto>Complete
  EndIf
  Let>test1=%dialog1.msradiogroup1.itemindex%
  Let>test2=%dialog1.msradiogroup2.itemindex%
  Let>test3=%dialog1.msradiogroup3.itemindex%
  Let>test4=%dialog1.msradiogroup4.itemindex%
  Let>test5=%dialog1.msradiogroup5.itemindex%
  Let>test6=%dialog1.msradiogroup6.itemindex%

  If>{(((%test1%=0)and(%test3%=0))or((%test2%=0)and(%test4%=0)))and(%test5%<>2)and(%test6%<>2)and(%test3%<>3)and(%test4%<>3)}
    MDL>You must make at least one selection%CRLF%from the first two groups in each column%CRLF%or select BLEND.
	ResetDialogAction>dialog1
  Else
    Let>cls1=value_hor_%dialog1.msradiogroup1.itemindex%
    Let>cls2=value_ver_%dialog1.msradiogroup3.itemindex%
    If>dialog1.msradiogroup5=SLIDE
      Let>cls={%AW_HIDE% OR %cls1% OR %cls2% OR %AW_SLIDE%}
    Else
      Let>cls={%AW_HIDE% OR %cls1% OR %cls2%}
    EndIf
	Let>opn1=value_hor_%dialog1.msradiogroup2.itemindex%
  	Let>opn2=value_ver_%dialog1.msradiogroup4.itemindex%
    If>dialog1.msradiogroup6=SLIDE
      Let>opn={%opn1% OR %opn2% OR %AW_SLIDE%}
    Else
      Let>opn={%opn1% OR %opn2%}
    EndIf

    If>dialog1.msradiogroup6=BLEND
      Let>opn=%AW_BLEND%
    EndIf
    If>dialog1.msradiogroup5=BLEND
      Let>cls={%AW_HIDE% OR %AW_BLEND%}
    EndIf
	If>%Process_var_1%=save,Save
    Wait>0.1
    Libfunc>user32.dll,AnimateWindow,Result,dialog1.handle,dialog1.msedit1,cls
    Wait>0.1
    Libfunc>user32.dll,AnimateWindow,Result,dialog1.handle,dialog1.msedit2,opn
    Label>Complete
	If>dialog1.msradiogroup6=BLEND
	LibFunc>User32,AnimateWindow,swres,dialog1.handle,1,327696
	LibFunc>User32,ShowWindow,swres,dialog1.handle,1
	EndIf
    ResetDialogAction>dialog1
    Press tab*7
  EndIf
END>Process

SRT>Save
      Label>Loop2
    Show>Dialog5,res5
    If>res5=2
      Show>dialog1
      Goto>Loop
    EndIf
    If>dialog5.msedit1=
      MDL>Dialog name required
      Goto>Loop2
    EndIf
    If>cls=
      MDL>you must run the settings before saving them
      Show>dialog1
      Goto>Loop
    EndIf
    Let>Clip=//Open %dialog5.msedit1% script%CRLF%
    Concat>Clip,Libfunc>user32.dll,AnimateWindow,Result,%dialog5.msedit1%.handle,%dialog1.msedit1%,%opn%%CRLF%
    Concat>Clip,//Close %dialog5.msedit1% script%CRLF%
    Concat>Clip,Libfunc>user32.dll,AnimateWindow,Result,%dialog5.msedit1%.handle,%dialog1.msedit1%,%cls%
    PutClipBoard>Clip
    GoSub>EOF
END>Save


SRT>Help
Let>helptext=http://msdn.microsoft.com/en-us/library/ms632669.aspx%CRLF%%CRLF%
Concat>helptext,AnimateWindow Function:%CRLF%

Concat>helptext,The AnimateWindow function enables you to produce special effects when showing or%CRLF%
Concat>helptext,hiding windows. There are four types of animation: roll, slide, collapse or expand,%CRLF%
Concat>helptext,and alpha-blended fade.%CRLF%%CRLF%

Concat>helptext,Syntax:%CRLF%

Concat>helptext,    BOOL AnimateWindow(%CRLF%
Concat>helptext,        HWND hwnd,%CRLF%
Concat>helptext,        DWORD dwTime,%CRLF%
Concat>helptext,        DWORD dwFlags%CRLF%
Concat>helptext,    );%CRLF%%CRLF%
Concat>helptext,Parameters:%CRLF%%CRLF%
Concat>helptext,hwnd%CRLF%
Concat>helptext,%TAB%[in] Handle to the window to animate. The calling thread must own this window.%CRLF%
Concat>helptext,dwTime%CRLF%
Concat>helptext,%TAB%[in] Specifies how long it takes to play the animation, in milliseconds.%CRLF%
Concat>helptext,%TAB%Typically, an animation takes 200 milliseconds to play.%CRLF%
Concat>helptext,dwFlags%CRLF%
Concat>helptext,%TAB%[in] Specifies the type of animation. This parameter can be one or more of the%CRLF%
Concat>helptext,%TAB%following values. Note that, by default, these flags take effect when showing a%CRLF%
Concat>helptext,%TAB%window. To take effect when hiding a window, use AW_HIDE and a logical OR%CRLF%
Concat>helptext,%TAB%operator with the appropriate flags.%CRLF%
Concat>helptext,%CRLF%
Concat>helptext,AW_SLIDE%CRLF%
Concat>helptext,%TAB%Uses slide animation. By default, roll animation is used. This flag is ignored%CRLF%
Concat>helptext,%TAB%when used with AW_CENTER.%CRLF%
Concat>helptext,AW_ACTIVATE%CRLF%
Concat>helptext,%TAB%Activates the window. Do not use this value with AW_HIDE.%CRLF%
Concat>helptext,AW_BLEND%CRLF%
Concat>helptext,%TAB%Uses a fade effect. This flag can be used only if hwnd is a top-level window.%CRLF%
Concat>helptext,AW_HIDE%CRLF%
Concat>helptext,%TAB%Hides the window. By default, the window is shown.%CRLF%
Concat>helptext,AW_CENTER%CRLF%
Concat>helptext,%TAB%Makes the window appear to collapse inward if AW_HIDE is used or expand%CRLF%
Concat>helptext,%TAB%outward if the AW_HIDE is not used. The various direction flags have no effect.%CRLF%
Concat>helptext,AW_HOR_POSITIVE%CRLF%
Concat>helptext,%TAB%Animates the window from left to right. This flag can be used with roll or%CRLF%
Concat>helptext,%TAB%slide animation. It is ignored when used with AW_CENTER or AW_BLEND.%CRLF%
Concat>helptext,AW_HOR_NEGATIVE%CRLF%
Concat>helptext,%TAB%Animates the window from right to left. This flag can be used with roll or%CRLF%
Concat>helptext,%TAB%slide animation. It is ignored when used with AW_CENTER or AW_BLEND.%CRLF%
Concat>helptext,AW_VER_POSITIVE%CRLF%
Concat>helptext,%TAB%Animates the window from top to bottom. This flag can be used with roll or%CRLF%
Concat>helptext,%TAB%slide animation. It is ignored when used with AW_CENTER or AW_BLEND.%CRLF%
Concat>helptext,AW_VER_NEGATIVE%CRLF%
Concat>helptext,%TAB%Animates the window from bottom to top. This flag can be used with roll or%CRLF%
Concat>helptext,%TAB%slide animation. It is ignored when used with AW_CENTER or AW_BLEND.%CRLF%
Concat>helptext,%CRLF%
Concat>helptext,%TAB%Flag%TAB%%TAB%%TAB%%TAB%Hex%TAB%%TAB%%TAB%Integer%CRLF%
Concat>helptext,%TAB%AW_HOR_POSITIVE%TAB%%TAB%0x00000001%TAB%%TAB%1%CRLF%
Concat>helptext,%TAB%AW_HOR_NEGATIVE%TAB%%TAB%0x00000002%TAB%%TAB%2%CRLF%
Concat>helptext,%TAB%AW_VER_POSITIVE%TAB%%TAB%0x00000004%TAB%%TAB%4%CRLF%
Concat>helptext,%TAB%AW_VER_NEGATIVE%TAB%%TAB%0x00000008%TAB%%TAB%8%CRLF%
Concat>helptext,%TAB%AW_CENTER%TAB%%TAB%%TAB%0x00000010%TAB%%TAB%16%CRLF%
Concat>helptext,%TAB%AW_HIDE%TAB%%TAB%%TAB%0x00010000%TAB%%TAB%65536%CRLF%
Concat>helptext,%TAB%AW_ACTIVATE%TAB%%TAB%%TAB%0x00020000%TAB%%TAB%131072%CRLF%
Concat>helptext,%TAB%AW_SLIDE%TAB%%TAB%%TAB%0x00040000%TAB%%TAB%262144%CRLF%
Concat>helptext,%TAB%AW_BLEND%TAB%%TAB%%TAB%0x00080000%TAB%%TAB%524288%CRLF%
Let>dialog7.mslabel1=%helptext%
ResetDialogAction>dialog7
Show>dialog7
Label>Loop7
  GetDialogAction>dialog7,res7
  If>res7=2,Done7
  If>res7=3
    Exe>http://msdn.microsoft.com/en-us/library/ms632669.aspx
	ResetDialogAction>dialog7
  EndIf
  Wait>0.01
Goto>Loop7
Label>Done7
ResetDialogAction>dialog7
END>Help
//Dick Lockey
//July 12,2008
Last edited by JRL on Thu Jan 20, 2011 10:54 pm, edited 2 times in total.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Wed Aug 27, 2008 6:42 pm

Fun script to play with. :D

Thank you for sharing it with all of us.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Dialog Animation : Libfunc>user32.dll,AnimateWindow

Post by jpuziano » Fri Jan 21, 2011 6:21 am

JRL wrote:Edit 01/20/2011:
There was an extra OnEvent line at the top of this code that was apparently ignored in older versions of Macro Scheduler but caused version 12 to halt. It has been removed. Thank you to jpuziano for pointing this out.
No problem... thanks again for sharing this great script.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Grovkillen
Automation Wizard
Posts: 1035
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Dialog Animation : Libfunc>user32.dll,AnimateWindow

Post by Grovkillen » Mon Jul 06, 2020 8:37 am

I thought I'd reply here because this example script wasn't making me understand the idea of the DWORD as decimal.

This part:

Code: Select all

LibFunc>User32,AnimateWindow,swres,dialog1.handle,1,327696
Equals to the DWORD value of 0x00050010 which doesn't make any sense because that would be overruled by "AW_CENTER":
AW_SLIDE 0x00040000
Uses slide animation. By default, roll animation is used. This flag is ignored when used with AW_CENTER.


So the value for AW_SLIDE (and hide) is 0x00040010 = 262160. If we want to simply do the AW_CENTER followed by a AW_HIDE we use the DWORD value of 0x00010010 = 65552:

Code: Select all

LibFunc>User32,AnimateWindow,swres,dialog1.handle,1,65552
For others looking to learn how to use Windows API and come upon these types of declarations. Use the Windows calculator and set it to "programmer" view. Click the button for type of calculations to DWORD (not WORD, BYTE or QWORD) and then click on the HEX row and type the hexadecimal value, you now get the corresponding decimal value below... if you need to do the conversion the other way around you click on the decimal row and type the decimal value.

To combine flags as we have done above you simply add the values together, as an example:

AW_BLEND = 0x00080000
AW_HIDE = 0x00010000
combined: 0x00090000 = decimal: 589824

This would make the window fade out (duration 2000 mSec):

Code: Select all

LibFunc>User32,AnimateWindow,swres,dialog1.handle,2000,589824
https://docs.microsoft.com/en-us/window ... matewindow

PS. you can do this with any element that got a handle.
PS2. Remember that hex goes from 0..F when adding values together.
0x00080000 + 0x00080000 = 0x00100000
0x00060000 + 0x00080000 = 0x000E0000
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1035
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Dialog Animation : Libfunc>user32.dll,AnimateWindow

Post by Grovkillen » Thu May 25, 2023 11:21 am

Note to myself: animations are blocking and thus stalling the script.
Let>ME=%Script%

Running: 15.0.24
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts