Window Display Effects for VO

Users of the VO Productivity Pack 3 may have noticed the new display effects for the VO Export Explorer splash screen - it randomly appears to fade-in, slide or expand into view.

Using the code below this feature is easy to implement in your applications as well.

These display effects are based on the use of a function called AnimateWindow. This function was introduced in Windows 98 and subsequently refined in Windows 2000. I haven't yet verified what improvements may have been included in Windows ME.

AnimateWindow takes three parameters:
- the handle to the window you want to show or hide
- the length of time to display the animation
- the animation type, which can have one or more of the following values:

Value Description
AW_SLIDE Uses slide animation. By default, roll animation is used.
This flag is ignored when used with AW_CENTER.
AW_ACTIVATE Activates the window. Do not use this value with AW_HIDE.
AW_BLEND Uses a fade effect.
This flag can be used only if hwnd is a top-level window.
AW_HIDE Hides the window. By default, the window is shown.
AW_CENTER Makes the window appear to collapse inward if AW_HIDE is
used or expand outward if the AW_HIDE is not used.
AW_HOR_POSITIVE Animates the window from left to right.
This flag can be used with roll or slide animation.
It is ignored when used with AW_CENTER or AW_BLEND.
AW_HOR_NEGATIVE Animates the window from right to left.
This flag can be used with roll or slide animation.
It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_POSITIVE Animates the window from top to bottom.
This flag can be used with roll or slide animation.
It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_NEGATIVE Animates the window from bottom to top.
This flag can be used with roll or slide animation.
It is ignored when used with AW_CENTER or AW_BLEND.

In testing these animation types I found the following restrictions:
- AW_SLIDE by itself does not produce any effect
- AW_BLEND does not display the window under Windows 98
- the only animation effect that works with AW_HIDE is AW_BLEND

To make it easy to use this function I created a method called Animate of class Window. You can see the code below. You can try the example code to animate the HelpAbout window of the Standard Application.

 

METHOD Show() CLASS HelpAbout
    // Make the window fade into view
    IF SELF:Animate(1000,AW_BLEND)
        SELF:SetFocus()
    ELSE
        SUPER:show()
    ENDIF

    // To show window from left to right, top to bottom 
    // SELF:Animate(500,_or(AW_HOR_POSITIVE,AW_VER_POSITIVE))
METHOD Close(oE) CLASS HelpAbout
    // Make the window fade away
    SELF:Animate(1000,_or(AW_HIDE,AW_BLEND))

    RETURN SUPER:close(oE)
METHOD Animate(nTime,nFlags) CLASS Window
    LOCAL hUser, hFunc AS PTR
    LOCAL hWindow AS PTR
    LOCAL dwTime,dwFlags AS DWORD
    LOCAL pVersionInfo IS _WINOSVERSIONINFO
    LOCAL lDone AS LOGIC
    
    // Determine Windows version
    pVersionInfo.dwOSVersionInfoSize := _sizeof(_WINOSVERSIONINFO)
    GetVersionEx(@pVersionInfo)

    // AW_BLEND not shown on Windows version before Win2000, 
    // so remove it (what about ME?)
    IF pVersionInfo.dwMajorVersion < 5
        nFlags := _And(DWORD(nFlags),_not(DWORD(AW_BLEND)))
    ENDIF
        
    hUser := GetModuleHandle(PSZ("USER32.DLL"))
    
    hWindow := SELF:handle()
    dwTime := nTime
    dwFlags := nFlags
    
    IF ! hUser == NULL_PTR
        hFunc := GetProcAddress(hUser,PSZ("AnimateWindow"))
        
        IF ! hFunc == NULL_PTR
            PCALL(hFunc,hWindow,dwTime,dwFlags)
            lDone := TRUE
        ELSE
            // method was called on an OS that does not
            // support AnimateWindow, e.g. Win95, WinNT4
            lDone := FALSE
        ENDIF
    ENDIF
    
    RETURN lDone
DEFINE AW_ACTIVATE := 0x00020000
DEFINE AW_BLEND := 0x00080000
DEFINE AW_CENTER := 0x00000010
DEFINE AW_HIDE := 0x00010000
DEFINE AW_HOR_NEGATIVE := 0x00000002
DEFINE AW_HOR_POSITIVE := 0x00000001
DEFINE AW_SLIDE := 0x00040000
DEFINE AW_VER_NEGATIVE := 0x00000008
DEFINE AW_VER_POSITIVE := 0x00000004