' This is a demo to illustrate the programming of an animated
' icon when a form is minimized.
Const true = -1
Const false = 0
Dim soundflag As Integer
Dim minflag As Integer
Dim normflag As Integer
Dim maxflag As Integer

Sub Timer1_Timer ()
    If windowstate = 0 And normflag = true Then Animate
    If windowstate = 1 And minflag = true Then Animate
    If windowstate = 2 And maxflag = true Then Animate
End Sub


Sub Minimize_Click ()
    windowstate = 1
    minimize.visible = 0
End Sub

Sub mabout_Click ()
    crlf$ = Chr$(13) + Chr$(10)
    para$ = crlf$ + crlf$
    mess1$ = "I wrote this program to illustrate a technique for animating minimized forms as described in the Microsoft Knowledge Base on Compuserve.  The nice'Help-Description' box in this program was adapted from an article in the February 1992 "
    mess2$ = "issue of 'Inside Visual Basic' published by the Cobb Group." + crlf$ + "Please feel free to distribute this program.  I can be reached on Compuserve at 76356,2251." + para$ + "Harry Garland" + crlf$ + "76356,2251"
    mess$ = mess1$ + mess2$
    dummy = MsgBox(mess$, 64, "About This Program")
End Sub

Sub msound_Click ()
    soundflag = Abs(soundflag) - 1 'toggle soundflag
    msound.checked = soundflag
End Sub

Sub mdescription_Click ()
    iconhlp.Show
    crlf$ = Chr$(13) + Chr$(10)
    para$ = crlf$ + crlf$
    a$ = "The Microsoft knowledge base, available on Compuserve, describes this technique for animating iconized (minimized) forms in Visual Basic.  For reference please see Microsoft document Q79601 dated 2/7/92. "
    b$ = "Normally when a form is minimized it is represented by an icon that is set by the icon property of the form. This icon is a bit map that cannot be animated.  The technique we are demonstrating in this program deletes the icon property of "
    c$ = "the form so that a miniature version of the form itself serves as the icon.  The minimized form can then be animated by using a timer event to invoke graphics operations on the form."
    d$ = "To set up a form so that it can be animated in this way use the property bar to set AutoRedraw to 0 (False). Also using the property bar select the icon property of the form; highlight the property (icon) then press the Delete key. "
    e$ = "Next add a timer to your form and insert your graphics animation code, such as the following, into the timer event subroutine: "
    f$ = "Sub Timer1_Timer ()" + crlf$
    g$ = "    Static prevx!, prevy!" + crlf$
    h$ = "    If windowstate = 1 Then 'i.e. if the form is minimized" + crlf$
    i$ = "      Beep ' if you want sound" + crlf$
    k$ = "      fillcolor = QBColor(4)" + crlf$
    l$ = "      Circle (prevx!, prevy!), scalewidth / 6, QBColor(0)" + crlf$
    m$ = "      fillstyle = 0" + crlf$
    n$ = "      fillcolor = QBColor(14)" + crlf$
    o$ = "      prevx! = Int(Rnd(1) * scalewidth) + 1" + crlf$
    p$ = "      prevy! = Int(Rnd(1) * scaleheight) + 1" + crlf$
    q$ = "      Circle (prevx!, prevy!), scalewidth / 6, QBColor(4)" + crlf$
    r$ = "    End If" + crlf$
    s$ = "End Sub" + crlf$
    t$ = "That's all there is to it!"
    iconhlp.text1.text = a$ + para$ + b$ + c$ + para$ + d$ + e$ + para$ + f$ + g$ + h$ + i$ + k$ + l$ + m$ + n$ + o$ + p$ + q$ + r$ + s$ + para$ + t$
End Sub

Sub normform_Click ()
    normflag = Abs(normflag) - 1
    normform.checked = normflag
End Sub

Sub Form_Load ()
    soundflag = false 'Initially there is no sound
    msound.checked = soundflag
    minflag = true    'Animate when form is minimized
    minform.checked = minflag
    normflag = false
    normform.checked = normflag
    maxflag = true
    maxform.checked = maxflag
End Sub

Sub Animate ()
    Static prevx!, prevy!
    fillstyle = 0
    If soundflag = true Then Beep
    fillcolor = QBColor(4)
    Circle (prevx!, prevy!), scalewidth / 6, QBColor(14)
    fillcolor = QBColor(14)
    prevx! = Int(Rnd(1) * scalewidth) + 1
    prevy! = Int(Rnd(1) * scaleheight) + 1
    Circle (prevx!, prevy!), scalewidth / 6, QBColor(14)
End Sub

Sub minform_Click ()
    minflag = Abs(minflag) - 1
    minform.checked = minflag
End Sub

Sub maxform_Click ()
    maxflag = Abs(maxflag) - 1
    maxform.checked = maxflag
End Sub

