Author |
Topic: Caret in Editbox (Read 1172 times) |
|
nitwit
Guest
|
 |
Caret in Editbox
« Thread started 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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Caret in Editbox
« Reply #1 on: Apr 23rd, 2010, 08:27am » |
|
on Apr 22nd, 2010, 2:51pm, Guest-nitwit wrote: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. |
|
Call PROC_setfocus() in WINLIB5 (or WINLIB5A):
http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#setfocus
Richard.
|
|
Logged
|
|
|
|
nitwit
Guest
|
 |
Re: Caret in Editbox
« Reply #2 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?
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Caret in Editbox
« Reply #3 on: Apr 23rd, 2010, 10:26pm » |
|
on Apr 23rd, 2010, 6:24pm, Guest-nitwit wrote:It does also work on editbox handles. |
|
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.
|
|
Logged
|
|
|
|
nitwit
Guest
|
 |
Re: Caret in Editbox
« Reply #4 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!).
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Caret in Editbox
« Reply #5 on: Apr 25th, 2010, 09:41am » |
|
on Apr 25th, 2010, 09:28am, Guest-nitwit wrote:"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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Caret in Editbox
« Reply #6 on: Apr 26th, 2010, 08:30am » |
|
on Apr 25th, 2010, 09:41am, Richard Russell wrote: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:
http://bb4w.wikispaces.com/Finding+which+window+has+input+focus
Richard.
|
|
Logged
|
|
|
|
|