How To Create a Nonblinking Caret (74607)



The information in this article applies to:

  • Microsoft Platform Software Development Kit (SDK) 1.0
  • Microsoft Windows Software Development Kit (SDK) 3.0
  • Microsoft Windows Software Development Kit (SDK) 3.1

This article was previously published under Q74607

SUMMARY

The Microsoft Windows graphical environment is designed to provide a blinking caret. However, using a timer and the SetCaretBlinkTime() function, an application can "trick" the caret into not blinking.

Applications should not arbitrarily change the caret blink time and respect the setting that the user has chosen.

If you change the blink time, subsequently activated applications will use the modified blink time, even if you restore the previous blink time when you lose the keyboard focus or become inactive. This is due to the multithreaded environment, where deactivation of your application is not synchronized with the activation of another application. This feature allows the system to activate another application even if the current application is hung.

MORE INFORMATION

Although Windows is designed to blink the caret at a specified interval, a timer function and SetCaretBlinkTime() can be used to prevent Windows from turning the caret off by following these three steps:
  1. Call SetCaretBlinkTime(10000), which instructs Windows to blink the caret every 10,000 milliseconds (10 seconds). This results in a "round-trip" time of 20 seconds to go from OFF to ON and back to OFF (or vice versa).
  2. Create a timer, using SetTimer(), specifying a timer procedure and a 5,000 millisecond interval between timer ticks.
  3. In the timer procedure, call SetCaretBlinkTime(10000). This resets the timer in Windows that controls the caret blink.
When an application implements this procedure, Windows never removes the caret from the screen, and the caret does not blink.

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbCaret kbhowto KB74607