Using Alternate Cursors

The statements that you use to specify a cursor in your resource script and to obtain a handle to a cursor in your program are very similar to the icon statements shown above:

Resource script: mycursor CURSOR cursfile.cur
Program source: hCursor = LoadCursor (hInstance, "mycursor") ;

The other methods shown for icons (using ID numbers and MAKEINTRESOURCE) work with cursors also. WINDOWS.H includes a typedef definition for HCURSOR that you can use for storing the cursor handle. (Both HICON and HCURSOR are defined as HANDLE.)

You can use the cursor handle obtained from LoadCursor when setting the hCursor member of the window class structure:

wndclass.hCursor = LoadCursor (hInstance, "mycursor") ;

This causes the mouse cursor to be displayed as your customized cursor when the mouse is within the client area of your window.

If you use child windows, you may want the cursor to appear differently, depending on the child window below the cursor. If your program defines the window class for these child windows, you can use different cursors for each class by appropriately setting the hCursor field in each window class. And if you use predefined child window controls, you can alter the hCursor field of the window class using:

SetClassWord (hwndChild, GCW_HCURSOR,

LoadCursor (hInstance, "childcursor") ;

If you separate your client area into smaller logical areas without using child windows, you can use SetCursor to change the mouse cursor:

SetCursor (hCursor) ;

You should call SetCursor during processing of the WM_MOUSEMOVE message. Otherwise, Windows uses the cursor specified in the window class to redraw the cursor when it is moved.

RESOURC1 uses the name of the program for the name of the cursor:

resourc1 CURSOR resourc1.cur

When RESOURC1.C defines the window class, this szAppName variable is used for LoadCursor:

wndclass.hCursor = LoadCursor (hInstance, szAppName) ;