Older Version
Newer Version
JanetTerra
Feb 10, 2015
=AnimateWindow=
===Opening and Closing Windows with Animation===
The {{AnimateWindow}} function allows four types of special effects when showing or hiding windows: roll, slide, expand, and fade. The call is made to {{#user32}}, passing the handle of the window ({{handle}}), the duration of animation in milliseconds ({{dwTime}}), and the desired effects ({{dwFlags}}).
[[code format="lb"]]
Function AnimateWindow(handle, dwTime, dwFlags)
CallDLL #user32, "AnimateWindow", _
handle as uLong, _
dwTime as uLong, _
dwFlags as uLong, _
result as Long
End Function
[[code]]
The functions returns a zero if the function fails, or a non-zero if the function is successful.
===Specifying the Animation Types===
{{AW_SLIDE}} Uses slide animation, the default is {{AW_ROLL}}
{{AW_HOR_POSITIVE}} Animates the window from left to right, used with {{AW_SLIDE}}, or the default {{AW_ROLL}}
{{AW_HOR_NEGATIVE}} Animates the window from right to left, used with {{AW_SLIDE}}, or the default {{AW_ROLL}}
{{AW_VER_POSITIVE}} Animates the window from top to bottom, used with {{AW_SLIDE}}, or the default {{AW_ROLL}}
{{AW_VER_NEGATIVE}} Animates the window from bottom to top, used with {{AW_SLIDE}}, or the default {{AW_ROLL}}
{{AW_CENTER}} Expands the window from centerpoint outward when opening, negates any other direction flags
{{AW_BLEND}} Uses a fade in effect when opening, or a fade out effect when closing, ignored if {{AW_CENTER}} is also assigned
{{AW_ACTIVATE}} Activates the window, should not be used with {{AW_HIDE}}
{{AW_HIDE}} Hides the window, the default is a visible window
===Defining the Animation Values===
Liberty BASIC recognizes many of the Windows constants. These animated window constants are not recognized. The values will need to be defined within the code.
[[code format="lb"]]
AW.SLIDE = HexDec("&H40000")
AW.HOR.POSITIVE = HexDec("&H1")
AW.HOR.NEGATIVE = HexDec("&H2")
AW.VER.POSITIVE = HexDec("&H4")
AW.VER.NEGATIVE = HexDec("&H8")
AW.CENTER = HexDec("&H10")
AW.BLEND = HexDec("&H80000")
AW.ACTIVATE = HexDec("&H20000")
AW.HIDE = HexDec("&H10000")
[[code]]
If these values need to be seen within several subs or functions, it may be best to declare them {{Global}} in the beginning of your program.
[[code format="lb"]]
Global AW.SLIDE
Global AW.HOR.POSITIVE, AW.HOR.NEGATIVE
Global AW.VER.POSITIVE, AW.VER.NEGATIVE
Global AW.CENTER
Global AW.ACTIVATE, AW.HIDE
Global AW.BLEND
[[code]]
===Showing and Hiding Windows===
To show a window opening using an animation, that window must first be in {{AW_HIDE}} mode. Assign the [[lbpe/wikistylebits|stylebits]] {{_WS_VISIBLE}} in the removebits position before opening the window.
[[code format="lb"]]
Stylebits #a, 0, _WS_VISIBLE, 0, 0
[[code]]
===The Demo===
The following demo uses various combinations of the {{AW}} values. Some effects are more pleasing than others. Not all combinations work with all types of windows. [[http://msdn2.microsoft.com/en-us/library/ms632669(VS.85).aspx|MSDN]] suggests 200 milliseconds as the value for {{dwTime}}. This demo uses a greater {{dwTime}} value for illustrative purposes. Adjust the value according to the needs of your program.
[[code format="lb"]]
Nomainwin
WindowWidth = 500
WindowHeight = 400
UpperLeftX = Int((DisplayWidth - WindowWidth) /2)
UpperLeftY = Int((DisplayHeight - WindowHeight) /2)
Button #demo.b1, " Horizontal L -> R ", AnimWindowOpen, UL, 100, 80, 120, 30
Button #demo.b2, " Horizontal R -> L ", AnimWindowOpen, UL, 100, 120, 120, 30
Button #demo.b3, " Vertical T -> B ", AnimWindowOpen, UL, 100, 160, 120, 30
Button #demo.b4, " Vertical B -> T ", AnimWindowOpen, UL, 100, 200, 120, 30
Button #demo.b5, " Diagonal L -> R", AnimWindowOpen, UL, 280, 80, 120, 30
Button #demo.b6, " Diagonal R -> L ", AnimWindowOpen, UL, 280, 120, 120, 30
Button #demo.b7, " Expand from Center ", AnimWindowOpen, UL, 280, 160, 120, 30
Button #demo.b8, " Fade In ", AnimWindowOpen, UL, 280, 200, 120, 30
Open "Animated Window" for Window as #demo
#demo "Trapclose XbyTrap"
' Undefined Windows Constants
Global AW.HOR.POSITIVE, AW.HOR.NEGATIVE
Global AW.VER.POSITIVE, AW.VER.NEGATIVE
Global AW.CENTER, AW.HIDE, AW.ACTIVATE
Global AW.SLIDE, AW.BLEND
AW.HOR.POSITIVE = HexDec("&H1")
AW.HOR.NEGATIVE = HexDec("&H2")
AW.VER.POSITIVE = HexDec("&H4")
AW.VER.NEGATIVE = HexDec("&H8")
AW.CENTER = HexDec("&H10")
AW.HIDE = HexDec("&H10000")
AW.ACTIVATE = HexDec("&H20000")
AW.SLIDE = HexDec("&H40000")
AW.BLEND = HexDec("&H80000")
Wait
Sub XbyTrap handle$
Close #demo
End
End Sub
Sub AnimWindowOpen handle$
Select Case Right$(handle$, 1)
Case "1"
dwFlags = AW.HOR.POSITIVE or AW.SLIDE
Button #a.1 "Close", AnimWindowClose, UL, 150, 100
title$ = "Horizontal Slide Left to Right"
Case "2"
dwFlags = AW.HOR.NEGATIVE or AW.SLIDE
Button #a.2 "Close", AnimWindowClose, UL, 150, 100
title$ = "Horizontal Slide Right to Left"
Case "3"
dwFlags = AW.VER.POSITIVE or AW.SLIDE
Button #a.3 "Close", AnimWindowClose, UL, 150, 100
title$ = "Vertical Slide Top to Bottom"
Case "4"
dwFlags = AW.VER.NEGATIVE or AW.SLIDE
Button #a.4 "Close", AnimWindowClose, UL, 150, 100
title$ = "Vertical Slide Bottom to Top"
Case "5"
dwFlags = AW.HOR.POSITIVE or AW.VER.NEGATIVE or AW.SLIDE
Button #a.5 "Close", AnimWindowClose, UL, 150, 100
title$ = "Diagonal Left to Right"
Case "6"
dwFlags = AW.HOR.NEGATIVE or AW.VER.POSITIVE or AW.SLIDE
Button #a.6, "Close", AnimWindowClose, UL, 150, 100
title$ = "Diagonal Right to Left"
Case "7"
dwFlags = AW.CENTER or AW.ACTIVATE
Button #a.7 "Close", AnimWindowClose, UL, 150, 100
title$ = "Expand from Center Outward"
Case "8"
dwFlags = AW.BLEND
Button #a.8, "Close", AnimWindowClose, UL, 150, 100
title$ = "Vertical Slide Bottom to Top"
End Select
WindowWidth = 400
WindowHeight = 300
UpperLeftX = 50
UpperLeftY = 50
BackgroundColor$ = "Darkpink"
Stylebits #a, 0, _WS_VISIBLE, 0, 0
Open title$ for Dialog_Modal as #a
#a "Trapclose NoAnimWindowClose"
null = AnimateWindow(hWnd(#a), 1000, dwFlags)
End Sub
Sub AnimWindowClose handle$
Select Case Right$(handle$, 1)
Case "1"
dwFlags = AW.HOR.NEGATIVE or AW.SLIDE or AW.HIDE
Case "2"
dwFlags = AW.HOR.POSITIVE or AW.SLIDE or AW.HIDE
Case "3"
dwFlags = AW.VER.NEGATIVE or AW.SLIDE or AW.HIDE
Case "4"
dwFlags = AW.VER.POSITIVE or AW.SLIDE or AW.HIDE
Case "5"
dwFlags = AW.HOR.NEGATIVE or AW.VER.POSITIVE or AW.SLIDE or AW.HIDE
Case "6"
dwFlags = AW.HOR.POSITIVE or AW.VER.NEGATIVE or AW.SLIDE or AW.HIDE
Case "7"
dwFlags = AW.CENTER or AW.HIDE ' No effect, unsure why
Case "8"
dwFlags = AW.BLEND or AW.HIDE
End Select
null = AnimateWindow(hWnd(#a), 500, dwFlags)
Close #a
End Sub
Sub NoAnimWindowClose handle$
Close #handle$
End Sub
Function AnimateWindow(handle, dwTime, dwFlags)
CallDLL #user32, "AnimateWindow", _
handle as uLong, _
dwTime as uLong, _
dwFlags as uLong, _
result as Long
End Function
[[code]]
===Where's the Imploding Window?===
<span style="text-decoration: line-through;">[[http://msdn2.microsoft.com/en-us/library/ms632669(VS.85).aspx|MSDN]] states //To take effect when hiding a window, use AW_HIDE and a logical OR operator with the appropriate flags// and //AW_CENTER makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used//. Thus far, I haven't found the correct combination to achieve an imploding closing window.</span>
2/10/2015 - Thanks to datwill for solving this problem by reassigning the variable AW.ACTIVATE from &20000 to &H20000. The closing window now implodes.
----