Hide and show the mouse cursor

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 mouseShowCursor False' do whatever you need to do' ....' make the cursor visible againShowCursor 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 SubSub RoutineTwo()    ShowCursor False    '    ' do something else    '    ' this does NOT make the cursor visible    ShowCursor True   End Sub


Share the Post: