Applies to  VB4+ 

Displaying the Hourglass

Technique 1

To display the hourglass mouse pointer throughout your application, set the MousePointer property of the Screen object:

To show the hourglass, call Hourglass True. To hide the hourglass, call Hourglass False.

The Hourglass procedure uses an internal counter so that you can nest Hourglass calls. For example, suppose you have a procedure Y that calls a procedure Z, and both show the hourglass:

Sub Y()
    Hourglass True
    ' [Long operation begins]

    Z   ' Call another lengthy procedure
    
    ' [Long operation continues]
    Hourglass False
End Sub

Sub Z()
    Hourglass True
    ' [Long operation]
    Hourglass False
End Sub

The implementation of Hourglass ensures that after Z calls Hourglass False, the hourglass is still visible -- as it should be since Y is still busy.

Technique 2

The previous technique isn't perfect. If Z displays a message box in the middle of its processing, the user will still see the hourglass. The Hourglass procedure in General.bas lets you temporarily turn off the hourglass:

To show or hide the hourglass, call Hourglass with the hgOn or hgOff constants. Before displaying a message box or a modal form, call Hourglass with hgSave to ensure that the hourglass is off. Afterward, call Hourglass with hgRestore to restore the previous state of the hourglass. For example:

Sub Z()
    Hourglass hgOn
    ' [Long operation begins]
    
    Hourglass hgSave
    MsgBox "Test"
    Hourglass hgRestore
    
    ' [Long operation continues]
    Hourglass hgOff
End Sub

The Hourglass procedure uses a fixed stack size of 10 to store the hourglass states, which should be adequate for most applications. You can, of course, change the upper bound as needed, or perhaps implement the stack as a dynamic array.

See Also

Microsoft Knowledge Base

1