CreateCaret

  BOOL 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.

Parameters

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 this 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.

Return Value

The return value is TRUE if the function was successful, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information.

Comments

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

The system caret is a shared resource. A window should create a caret only when it has the keyboard focus or is active. It should destroy the caret before losing the keyboard 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 display.

See Also

CreateBitmap, CreateDIBitmap, DestroyCaret, GetSystemMetrics, LoadBitmap, ShowCaret