nukesrus21
Apr 22, 2012
=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="vbnet"]] Function AnimateWindow(handle, dwTime, dwFlags)CallDLLCallDLL #user32, "AnimateWindow", _handlehandle as uLong, _dwTimedwTime asLong,uLong, _dwFlagsdwFlags asLong,uLong, _resultresult 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="vbnet"]]AW.SLIDEAW.SLIDE = HexDec("&H40000")AW.HOR.POSITIVEAW.HOR.POSITIVE = HexDec("&H1")AW.HOR.NEGATIVEAW.HOR.NEGATIVE = HexDec("&H2")AW.VER.POSITIVEAW.VER.POSITIVE = HexDec("&H4")AW.VER.NEGATIVEAW.VER.NEGATIVE = HexDec("&H8")AW.CENTERAW.CENTER = HexDec("&H10")AW.BLENDAW.BLEND = HexDec("&H80000")AW.ACTIVATEAW.ACTIVATE = HexDec("&20000")AW.HIDEAW.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="vbnet"]]GlobalGlobal AW.SLIDEGlobalGlobal AW.HOR.POSITIVE, AW.HOR.NEGATIVEGlobalGlobal AW.VER.POSITIVE, AW.VER.NEGATIVEGlobalGlobal AW.CENTERGlobalGlobal AW.ACTIVATE, AW.HIDEGlobalGlobal 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[[wikistylebits|stylebits]][[lbpe/wikistylebits|stylebits]] {{_WS_VISIBLE}} in the removebits position before opening the window. [[code format="vb"]]StylebitsStylebits #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="vbnet"]]Nomainwin WindowWidthNomainwin WindowWidth = 500WindowHeightWindowHeight = 400UpperLeftXUpperLeftX = Int((DisplayWidth - WindowWidth) /2)UpperLeftYUpperLeftY = Int((DisplayHeight - WindowHeight) /2)ButtonButton #demo.b1, " Horizontal L -> R ", AnimWindowOpen, UL, 100, 80, 120, 30ButtonButton #demo.b2, " Horizontal R -> L ", AnimWindowOpen, UL, 100, 120, 120, 30ButtonButton #demo.b3, " Vertical T -> B ", AnimWindowOpen, UL, 100, 160, 120, 30ButtonButton #demo.b4, " Vertical B -> T ", AnimWindowOpen, UL, 100, 200, 120, 30ButtonButton #demo.b5, " Diagonal L -> R", AnimWindowOpen, UL, 280, 80, 120, 30ButtonButton #demo.b6, " Diagonal R -> L ", AnimWindowOpen, UL, 280, 120, 120, 30ButtonButton #demo.b7, " Expand from Center ", AnimWindowOpen, UL, 280, 160, 120, 30ButtonButton #demo.b8, " Fade In ", AnimWindowOpen, UL, 280, 200, 120, 30OpenOpen "Animated Window" for Window as #demo#demo#demo "Trapclose XbyTrap" ' Undefined Windows ConstantsGlobalGlobal AW.HOR.POSITIVE, AW.HOR.NEGATIVEGlobalGlobal AW.VER.POSITIVE, AW.VER.NEGATIVEGlobalGlobal AW.CENTER, AW.HIDE, AW.ACTIVATEGlobalGlobal AW.SLIDE, AW.BLENDAW.HOR.POSITIVEAW.HOR.POSITIVE = HexDec("&H1")AW.HOR.NEGATIVEAW.HOR.NEGATIVE = HexDec("&H2")AW.VER.POSITIVEAW.VER.POSITIVE = HexDec("&H4")AW.VER.NEGATIVEAW.VER.NEGATIVE = HexDec("&H8")AW.CENTERAW.CENTER = HexDec("&H10")AW.HIDEAW.HIDE = HexDec("&H10000")AW.ACTIVATEAW.ACTIVATE = HexDec("&20000")AW.SLIDEAW.SLIDE = HexDec("&H40000")AW.BLENDAW.BLEND = HexDec("&H80000") Wait Sub XbyTrap handle$CloseClose #demo End End Sub Sub AnimWindowOpen handle$SelectSelect Case Right$(handle$, 1)CaseCase "1"dwFlagsdwFlags = AW.HOR.POSITIVE or AW.SLIDEButtonButton #a.1 "Close", AnimWindowClose, UL, 150, 100title$title$ = "Horizontal Slide Left to Right"CaseCase "2"dwFlagsdwFlags = AW.HOR.NEGATIVE or AW.SLIDEButtonButton #a.2 "Close", AnimWindowClose, UL, 150, 100title$title$ = "Horizontal Slide Right to Left"CaseCase "3"dwFlagsdwFlags = AW.VER.POSITIVE or AW.SLIDEButtonButton #a.3 "Close", AnimWindowClose, UL, 150, 100title$title$ = "Vertical Slide Top to Bottom"CaseCase "4"dwFlagsdwFlags = AW.VER.NEGATIVE or AW.SLIDEButtonButton #a.4 "Close", AnimWindowClose, UL, 150, 100title$title$ = "Vertical Slide Bottom to Top"CaseCase "5"dwFlagsdwFlags = AW.HOR.POSITIVE or AW.VER.NEGATIVE or AW.SLIDEButtonButton #a.5 "Close", AnimWindowClose, UL, 150, 100title$title$ = "Diagonal Left to Right"CaseCase "6"dwFlagsdwFlags = AW.HOR.NEGATIVE or AW.VER.POSITIVE or AW.SLIDEButtonButton #a.6, "Close", AnimWindowClose, UL, 150, 100title$title$ = "Diagonal Right to Left"CaseCase "7"dwFlagsdwFlags = AW.CENTER or AW.ACTIVATEButtonButton #a.7 "Close", AnimWindowClose, UL, 150, 100title$title$ = "Expand from Center Outward"CaseCase "8"dwFlagsdwFlags = AW.BLENDButtonButton #a.8, "Close", AnimWindowClose, UL, 150, 100title$title$ = "Vertical Slide Bottom to Top"EndEnd SelectWindowWidthWindowWidth = 400WindowHeightWindowHeight = 300UpperLeftXUpperLeftX = 50UpperLeftYUpperLeftY = 50BackgroundColor$BackgroundColor$ = "Darkpink"StylebitsStylebits #a, 0, _WS_VISIBLE, 0, 0OpenOpen title$ for Dialog_Modal as #a#a#a "Trapclose NoAnimWindowClose"nullnull = AnimateWindow(hWnd(#a), 1000, dwFlags) End Sub Sub AnimWindowClose handle$SelectSelect Case Right$(handle$, 1)CaseCase "1"dwFlagsdwFlags = AW.HOR.NEGATIVE or AW.SLIDE or AW.HIDECaseCase "2"dwFlagsdwFlags = AW.HOR.POSITIVE or AW.SLIDE or AW.HIDECaseCase "3"dwFlagsdwFlags = AW.VER.NEGATIVE or AW.SLIDE or AW.HIDECaseCase "4"dwFlagsdwFlags = AW.VER.POSITIVE or AW.SLIDE or AW.HIDECaseCase "5"dwFlagsdwFlags = AW.HOR.NEGATIVE or AW.VER.POSITIVE or AW.SLIDE or AW.HIDECaseCase "6"dwFlagsdwFlags = AW.HOR.POSITIVE or AW.VER.NEGATIVE or AW.SLIDE or AW.HIDECaseCase "7"dwFlagsdwFlags = AW.CENTER or AW.HIDE ' No effect, unsure whyCaseCase "8"dwFlagsdwFlags = AW.BLEND or AW.HIDEEndEnd Selectnullnull = AnimateWindow(hWnd(#a), 500, dwFlags)CloseClose #a End Sub Sub NoAnimWindowClose handle$CloseClose #handle$ End Sub Function AnimateWindow(handle, dwTime, dwFlags)CallDLLCallDLL #user32, "AnimateWindow", _handlehandle as uLong, _dwTimedwTime asLong,uLong, _dwFlagsdwFlags asLong,uLong, _resultresult as Long End Function [[code]] ===Where's the Imploding Window?=== [[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. ----