Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: beginner
Dec 30, 2000

Hide and show the mouse cursor

At times you may want to temporarily hide the mouse cursor, for example in order to reduce flickering. To do so you just need the ShowCursor API function:

Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long

' hide the mouse
ShowCursor False

' do whatever you need to do
' ....

' make the cursor visible again
ShowCursor True
Keep in mind that if you call the ShowCursor function more than once passing False as an argument, then you must call ShowCursor with True an equal number of times, otherwise the cursor will remain invisible. This behavior, while not intuitive, permits to call nested procedures - each one that hides and then restores the mouse cursor - and have the mouse cursor reappear only when the last procedure terminates its execution:

Sub RoutineOne()
    ShowCursor False
    Call RoutineTwo
    ' this makes the cursor visible again
    ShowCursor True   
End Sub

Sub RoutineTwo()
    ShowCursor False
    '
    ' do something else
    '
    ' this does NOT make the cursor visible
    ShowCursor True   
End Sub

Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap