When I enter some text in an edit box using SETCONTROLTEXT, is there any way I can return the caret position to the end of that text?
Wherever I use 'SETFOCUS' this simply puts the caret at the beginning of the text in the control.
Not essential, but would be more elegant. Have searched the sections on edit boxes thoroughly but can't deduce what would help.
:'(
This seems to work (don't ask me why). :D
SetFocus Window,ID
CONTROLCMD Window,ID,@EDSETSELECTION,-2,-2
;D Thanks. That certainly seems to work ok. It's something that has been bugging me for ages, so thanks for a solution.
I see that the @edgetselection gets the current selection of the edit control, but in the manual the variables are 0 and -1, so I'm intrigued by your -2, -2.
Perhaps someone else can explain what's happening here.
Thanks again for your help. Someone out there always has an answer.
@EDSETSELECTION is EM_SETSEL
QuoteThe EM_SETSEL message can be used to place a selected range of text in a Windows edit control. If the starting and ending positions of the range are set to the same position, no selection is made and a caret can be placed at that position.
I'm guessing -2 is treated like ffffffff-2 and since there isn't that much text there it goes to the end of the text.
I say that because if you have a string in the edit control,say, 10 characters long using 8,8 will place the caret after the 8th character.
Larry
Thanks for the thoughts and additional info, Larry.
However, I've found it continues to work, even with a page full of text in an editor (including numerous 'blank' lines or spaces) . so can't be related to the length of the string.
Doesn't seem to make any difference if the variables are -2,-2, or -2,-1, or -3, -3 etc.
However, -1,-2, or -2,0, or -2,1 just means the text is highlighted. Haven't experimented much beyond that.
Where does your quote about EM_SETSEL come from? (I'm assuming this is the Windows equivalent of the EB flag)
Thanks for the help.
;)
Quote from the SDK on EM_SETSEL:
QuoteIf the start is 0 and the end is â€ââ,¬Å"1, all the text in the edit control is selected. If the start is â€ââ,¬Å"1, any current selection is deselected.
Edit controls: The control displays a flashing caret at the end position regardless of the relative values of start and end.
Quote from: AdrianFox on February 23, 2009, 10:11:20 AM
Doesn't seem to make any difference if the variables are -2,-2, or -2,-1, or -3, -3 etc.
My point exactly. If you think of the number as a two's compliment then a negative number is a really large positive number
Quote from: AdrianFox on February 23, 2009, 10:11:20 AM
Where does your quote about EM_SETSEL come from?
Found it on the internet
Quote from: AdrianFox on February 23, 2009, 10:11:20 AM
(I'm assuming this is the Windows equivalent of the EB flag)
Thought that was what I said in my previous post ;)
Quote@EDSETSELECTION is EM_SETSEL
Larry
I know I have posted this before:
'subroutine to easily append text in an edit control.
CONST WM_GETTEXTLENGTH = 0xE
Sub AppendEdit(window win,int id,string text,int addNL)
int _textlen:_textlen =SendMessage(win, WM_GETTEXTLENGTH,0,0,id)
ControlCmd win, id, @EDSETSELECTION, _textlen, _textlen
if(addNL)
ControlCmd win, id, @EDREPLACESEL, text + "\n"
else
ControlCmd win, id, @EDREPLACESEL, text
endif
Endsub
Use WM_GETTEXTLENGTH to retrieve how much text is in the edit box, and then send it @EDSETSELECTION with that value as both of the parameters, and the caret will be moved to the end of text in the control. The subroutine, one that I use a lot, allows easily appending text in the edit control without having to retrieve the existing text first.
Paul.
Thanks for the subroutine Paul.
This gives me a complete solution for the problem.
Best wishes,