Anyone know of a way how to put the caret in an Edit control to the start of a selection?
Or how to select text in an Edit control with the caret being at the start of the selection afterwards?
The problem is that with EM_SETSEL (Message to Edit Control) it puts the caret always at the end of the selection but not at the start, not matter how you submit the parameters.
It seems to me that, when a selection exists, it maybe could work with EM_POSFROMCHAR (Message to Edit Control) and DllCall("User32.dll\SetCaretPos", "Int", X, "Int", Y)??
I tried the following:
Code: Select all
Edit_PosFromChar(hEdit,p_CharPos,ByRef X,ByRef Y) ;I found this function in one of the ahk forums
{
Static EM_POSFROMCHAR:=0xD6
SendMessage EM_POSFROMCHAR,p_CharPos,0,,ahk_id %hEdit%
X:=(ErrorLevel & 0xFFFF)<<48>>48
;-- LOWORD of result and converted from UShort to Short
Y:=(ErrorLevel>>16)<<48>>48
;-- HIWORD of result and converted from UShort to Short
}
indexOfTargetChar := 3 ;its only some number for testing, supposedly zero-based
Edit_PosFromChar(HEDIT, indexOfTargetChar, X, Y) ;HEDIT is the handle to the Edit control
VarSetCapacity(iX, 4, 0)
VarSetCapacity(iY, 4, 0)
NumPut(X, iX, 0, "Int")
NumPut(Y, iY, 0, "Int")
DllCall("User32.dll\SetCaretPos", "Int", iX, "Int", iY)
If I call SetCaretPos as DllCall("User32.dll\SetCaretPos", "Int", &iX, "Int", &iY) (note the &) then the caret changes to not visible at all. Subsequent manual selection behaves the same as described, though.
Does anybody know of a solution? Thx!