Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
EM_EXSETSEL, selecting string in rich-edit control
I can not get the selection correct.

In the below script I collect all the occurring first and last character positions (cmin[] and cmax[]) of a substring I am trying to find.
Example below, I collect all the first and last positions of all occurring "ABC" and store the positions in 'cmin' and 'cmax'.

The moment I want to select it in the textfield using cmin and cmax, there seems to be an offset.
Press the "get" button and you see that the first occurence of "ABC" is not correctly selected.
(Do I need to take into account that the "[]" counts as 1 char?)

To be clear when the "get" button is pressed I try to focus on the FIRST occurrence (cmin[0] and cmax[0])

Function getcharpos_dlg
Copy      Help
str dd=
;0 "" 0x90C80AC8 0x0 0 0 168 103 "Dialog"
;4 Button 0x54032000 0x0 9 83 48 14 "get"
;5 Edit 0x54030080 0x200 65 83 96 12 ""
;3 RichEdit20A 0x54233044 0x200 1 2 162 77 ""
;DIALOG EDITOR: "" 0x2040601 "*" "" "" ""

str controls = "5 3"
str e5 re3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,,ARRAY(int) cmin cmax
,,str to_find
,case WM_COMMAND goto messages2
sel wParam
,case IDOK
,case 4
,,act id(3 hDlg)
,,_s.getwintext(id(3 hDlg))
,,to_find.getwintext(id(5 hDlg))
,,sub.getpos(hDlg _s to_find cmin cmax)
,,for _i 0 cmin.len
,,,out cmin[_i]
,,,out cmax[_i]
,,,out "---"

,,SendMessage(id(3 hDlg) EM_EXSETSEL 0 &cr)

ret 1


#sub getpos
function int'hDlg str'txt str'to_find ARRAY(int)&cmin ARRAY(int)&cmax

;; This subfunction 'getpos' fills the 2 arrays cmin and cmax

int x
int ln
foreach _s txt
,_i=find(_s to_find)
,,x=findl(txt ln)        
Easiest workaround - replace \r\n with \n before getpos.


Forum Jump:

Users browsing this thread: 1 Guest(s)