Position cursor within textbox

Discussions about the Liberty BASIC language, with particular reference to LB Booster
Dermot
Posts: 4
Joined: Thu Apr 19, 2018 1:24 pm

Position cursor within textbox

Post by Dermot »

I wish to be able to display text in a textbox, and then position the cursor at the end of the that text, so that any further text entered by the user would then be added at the end.
Dermot
Posts: 4
Joined: Thu Apr 19, 2018 1:24 pm

Re: Position cursor within textbox

Post by Dermot »

I should have added that I have no problem with the display aspect, as I have been using LBB for years, and have developed a number of commercial programs. It is merely the cursor placement I am interested in, analagous to the texteditor command - print #handle, "!select column row" ;
I am not aware of such a command for a textbox
guest
Site Admin
Posts: 192
Joined: Tue Apr 03, 2018 1:34 pm

Re: Position cursor within textbox

Post by guest »

Dermot wrote: Wed Aug 07, 2019 1:20 pm I wish to be able to display text in a textbox, and then position the cursor at the end of the that text, so that any further text entered by the user would then be added at the end.
I'm sure it's quite straightforward using an API call (EM_SETSEL is the message you need), and somewhere I've got the code to do it. Unfortunately I'm bogged down with other things at the moment and cannot instantly find it.
sarmednafi
Posts: 36
Joined: Fri Apr 06, 2018 6:27 am

Re: Position cursor within textbox

Post by sarmednafi »

Richard,

Thank you, Here is the code,

Code: Select all


'Place text in textbox and locate
'caret at end of text.

nomainwin
textbox #1.t, 10,10,100,124
Open "Type" for window as #1
#1 "trapclose [quit]"
#1.t "!setfocus"
#1.t "Hello World"

startpos=len("Hello World")
endpos=startpos

hText=hwnd(#1.t)
calldll #user32, "SendMessageA",_
hText as ulong,_EM_SETSEL as long,_
startpos as long, endpos as long,_
re as long

wait

[quit] close #1:end

Regards
Dermot
Posts: 4
Joined: Thu Apr 19, 2018 1:24 pm

Re: Position cursor within textbox

Post by Dermot »

To Sarmednafi

Thanks very much
That works great

Regards

Dermot