Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Offset in Edit control
Hi Gintaras,
I would like to get the offset of a cursor click within a text box. I thought of this:

Copy      Help
out _s.len

but was wondering if there was any more elegant way of doing it (i.e. not having to handle the onscreen select de-select steps, etc)

I looked into GetCaretXY but this is the x,y insted of offset.

Send message EM_GETSEL.
Thanks, that works perfect!
Now I am trying to take it to the next level. Rather than confirming that I am within an offset range (of a certain text str) by getting the cursorpos (after a left click or arrow navigation)

Copy      Help
int i; ARRAY(CHARRANGE) arrSearch
if(findrx(WholeText Searchstr 0 1 arrSearch)<0) out "does not match"; ret
for i 0 arrDitselInsert.len
,int offsetmin(arrSearch[i].cpMin) length(arrSearch[i].cpMax-arrSearch[i].cpMin) offsetmax(arrSearch[i].cpMax)

Copy      Help
int cursorPos; SendMessage(c EM_GETSEL 0 &cursorPos)
if cursorPos >= offsetmin and cursorPos <= offsetmax

, I would like to determine this merely on hover-over. I think this may be impossible but is it possible to get the cursorpos (offset) of where the mouse cursor (not the text control cursor) is hovering (x,y) WITHOUT giving a lef click to the edit control?

It is easy to do if I put a lef command into my rep loop, but that obviously messes up the user experience.
This may be impossible or too difficult given that the text size may change in a rich edit by ctrl-mousewheel and other interactions, but just thought I would check.

Are there other ways to see if you are hovered over a certain text string in an edit control?

Thanks, this seems like it will be perfect. When I try though, I get a number returned but same number no matter what the x,y coordinates are. It must be my syntax. I first tried with POINT p, but then check on MSDN and they say POINTL. I tried with both. No difference:

cid is from RichEdit control

Copy      Help
POINT p; xm(p cid) ;;get mouse position into p.x and p.y
int cursorPos = SendMessage(cid EM_CHARFROMPOS 0 &p)
out cursorPos

p.x = xm
p.y = ym
int cursorPos = SendMessage(cid EM_CHARFROMPOS 0 &p)
out cursorPos

Any thoughts? I think I am close!
Thanks so much,
Here works. Don't know, maybe the message does not work with controls in other processes. Of course should not work, need to store the POINT variable in shared memory. Or it is not an edit or rich edit control.
Function Dialog143
Copy      Help
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str rea3
;sel message
,;case WM_COMMAND goto messages2

if(!ShowDialog("Dialog143" &Dialog143 &controls)) ret

;1 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 RichEdit20A 0x54233044 0x200 0 0 224 52 ""
;DIALOG EDITOR: "" 0x2040001 "" "" "" ""

sel message
,SetTimer hDlg 1 500 0
,case WM_TIMER
,sel wParam
,,case 1
,,int cid=id(3 hDlg)
,,POINT p; xm(p cid 1) ;;get mouse position into p.x and p.y
,,int cursorPos = SendMessage(cid EM_CHARFROMPOS 0 &p)
,,out cursorPos
,case WM_COMMAND goto messages2
sel wParam
,case IDOK
ret 1
Thanks Gintaras. The QM dialog sample worked but if I try it with WordPad or other program. It either crashes wordpad or gives same name in other software's RichEdit field.
What is the issue you mentioned with shared memory. How would I set this up?
Use __ProcessMemory class, allocate memory in that process, copy the POINT variable to the memory and pass its address as lParam.
works great!
Even in exe which I thought it would not work in!,

Forum Jump:

Users browsing this thread: 1 Guest(s)