VB:Tutorials:WINAPI:Hiding and Displaying the Mouse Cursor

From GPWiki
Jump to: navigation, search

Pesky, isn't it? I hate that little cursor sometimes, and now I'm armed and ready to kill it. The scourge of mice everywhere, the bane of the arrow, it's the ShowCursor function!

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

This tutorial is not for the faint of heart, or the verbose... this promises to be quite short. There are only two things you need to know about this API call, how to hide the cursor, and how to show the cursor. Notice I said "hide" not destroy. The ability to click is still there, even though we remove the cursor, there is simply no longer a graphical representation.

To remove the cursor, pass 0 (that's a zero not the letter 'o') as the bShow argument. To replace the cursor, pass 1 as the bShow argument, that's it! Here's an example in case you're a slow learner :)

ShowCursor 0

That would remove the cursor! How quaint. Anyway, I have written a small program that toggles the cursor on and off, so download it if you're still confused.