|
|
Title | Manage hourglass cursors |
Description | This example shows how to manage hourglass cursors in Visual Basic 6. It keeps track of the number of routines that have displayed the cursor but have not yet ended. |
Keywords | cursor, hourglass, wait |
Categories | Graphics, Software Engineering |
|
|
Thanks to Chimeric.
When many routines call each other, it can be hard to keep track of the mouse pointer so it remains an hourglass until all operations have finished. Use a static counter to keep track of the number of routines that have started a wait but not yet ended it.
|
|
' Add or subtract one from wait_counter. If
' wait_counter = 0, display the default cursor.
' Otherwise display the hourglass cursor.
Private Sub Hourglass(ByVal start_wait As Boolean)
Static wait_counter As Integer
Dim was_hourglass As Boolean
Dim now_hourglass As Boolean
' Record the current cursor state.
was_hourglass = (wait_counter > 0)
' Update start_wait.
If start_wait Then
wait_counter = wait_counter + 1
Else
wait_counter = wait_counter - 1
End If
If wait_counter < 0 Then wait_counter = 0
' See if the cursor's status has changed.
' We only set it if it has. Otherwise
' repeatedly resetting the cursor with the
' same value will make it flicker.
now_hourglass = (wait_counter > 0)
If now_hourglass <> was_hourglass Then
If wait_counter = 0 Then
MousePointer = vbDefault
Else
MousePointer = vbHourglass
End If
End If
' Update the wait counter display.
' Remove this in a real application.
lblWaits = wait_counter
End Sub
|
|
|
|
|
|