User Tools

Site Tools


Using non-standard mouse pointers

by Richard Russell, October 2007

You can select the mouse pointer (cursor) from any of the standard shapes using the MOUSE ON statement. However there may be occasions when you want to use a pointer that is not one of the standard shapes. This is most straightforwardly achieved by loading the pointer shape from a cursor (.CUR) file.

For example suppose you want to use the 'closed hand' shape in the file HMOVE.CUR. Firstly you must load the file and obtain a handle to the cursor:

        IMAGE_CURSOR = 2
        LR_LOADFROMFILE = 16
        cursor$ = "C:\Windows\Cursors\HMOVE.CUR"
        SYS "LoadImage", 0, cursor$, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE TO hHand%

Note that the 2 signifies that the file contains a cursor image.

Having obtained the handle (in this case hHand%) you can use it to set the mouse pointer to this shape as follows:

        WM_MOUSEMOVE = 512
        @hcsr% = hHand%
        SYS "SendMessage", @hwnd%, WM_MOUSEMOVE, 0, 0

The SendMessage is simply to force the cursor to change immediately, rather than when the mouse is next moved. Depending on how your program works, it may not be essential.

You must be careful to load the file only once, to avoid a resource leak. Once you have obtained a handle to the cursor you can use it to change the pointer shape whenever you like in your program, without needing to load the file again.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
using_20non-standard_20mouse_20pointers.txt · Last modified: 2018/04/16 15:38 by richardrussell