BBC BASIC for Windows
Programming >> User Interface >> Caret in Editbox http://bb4w.conforums.com/index.cgi?board=ui&action=display&num=1271947903 Caret in Editbox
Post by nitwit on Apr 22nd, 2010, 2:51pm
How do I get the caret automatically into an editbox ie not using a mouse click? The editbox is in the main window but not in a dialogue box.
Re: Caret in Editbox
Post by admin on Apr 23rd, 2010, 08:27am
Richard.
Re: Caret in Editbox
Post by nitwit on Apr 23rd, 2010, 6:24pm
Yes, I read about PROC_setfocus() on page 875 of the PDF version of the manual but it just mentions window handles! Brain not geared to lateral thinking. It does also work on editbox handles. Thanks.
Next question - I want to move the caret to another editbox using the up/down cursor control keys but presumably need to know which editbox (handle) the caret is in. How do I find that out?
Re: Caret in Editbox
Post by admin on Apr 23rd, 2010, 10:26pm
Edit box handles (and all other control handles) are window handles!
Quote:
Next question - I want to move the caret to another editbox using the up/down cursor control keys but presumably need to know which editbox (handle) the caret is in. How do I find that out?
Not very easy. The only way that immediately comes to mind is to use ON SYS to monitor messages sent by the various edit boxes and record the received @lparam% value, which should be the handle of whichever control sent the message. Thus the control containing the caret ought to be the one which most recently sent a message.
Within a dialogue box, keyboard 'navigation' between controls is done for you automatically. Could you perhaps use a 'docked' dialogue box instead of your current approach and take advantage of this feature?
Richard.
Re: Caret in Editbox
Post by nitwit on Apr 25th, 2010, 09:28am
"I don't believe it" - The mighty Microsoft OS does not have a simple SYS call to give you the caret position. Hopeless!
I will look at the dialogue box solution for my next program but for now I have solved the problem as long as I don't click the mouse in different editbox (which I don't want to anyway!).
Re: Caret in Editbox
Post by admin on Apr 25th, 2010, 09:41am
"I don't believe it" - The mighty Microsoft OS does not have a simple SYS call to give you the caret position. Hopeless!
There is an API - GetFocus() - but it has to be used from the same thread that contains the Message Queue. That means you cannot call it as a straightforward SYS from BB4W.
If you look at the code for PROC_setfocus in WINLIB5 you will see the hoops that have to be jumped through to make the SetFocus() API work (which has the same restriction). It would be possible to adapt that code to make an FN_getfocus function, but I didn't suggest that approach because it involves assembler code.
Richard.
Re: Caret in Editbox
Post by admin on Apr 26th, 2010, 08:30am
There is an API - GetFocus() - but it has to be used from the same thread that contains the Message Queue. That means you cannot call it as a straightforward SYS from BB4W.
I have listed a routine which works (and doesn't use assembler code) here: