Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Edit box replacement in real time
#1
Hi,

In the following dialog box, I want to achieve the effect of replacing text in real time

Please look at the image below, when I enter text in the edit box on the right, the content in the edit box on the left is also replaced,  in real time

Also how to change the color of the border line of the edit box, such as the blue blue-headed arrow below

Thanks in advance for any advice and help
david


   

Macro Macro2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 392 192 "Dialog" "4"
;4 Edit 0x54030080 0x200 280 8 104 12 ""
;5 Edit 0x54030080 0x204 280 28 104 13 ""
;3 Edit 0x54231044 0x200 8 8 264 176 ""
;1 Button 0x54030001 0x4 280 171 48 14 "OK"
;2 Button 0x54030000 0x4 336 171 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "4 5 3"
str e4 e5 e3
e3=
;My name is ┆name┆, my age is ┆age┆,  thank you!

if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SendMessage id(4 hDlg) EM_SETCUEBANNER TRUE @"┆name┆"
,SendMessage id(5 hDlg) EM_SETCUEBANNER TRUE @"┆age┆"
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
from the picture it looks as if you want to leave the ┆ in place
if so use this
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 392 192 "Dialog" "4"
;4 Edit 0x54030080 0x200 280 8 104 12 ""
;5 Edit 0x54030080 0x204 280 28 104 13 ""
;3 Edit 0x54231044 0x200 8 8 264 176 ""
;1 Button 0x54030001 0x4 280 171 48 14 "OK"
;2 Button 0x54030000 0x4 336 171 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "4 5 3"
str e4 e5 e3
e3=
;My name is ┆name┆, my age is ┆age┆,  thank you!

if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc v;; must have v attribute
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SendMessage id(4 hDlg) EM_SETCUEBANNER TRUE @"┆name┆"
,SendMessage id(5 hDlg) EM_SETCUEBANNER TRUE @"┆age┆"
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case [EN_CHANGE<<16|4,EN_CHANGE<<16|5]
,DT_GetControls(hDlg)
,if(empty(e4))
,,e4="name"
,if(empty(e5))
,,e5="age"
,_s=F" My name is ┆{e4}┆, my age is ┆{e5}┆,  thank you!"
,DT_SetControl(hDlg 3 _s)

ret 1

If you want to remove the ┆ completely, then do this
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 392 192 "Dialog" "4"
;4 Edit 0x54030080 0x200 280 8 104 12 ""
;5 Edit 0x54030080 0x204 280 28 104 13 ""
;3 Edit 0x54231044 0x200 8 8 264 176 ""
;1 Button 0x54030001 0x4 280 171 48 14 "OK"
;2 Button 0x54030000 0x4 336 171 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "4 5 3"
str e4 e5 e3
e3=
;My name is ┆name┆, my age is ┆age┆,  thank you!

if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc v;; must have v attribute
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SendMessage id(4 hDlg) EM_SETCUEBANNER TRUE @"┆name┆"
,SendMessage id(5 hDlg) EM_SETCUEBANNER TRUE @"┆age┆"
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case [EN_CHANGE<<16|4,EN_CHANGE<<16|5]
,DT_GetControls(hDlg)
,if(empty(e4))
,,e4="┆name┆"
,if(empty(e5))
,,e5="┆age┆"
,_s=F" My name is {e4}, my age is {e5},  thank you!"    
,DT_SetControl(hDlg 3 _s)

ret 1
#3
Thanks for your help, 

My description is not detailed enough,The second code above is closer to my idea

I want to replace the two fields (┆name┆ and ┆age┆) If they exist, in the E3 edit box in real time, The E3 edit box content inside is constantly changing, Not fixed
#4
This should be a good starting point
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 392 192 "Dialog" "4"
;4 Edit 0x54030080 0x200 280 8 104 12 ""
;5 Edit 0x54030080 0x204 280 28 104 13 ""
;3 Edit 0x54231044 0x200 8 8 264 176 ""
;1 Button 0x54030001 0x4 280 171 48 14 "OK"
;2 Button 0x54030000 0x4 336 171 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "4 5 3"
str e4 e5 e3
e3=
;My name is ┆name┆, my age is ┆age┆,  thank you!

if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc v;; must have v attribute
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,str- e3t1 e3t2
,SendMessage id(4 hDlg) EM_SETCUEBANNER TRUE @"┆name┆"
,SendMessage id(5 hDlg) EM_SETCUEBANNER TRUE @"┆age┆"
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case [EN_CHANGE<<16|4,EN_CHANGE<<16|5]
,DT_GetControls(hDlg)
,_s=e3
,if(empty(e4))
,,e4="┆name┆"
,if(empty(e5))
,,e5="┆age┆"
,if(findrx(_s "┆name┆" 0 8)>=0)
,,_s.replacerx("┆name┆" e4 8)
,else
,,_s.replacerx(e3t1 e4 2|8);err

,if(findrx(_s "┆age┆" 0 8)>=0)
,,_s.replacerx("┆age┆" e5 8)
,else
,,_s.replacerx(e3t2 e5 2|8);err
,e3t1= e4
,e3t2=e5
,DT_SetControl(hDlg 3 _s)

ret 1
#5
Double-byte characters have no effect e.g Replace with 哈哈
#6
I think you are trying to say it is having trouble with double-byte characters. 
Try this
Code:
Copy      Help
str Text r Words
Words=
;┆name┆ = ""
;┆age┆ = ""

ICsv xt._create
xt.Separator="="
ICsv xw._create
xw.Separator="="
xw.FromString(Words)

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 392 192 "Dialog" "4"
;4 Edit 0x54030080 0x200 280 8 104 12 ""
;5 Edit 0x54030080 0x204 280 28 104 13 ""
;3 Edit 0x54231044 0x200 8 8 264 176 ""
;1 Button 0x54030001 0x4 280 171 48 14 "OK"
;2 Button 0x54030000 0x4 336 171 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "4 5 3"
str e4 e5 e3
e3=
;My name is ┆name┆, my age is ┆age┆,  thank you!

if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc v;; must have v attribute
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,str- e3t e3t1
,_s.getwintext(id(3 hDlg))
,Text=F" original = ''{_s}''"
,SendMessage id(4 hDlg) EM_SETCUEBANNER TRUE @"┆name┆"
,SendMessage id(5 hDlg) EM_SETCUEBANNER TRUE @"┆age┆"
,xt.FromString(Text)    
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case EN_KILLFOCUS<<16|3
,e3t.getwintext(lParam)
,e3t1=xt.Cell(0 1)
,if e3t<>e3t1
,,DT_GetControls(hDlg)
,,if(empty(e4) and empty(e5))
,,,Text=F" original = ''{e3t}''"
,,,xt.FromString(Text)
,case [EN_CHANGE<<16|4,EN_CHANGE<<16|5]
,DT_GetControls(hDlg)
,_s=xt.Cell(0 1)
,Words=
,F
,;┆name┆ = "{e4}"
,;┆age┆ = "{e5}"

,xw.FromString(Words)
,for int'i 0 xw.RowCount
,,r=xw.Cell(i 1)
,,if(r.len)
,,,_s.findreplace(xw.Cell(i 0) r 2)
,,else
,,,r= xw.Cell(i 0)
,DT_SetControl(hDlg 3 _s)

ret 1
#7
Thanks again, works well now
#8
adding ' or "  marks around the string, I want to make it easier to operate
I thought of the following method, adding it based on the number of spaces at the end of the string
bug, How to apply to the replace operation of the text edit box above 
I tried unsuccessfully

Macro Macro6
Code:
Copy      Help
_s="abc" ;;no space after abc -> out abc
_s="abc " ;;There is a space after abc -> out 'abc'
_s="abc  " ;;There are two spaces after abc -> out "abc"

str pattern2=".+  $"
str pattern1=".+ $"

if(findrx(_s pattern2)=0)
,out F"''{_s.trim}''" ;;out "abc"
else if(findrx(_s pattern1)=0)
,out F"'{_s.trim}'" ;;out 'abc'
else
,out _s ;;out abc
#9
@Kevin

I looked for the following code, Is it possible? replace string in real time with ARRAY(POINT)?

Macro A1
Code:
Copy      Help
out
str template=
;My name is $inp_name$, my age is $inp_age$,  thank you!

ARRAY(str) a
if(!findrx(template "\$(?:inp)_(.+?)\$" 0 4 a)) ret template

ARRAY(str) c.create(a.len+1)
c[0]="4"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 224 %i ''Manual Text Input''[]3 Static 0x54000000 0x0 8 8 214 10 ''%s''[]" a.len*30+60 template)
int i idEdit(4) idStatic(503) y(28)
for i 0 a.len
,dd.formata("%i Static 0x54000000 0x0 8 %i 214 10 ''%s''[]%i " idStatic y a[1 i].escape(1) idEdit)
,sel a[0 i][1]
,,case 'i'
,,dd.formata("Edit 0x54030080 0x200 8 %i 208 13[]" y+12)
,if(i) c[0].formata(" %i" idEdit)
,y+30
,idEdit+1
,idStatic+1
y+10
dd.formata("1 Button 0x54030001 0x4 116 %i 48 14 ''OK''[]2 Button 0x54030000 0x4 168 %i 48 14 ''Cancel''[]END DIALOG" y y)

out c[0]
out dd

if(!ShowDialog(dd 0 &c[0])) end

str r
ARRAY(POINT) b
findrx(template "\$(?:inp)_.+?\$" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,int u=0; if(template[p.x+1]='s') val(c[i+1] 0 u); u+1
,r+c[i+1]+u
,j=p.y
r.geta(template j)

mes r


Forum Jump:


Users browsing this thread: 2 Guest(s)