Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleManage hourglass cursors
DescriptionThis 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.
Keywordscursor, hourglass, wait
CategoriesGraphics, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated