Detailed Description

A cursor is a small bitmap usually used for denoting where the mouse pointer is, with a picture that might indicate the interpretation of a mouse click.

As with icons, cursors in X and MS Windows are created in a different manner. Therefore, separate cursors will be created for the different environments. Platform-specific methods for creating a wxCursor object are catered for, and this is an occasion where conditional compilation will probably be required (see wxIcon for an example).

A single cursor object may be used in many windows (any subwindow type). The wxWidgets convention is to set the cursor for a window, as in X, rather than to set it globally as in MS Windows, although a global wxSetCursor() function is also available for MS Windows use.

Creating a Custom Cursor

The following is an example of creating a cursor from 32x32 bitmap data (down_bits) and a mask (down_mask) where 1 is black and 0 is white for the bits, and 1 is opaque and 0 is transparent for the mask. It works on Windows and GTK+.

The arguments hotSpotX and hotSpotY are only used when there's no hotspot info in the resource/image-file to load (e.g. when using wxBITMAP_TYPE_ICO under wxMSW or wxBITMAP_TYPE_XPM under wxGTK).

Parameters

cursorName

The name of the resource or the image file to load.

type

Icon type to load. It defaults to wxCURSOR_DEFAULT_TYPE, which is a #define associated to different values on different platforms:

under Windows, it defaults to wxBITMAP_TYPE_CUR_RESOURCE. Other permitted types under Windows are wxBITMAP_TYPE_CUR (to load a cursor from a .cur cursor file), wxBITMAP_TYPE_ICO (to load a cursor from a .ico icon file) and wxBITMAP_TYPE_ANI (to load a cursor from a .ani icon file).

under MacOS, it defaults to wxBITMAP_TYPE_MACCURSOR_RESOURCE; when specifying a string resource name, first the color cursors 'crsr' and then the black/white cursors 'CURS' in the resource chain are scanned through. Note that resource forks are deprecated on OS X so this is only available for legacy reasons and should not be used in new code.

If cursor are monochrome on the current platform, colors with the RGB elements all greater than 127 will be foreground, colors less than this background. The mask (if any) will be used to specify the transparent area.

In wxMSW the foreground will be white and the background black. If the cursor is larger than 32x32 it is resized.

In wxGTK, colour cursors and alpha channel are supported (starting from GTK+ 2.2). Otherwise the two most frequent colors will be used for foreground and background. In any case, the cursor will be displayed at the size of the image.

Under wxMac (Cocoa), large cursors are supported.

Notice that the image can define the cursor hot spot. To set it you need to use wxImage::SetOption() with wxIMAGE_OPTION_CUR_HOTSPOT_X or wxIMAGE_OPTION_CUR_HOTSPOT_Y, e.g.

A cursor can be reused for more than one window, and does not get destroyed when the window is destroyed. wxWidgets destroys all cursors on application exit, although it is best to clean them up explicitly.