How to Create and Display a Caret on the Window

2 01 2009




The CreateCaret Win32 API function creates a new shape for the system caret and assigns ownership of the caret to the specified window. The caret shape can be a line, a block, or a bitmap. Also it is using some other API functions such as SetCaretPos, ShowCaret and HideCaret. Then the caret blink time could adjust by the functions GetCaretBlinkTime and SetCaretBlinkTime.




void CreateSolidBlackCaret()
   // window handle
   HWND hwnd,      
   // width of cursor
   int nWidth = 100;     
   // height of cursor
   int nHeight = 100;
   // horizontal coordinate of cursor
   int x       = 10;          
   // vertical coordinate of cursor
   int y       = 10;           

   //Create a solid black caret.
   //Adjust the caret position
   //Display the caret

void HideMyCaret()

void AdjustCaretBlinkTime()
   UINT n = GetCaretBlinkTime();
   SetCaretBlinkTime(n -/+ 100);




The system provides one caret per queue. A window should create a caret only when it has the keyboard focus or is active. The window should destroy the caret before losing the keyboard focus or becoming inactive.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: