CreateCaret

Syntax

void CreateCaret(hWnd,hBitmap,nWidth,nHeight)

This 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 as defined by the hBitmap parameter. If hBitmap is a bitmap handle, the nWidth and nHeight parameters are ignored; the bitmap defines its own width and height. (The bitmap handle must have been previously created by using the CreateBitmap, CreateDIBitmap, or LoadBitmap function.) If hBitmap 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.

If nWidth or nHeight is zero, the caret width or height is set to the system's window-border width or height. Using the window-border width or height guarantees that the caret will be visible on a high-resolution display.

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, the ShowCaret function must be called.

Parameter Type/Description  

hWnd HWND Identifies the window that owns the new caret.  
hBitmap HBITMAP Identifies the bitmap that defines the caret shape. If hBitmap is NULL, the caret is solid; if hBitmap is 1, the caret is gray.  
nWidth int Specifies the width of the caret (in logical units).  
nHeight int Specifies the height of the caret (in logical units).  

Return Value

None.

Comments

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 with the SM_CXBORDER and SM_CYBORDER indexes.