Code Archive - Cursors - Hide the Cursor

With certain programs, mostly full-screen games, it becomes neccessary to hide the system cursor. Unfortuantly, Visual Basic does not offer any built-in way, like with most things, to do this automatically. There are two different methods that can be used, either by API, or using a custom cursor.

Note: In both cases, this does not disable the cursor, it only hides it, meaning that the user will still be able to click around on the screen, but with some trouble.

Method #1 - APIs

Showing or hiding the cursor can be achieved using the ShowCursor API call. It's declaration is:

Declare Function ShowCursor Lib "User32" (ByVal bShow As Long) As Long

This API call is very easy to use. Just call it with the value Falsein the bShow argument, and True to show it again.

It should be noted that the system keeps an internal count, so if you call ShowCursor twice to hide the cursor, you will need to call ShowCursor again to show it. The function returns the value of this count. If the counter is 0 or greater, then the cursor is visible, else it isn't. To correctly hide or show the cursor, you should use a loop to check for the required value from the function.

WARNING: If you fail to show the cursor when your application terminates, the cursor will remain invisible. The only action the end-user could do would be to restart your system.

Method #2 - Custom Cursor

The first step of this method is to create a totally blank cursor, one that will not display a single pixel. You can either make your own, or use the one I have created by downloading it here. Then, assign the cursor like you would any other custom cursor to a form or control. With this method, the cursor will only hide when over your application, but you do not need to worry about cleaning up after yourself. This is my perferred method for full-screen games.