devxlogo

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

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.