Recent

Author Topic: Caret stops blinking after a few seconds  (Read 3778 times)

Dr.Theopolis

  • Jr. Member
  • **
  • Posts: 69
Caret stops blinking after a few seconds
« on: June 21, 2018, 04:53:04 pm »
Update: Turns out my issue may not have anything to do with Lazarus. The caret stops blinking in Notepad and Wordpad too.


I've been taking a look at the KMemo component, and it does something a little weird that I've been trying to fix. When the memo component has focus, the caret blinks for about 5 or 6 seconds, and then it stops blinking. The control still has focus at that time. If the control loses focus and then regains it, the caret starts blinking again for a few seconds and stops.

So I was just curious - What drives a caret to blink in a Windows application? Why do you suppose it would stop blinking?
 
« Last Edit: June 23, 2018, 06:06:04 pm by Dr.Theopolis »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5631
    • wiki
Re: Caret stops blinking after a few seconds
« Reply #1 on: June 21, 2018, 07:37:20 pm »
On Windows it depends.

Is it a self drawn caret, or is it the system caret?
An indicator may be, if you change the blink rate in the system setting, will the caret be affected (even if you do, while the app is already running)

If the app draws it's own caret.... Well, I don't know.

Normally on windows, a memo component calls SetCaret or ShowCaret, from the win api. (search the code)
And then windows draws the caret and makes it blink.

This normally works well. But windows only supports ONE caret per application (across all windows of the app). So if there is a 2nd memo, that wants the caret, then the first one will loose it.

Dr.Theopolis

  • Jr. Member
  • **
  • Posts: 69
Re: Caret stops blinking after a few seconds
« Reply #2 on: June 22, 2018, 02:03:10 am »
In the KMemo control, the caret is created using CreateCaret in winapih.inc.

Using LazLogger, I examined when the memo component gets and loses focus. When I run the app and just watch, the memo gets focus and never loses it, but the caret stops blinking as I have mentioned.

I read on Microsoft's website that the caret will continue blinking if the app has a message pump. So for troubleshooting purposes, I set up a timer that calls application.ProcessMessages and this had no effect. So next I had the timer do a PostMessage sending a LM_SETFOCUS message to the memo component every 5 seconds. Still, my logger says the memo never loses focus, but sending that message keeps the caret blinking.

In 20+ years of writing windows applications, I have never had to do something that silly to solve such a minor problem.

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Caret stops blinking after a few seconds
« Reply #3 on: June 22, 2018, 06:49:41 am »
Why do you suppose it would stop blinking?

My guess: full message queue.

Windows, internally, uses an undocumented message (WM_SYSTIMER $0118) to blink the caret beside other functions. If the queue is full, no more blinking messages are received.

If my guess is right, your application is not a simple kMemo test program.

josh

  • Hero Member
  • *****
  • Posts: 754
Re: Caret stops blinking after a few seconds
« Reply #4 on: June 22, 2018, 09:47:59 am »
hi

confirmed new project, place just kmemo, run it cursor blinks for 5/6 seconds then stops.. if you type into the kmemo then it blinks; stop typing then 5/6 seconds later it stops blinking.

When kmemo is placed on form the kmemo caption says that it is alpha version, so maybe a known issue; have you posted on kmemo website?
http://www.tkweb.eu/en/delphicomp/

ps minimizing an restoring the test projects; re-starts the caret for 5/6 seconds.
« Last Edit: June 22, 2018, 01:02:48 pm by josh »
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Caret stops blinking after a few seconds
« Reply #5 on: June 23, 2018, 04:44:15 pm »
Just downloaded tkweb-kcontrols. Compiled laz package without installing it. Tried the following code:
Code: Pascal  [Select]
  1.   m := TKMemo.Create(Self);
  2.   m.SetBounds(10,10,200, 150);
  3.   m.Parent := Self;
  4.   m.Visible:=True;

Did not see the caret problem. Possibly solved?


Dr.Theopolis

  • Jr. Member
  • **
  • Posts: 69
Re: Caret stops blinking after a few seconds
« Reply #6 on: June 23, 2018, 05:50:14 pm »
The issue might not have anything to do with TKMemo component. I am looking into it and will probably start a new topic if I have questions.