Explicitly Setting the Cursor Shape

Your application does not have to specify a class cursor. Instead, you can set the hCursor field to NULL to indicate that the window class has no class cursor. If a window has no class cursor, Windows will not automatically change the shape of the cursor when it moves into the client area of the window. This means that your application will need to display the cursor itself.

To use any cursor, whether built-in or custom, you must load it first. For example, to load the custom cursor MyCursor (defined in your application's resource script file) add the following statements to your initialization function:

static HCURSOR hMyCursor; /* static variable */

hMyCursor = LoadCursor (hInstance, (LPSTR) “MyCursor”);

Summary: The SetCursor function changes the cursor's shape.

Then, to change the cursor shape, use the SetCursor function to set the shape each time the cursor moves in the client area. Since Windows sends a WM_MOUSEMOVE message to the window on each cursor movement, you can manage the cursor by adding the following statements to the window function:

case WM_MOUSEMOVE:

SetCursor(hMyCursor);

break;

NOTE:

If your application needs to display the cursor itself, you must set the class-cursor field to NULL. Otherwise, Windows will attempt to set the cursor shape on each WM_MOUSEMOVE message, even though your application is also setting the cursor shape. This will result in a noticeable flicker as you move the cursor through the window.