Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
EM_EXSETSEL, selecting string in rich-edit control
#1
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
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;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 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040601 "*" "" "" ""

str controls = "5 3"
str e5 re3
re3=
;111
;33ABC
;100
;120
;1ABCaa
;1400
e5="ABC"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,,ARRAY(int) cmin cmax
,,str to_find
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,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)
,,out
,,for _i 0 cmin.len
,,,out cmin[_i]
,,,out cmax[_i]
,,,out "---"

,,CHARRANGE cr
,,cr.cpMin=cmin[0]
,,cr.cpMax=cmax[0]
,,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)
,if((_i>=0))        
,,x=findl(txt ln)        
,,cmin[]=x+_i
,,cmax[]=x+_i+to_find.len
,ln=ln+1
#2
Easiest workaround - replace \r\n with \n before getpos.

        _s.findreplace("[13]")
#3
THANK YOU!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)