void CreateCaret(hwnd, hbmp, nWidth, nHeight) | |||||
HWND hwnd; | /* handle of owner window | */ | |||
HBITMAP hbmp; | /* handle of bitmap for caret shape | */ | |||
int nWidth; | /* caret width | */ | |||
int nHeight; | /* caret height, */ |
The CreateCaret function creates a new shape for the system caret and assigns ownership of the caret to the given window. The caret shape can be a line, block, or bitmap.
hwnd
Identifies the window that owns the new caret.
hbmp
Identifies the bitmap that defines the caret shape. If this parameter is NULL, the caret is solid; if the parameter is 1, the caret is gray.
nWidth
Specifies the width of the caret in logical units. If this parameter is NULL, the width is set to the system-defined window-border width.
nHeight
Specifies the height of the caret, in logical units. If this parameter is NULL, the height is set to the system-defined window-border height.
This function does not return a value.
If the hbmp parameter contains a bitmap handle, the nWidth and nHeight parameters are ignored; the bitmap defines its own width and height. (The bitmap handle must have been created by using the CreateBitmap, CreateDIBitmap, or LoadBitmap function.) If hbmp is NULL or 1, nWidth and nHeight give the caret's width and height, in logical units; the exact width and height (in pixels) depend on the window's mapping mode.
The CreateCaret function automatically destroys the previous caret shape, if any, regardless of which window owns the caret. Once created, the caret is initially hidden. To show the caret, use the ShowCaret function.
The system caret is a shared resource. A window should create a caret only when it has the input focus or is active. It should destroy the caret before losing the input focus or becoming inactive.
The system's window-border width or height can be retrieved by using the GetSystemMetrics function, specifying the SM_CXBORDER and SM_CYBORDER indices. Using the window-border width or height guarantees that the caret will be visible on a high-resolution screen.
The following example creates a caret, sets its initial position, and then displays the caret:
case WM_SETFOCUS:
CreateCaret(hwndParent, NULL, CARET_WIDTH, CARET_HEIGHT);
SetCaretPos(CARET_XPOS, CARET_YPOS);
ShowCaret(hwndParent);
break;
CreateBitmap, CreateDIBitmap, DestroyCaret, GetSystemMetrics, LoadBitmap, ShowCaret