So far I'm sceptical about using carets in Visual FoxPro.
The caret needs a window handle. FoxPro controls are not windows, they have no window handles attached.
Your code uses a window handle obtained through
GetFocus function -- this is active form, not active control. Anyway this is the most appropriate handle that can be used.
I'm afraid that behind
GotFocus and
LostFocus events either for FoxPro controls or for the Form itself there is something that automatically resets a caret to its default state.
Nonetheless I will test this code.
So far check this link:
http://www.mentalis.org/tips/tip056.shtmlA VB sample explaining using carets, on a great VB site AllApi Network.
The code is pretty straightforward, just "translate" it into FoxPro.