Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sets the color for specific text within the RichEdit control
#1
Hi,

I want to achieve the effect in the picture below


[Image: hight.gif]

I have done the auto-replace function using QM code, However, no color is automatically added for specific text, the effect in the picture below

[Image: abc2.gif]

Is it complicated to implement auto-shading in QM? This may require more programming skills

Thanks in advance for any advice and help
david

Macro Highlight_text
Code:
Copy      Help
out
str template=
;For ┋Counter Variable┋ = ┋Lower Limit┋ To ┋Upper Limit┋
;,$P[I]
;Next

ARRAY(str) a
if(!findrx(template "┋(.+?)┋" 0 4 a)) end
ARRAY(str) c.create(a.len+1)
c[0]="4"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 490 %i ''Manual Text Input''[]" a.len*30+40)
int i idEdit(4) y(8)
for i 0 a.len
,dd.formata("%i Edit 0x54030080 0x200 8 %i 121 13[]" idEdit y)
,c[i+1]=a[0 i]
,if(i)
,,c[0].formata(" %i" idEdit)
,y+20
,idEdit+1
y+10
_s=
;1 Button 0x54030001 0x4 20 108 48 14 "OK"
;2 Button 0x54030000 0x4 80 108 48 14 "Cancel"
;3 RichEdit20A 0x54233044 0x0 136 8 346 114 ""
;END DIALOG

c.insert(i+1)
c[0].formata(" %i" 3)
dd.formata(_s)

;out dd

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

mes c[c.len-1]

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,_s=template
,_s.setwintext(id(3 hDlg))
,__Font-- f.Create("Microsoft YaHei Mono" 9 0) ;;font
,f.SetDialogFont(hDlg "3")
,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,EN_CHANGE<<16|6,EN_CHANGE<<16|7,EN_CHANGE<<16|8,EN_CHANGE<<16|9]
,DT_GetControls(hDlg)
,sub.RR(template c _s)
,DT_SetControl(hDlg 3 _s)
ret 1

#sub RR
function str'template ARRAY(str)'c str&r
int i
ARRAY(POINT) b
findrx(template "┋(.+?)┋" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,r+c[i+1]
,j=p.y
r.geta(template j)
#2
google:
rich edit control messages site:docs.microsoft.com

I would use Scintilla control, not richedit. But need some learning.
#3
Thanks for the reminder!
How to use Scintilla control in qm, Can you provide a simple examples? 
I didn't find a post on the forum

Insert declaration from dll file, It will be not loaded
#4
Scintilla documentation:
https://www.scintilla.org/ScintillaDoc.html

Example:
Function example_dialog_scintilla
Code:
Copy      Help
out

str text=
;aaa [[blue]] bbb
;ccc [[orange]] ddd
;ddd [[blue]] ddd
;

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 336 208 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 60 0 276 202 ""
;4 Button 0x54032000 0x0 4 4 48 14 "Clear"
;5 Button 0x54032000 0x0 4 24 48 14 "Update"
;1 Button 0x54030001 0x4 4 172 48 14 "OK"
;2 Button 0x54030000 0x4 4 188 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

int sci
int indicBlue(0) indicOrange(1)

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


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,
,sub.DefineIndicator(indicBlue 0xff0000)
,sub.DefineIndicator(indicOrange 0x00e0ff)
,
,sub.SetText(text)
,
,sub.SetIndicator(indicBlue "[[blue]]")
,sub.SetIndicator(indicOrange "[[orange]]")
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 4 ;;Clear
,sub.ClearIndicator(indicBlue)
,sub.ClearIndicator(indicOrange)
,case 5 ;;Update
,sub.ClearIndicator(indicBlue)
,sub.ClearIndicator(indicOrange)
,sub.SetIndicator(indicBlue "[[blue]]")
,sub.SetIndicator(indicOrange "[[orange]]")
,
ret 1
;messages3
SCI.SCNotification* k=+lParam
sel k.nmhdr.code
,case SCI.SCN_MODIFIED
,if k.modificationType&(SCI.SC_MOD_INSERTTEXT|SCI.SC_MOD_DELETETEXT)
,,out "modified"


#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub DefineIndicator v
function indicator color
sub.Sci(SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
sub.Sci(SCI.SCI_INDICSETFORE indicator color)
sub.Sci(SCI.SCI_INDICSETUNDER indicator 1)
sub.Sci(SCI.SCI_INDICSETALPHA indicator 128)

#sub SetIndicator v
function indicator $s
str text; sub.GetText(text)
int i n
rep
,i=find(text s i+n); if(i<0) break
,n=len(s)
,sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
,sub.Sci(SCI.SCI_INDICATORFILLRANGE i n)

#sub ClearIndicator v
function indicator
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORCLEARRANGE 0 SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0))

#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n text.all(n)))

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)
#5
thank you so much
#6
I meet a small question
the color didn't change during the process of changing the value of the control


Macro sci
Code:
Copy      Help
out
str template=
;For ┋Counter Variable┋ = ┋Lower Limit┋ To ┋Upper Limit┋
;,$P[I]
;Next

ARRAY(str) a
if(!findrx(template "┋(.+?)┋" 0 4 a)) end

ARRAY(str) c.create(a.len+1)
c[0]="5"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 490 %i ''Manual Text Input''[]" a.len*30+40)
int i idEdit(5) y(8)
for i 0 a.len
,dd.formata("%i Edit 0x54030080 0x200 8 %i 121 13[]" idEdit y)
,c[i+1]=a[0 i]
,if(i)
,,c[0].formata(" %i" idEdit)
,y+20
,idEdit+1
y+10
_s=
;1 Button 0x54030001 0x4 20 108 48 14 "OK"
;2 Button 0x54030000 0x4 80 108 48 14 "Cancel"
;3 Scintilla 0x54000000 0x20000 136 8 346 114 ""
;END DIALOG
dd.formata(_s)
;out dd
c.insert(i+1)
c[0].formata(" %i" 3)

int sci
int indicBlue(0) indicOrange(1)

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

mes c[c.len-1]

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,
,sci=id(3 hDlg)
,
,sub.DefineIndicator(indicBlue 0xff0000)
,sub.DefineIndicator(indicOrange 0x00e0ff)
,
,sub.SetText(template) ;;set e3 text
,
,;set ┋xxx┋ color
,for i 0 a.len
,,sub.SetIndicator(indicOrange a[0 i])
,
,;Todo: set font: "Microsoft YaHei Mono"  fontsize: 9
,;Todo: Hides the horizontal scroll bar
,;Todo: Customize the context menu
,
,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,EN_CHANGE<<16|6,EN_CHANGE<<16|7,EN_CHANGE<<16|8,EN_CHANGE<<16|9]
,DT_GetControls(hDlg)
,sub.RR(template c _s)
,sub.SetText(_s)
,
ret 1

#sub RR v
function str'template ARRAY(str)'c str&r

int i
ARRAY(POINT) b
findrx(template "┋(.+?)┋" 0 4 b)

int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,r+c[i+1]
,sub.SetIndicator(indicOrange a[0 i]) ;;set indicOrange color
,sub.SetIndicator(indicBlue c[i+1]) ;;set indicBlue color
,out c[i+1]
,j=p.y
r.geta(template j)

#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub DefineIndicator v
function indicator color
sub.Sci(SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
sub.Sci(SCI.SCI_INDICSETFORE indicator color)
sub.Sci(SCI.SCI_INDICSETUNDER indicator 1)
sub.Sci(SCI.SCI_INDICSETALPHA indicator 128)

#sub SetIndicator v
function indicator $s
str text; sub.GetText(text)
int i n
rep
,i=find(text s i+n); if(i<0) break
,n=len(s)
,sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
,sub.Sci(SCI.SCI_INDICATORFILLRANGE i n)

#sub ClearIndicator v
function indicator
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORCLEARRANGE 0 SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0))

#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n text.all(n)))

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)
#7
try this out
Code:
Copy      Help
out
str template=
;For ┋Counter Variable┋ = ┋Lower Limit┋ To ┋Upper Limit┋
;,$P[I]
;Next

ARRAY(str) a
if(!findrx(template "┋(.+?)┋" 0 4 a)) end

ARRAY(str) c.create(a.len+1)
c[0]="5"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 490 %i ''Manual Text Input''[]" a.len*30+40)
int i idEdit(5) y(8)
for i 0 a.len
,dd.formata("%i Edit 0x54030080 0x200 8 %i 121 13[]" idEdit y)
,c[i+1]=a[0 i]
,if(i)
,,c[0].formata(" %i" idEdit)
,y+20
,idEdit+1
y+10
_s=
;1 Button 0x54030001 0x4 20 108 48 14 "OK"
;2 Button 0x54030000 0x4 80 108 48 14 "Cancel"
;3 Scintilla 0x54000000 0x20000 136 8 346 114 ""
;END DIALOG
dd.formata(_s)
;out dd
c.insert(i+1)
c[0].formata(" %i" 3)

int sci
int indicBlue(0) indicOrange(1)

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

mes c[c.len-1]

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.Sci(SCI.SCI_SETHSCROLLBAR 0 0);;hide horz scrollbar
,sub.SetFont(sci "Segoe UI" 12);;set font name and size
,sub.DefineIndicator(indicBlue 0xff0000)
,sub.DefineIndicator(indicOrange 0x00e0ff)
,sub.SetText(template) ;;set e3 text
,;set ┋xxx┋ color
,for i 0 a.len
,,sub.SetIndicator(indicOrange a[0 i])
,;Todo: Customize the context menu
,sub.Sci(SCI.SCI_USEPOPUP 0 0)
,case WM_CONTEXTMENU
,sel GetDlgCtrlID(wParam)
,,case 3
,,sel ShowMenu("1 Copy[]2 Paste" hDlg)
,,,case 1 SendMessage wParam SCI.SCI_COPY 0 0
,,,case 2 SendMessage wParam SCI.SCI_PASTE 0 0    
,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,EN_CHANGE<<16|6,EN_CHANGE<<16|7,EN_CHANGE<<16|8,EN_CHANGE<<16|9]
,DT_GetControls(hDlg)
,sub.RR(template c _s)
,sub.SetText(_s)
,for i 0 a.len
,,if(empty(c[i+1]))
,,,sub.SetIndicator(indicOrange a[0 i])
,,if c[i+1] <> a[0 i]
,,,sub.SetIndicator(indicBlue c[i+1])
,,else
,,,sub.SetIndicator(indicOrange a[0 i])    
ret 1

#sub RR v
function str'template ARRAY(str)'c str&r

int i
ARRAY(POINT) b
findrx(template "┋(.+?)┋" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,if(empty(c[i+1]))
,,c[i+1]=a[0 i]
,r+c[i+1]
,j=p.y
r.geta(template j)

#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub DefineIndicator v
function indicator color
sub.Sci(SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
sub.Sci(SCI.SCI_INDICSETFORE indicator color)
sub.Sci(SCI.SCI_INDICSETUNDER indicator 1)
sub.Sci(SCI.SCI_INDICSETALPHA indicator 128)

#sub SetIndicator v
function indicator $s
str text; sub.GetText(text)
int i n
rep
,i=find(text s i+n); if(i<0) break
,n=len(s)
,sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
,sub.Sci(SCI.SCI_INDICATORFILLRANGE i n)

#sub ClearIndicator v
function indicator
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORCLEARRANGE 0 SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0))

#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)

#sub SetFont 
function hwnd [$fontName] [fontSize]

int h=hwnd
if(!empty(fontName)) SendMessage(h SCI.SCI_STYLESETFONT 32 fontName)
if(fontSize) SendMessage(h SCI.SCI_STYLESETSIZE 32 fontSize)

;save <code> styles
type __QDISTYLE colText colBack !bold !italic !underline !eol
ARRAY(__QDISTYLE) a.create(32)
int i
for i 1 18
,__QDISTYLE& r=a[i]
,r.colText=SendMessage(h SCI.SCI_STYLEGETFORE i 0)
,r.colBack=SendMessage(h SCI.SCI_STYLEGETBACK i 0)
,r.bold=SendMessage(h SCI.SCI_STYLEGETBOLD i 0)
,r.italic=SendMessage(h SCI.SCI_STYLEGETITALIC i 0)
,r.underline=SendMessage(h SCI.SCI_STYLEGETUNDERLINE i 0)
,r.eol=SendMessage(h SCI.SCI_STYLEGETEOLFILLED i 0)

;set other styles the same as the default style 32. It clears <code> styles etc, that is why we save/restore them.
SendMessage(h SCI.SCI_STYLECLEARALL 0 0)

;restore
for i 1 18
,&r=a[i]
,SendMessage(h SCI.SCI_STYLESETFORE i r.colText)
,SendMessage(h SCI.SCI_STYLESETBACK i r.colBack)
,SendMessage(h SCI.SCI_STYLESETBOLD i r.bold)
,SendMessage(h SCI.SCI_STYLESETITALIC i r.italic)
,SendMessage(h SCI.SCI_STYLESETUNDERLINE i r.underline)
,SendMessage(h SCI.SCI_STYLESETEOLFILLED i r.eol)
SendMessage(h SCI.SCI_STYLESETVISIBLE 31 0)
#8
@Kevin
Thanks for your help!!!
If the entered characters are duplicated, Change the color fails

[Image: eee.gif]
#9
fixed. code in #7 post adjusted
https://www.quickmacros.com/forum/showth...8#pid35808
#10
It seems, not very easy to control
This example is less appropriate because it is a keyword, Exclamation
but if there is a lot of code inside, it will add color to many of the same words

[Image: rrr.gif]
#11
#sub SetIndicator was just an example. For real code need to create a real function for setting indicators.
#12
@Gintaras 
Can you help me create this indicators function? or related reference code
I looked up a lot of relevant knowledge but still couldn't find a solution 
Thank you!
#13
sorry didn't see this post for a while.
Simplified code as much as I could

this works good in all my test
 
Code:
Copy      Help
out
str template=
;For ┋Counter Variable┋ = ┋Lower Limit┋ To ┋Upper Limit┋
;,$P[I]
;Next

ARRAY(str) a
if(!findrx(template "┋(.+?)┋" 0 4 a)) end
ARRAY(int) tpos.create(a.len)
ARRAY(str) c.create(a.len+1)
c[0]="5"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 490 %i ''Manual Text Input''[]" a.len*30+40)
int i idEdit(5) y(8)
for i 0 a.len
,dd.formata("%i Edit 0x54030080 0x200 8 %i 121 13[]" idEdit y)
,c[i+1]=a[0 i]
,if(i)
,,c[0].formata(" %i" idEdit)
,y+20
,idEdit+1
y+10
_s=
;1 Button 0x54030001 0x4 20 108 48 14 "OK"
;2 Button 0x54030000 0x4 80 108 48 14 "Cancel"
;3 Scintilla 0x54000000 0x20000 136 8 346 114 ""
;END DIALOG
dd.formata(_s)
;out dd
c.insert(i+1)
c[0].formata(" %i" 3)

int sci
int indicBlue(0) indicOrange(1)

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

mes c[c.len-1]

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.Sci(SCI.SCI_SETHSCROLLBAR 0 0);;hide horz scrollbar
,sub.SetFont(sci "Segoe UI" 12);;set font name and size
,sub.DefineIndicator(indicBlue 0xFF0000)
,sub.DefineIndicator(indicOrange 0x00e0ff)
,sub.SetText(template) ;;set e3 text
,;;;Customize the context menu
,sub.Sci(SCI.SCI_USEPOPUP 0 0)
,case WM_CONTEXTMENU
,sel GetDlgCtrlID(wParam)
,,case 3
,,sel ShowMenu("1 Copy[]2 Paste" hDlg)
,,,case 1 SendMessage wParam SCI.SCI_COPY 0 0
,,,case 2 SendMessage wParam SCI.SCI_PASTE 0 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case else
,word loword;  word hiword
,loword=wParam&0xFFFF
,hiword=wParam>>16
,sel hiword
,,case 768 ;;EN_CHANGE
,,DT_GetControls(hDlg)
,,sub.ClearIndicator(indicBlue)
,,sub.ClearIndicator(indicOrange)
,,sub.RR(template c _s)
,,sub.SetText(_s)
,,for i 1 c.len-1
,,,if(empty(c[i]))
,,,,DT_SetControl(hDlg loword a[0 i-1])
,,,,break
,,,if(i=1)
,,,,tpos[i-1]=find(_s c[i])
,,,else
,,,,tpos[i-1]=find(_s c[i] tpos[i-2]+c[i-1].len)
,,,if(loword= i+4)
,,,,sub.SetIndicator(indicBlue c[i] tpos[i-1])
,,,else
,,,,sub.SetIndicator(indicOrange c[i] tpos[i-1])    
,,case 256 ;;EN_SETFOCUS
,,DT_GetControls(hDlg)
,,sub.ClearIndicator(indicBlue)
,,sub.ClearIndicator(indicOrange)
,,for i 1 c.len-1
,,,str text2; sub.GetText(text2)
,,,if(i=1)
,,,,tpos[i-1]=find(text2 c[i])
,,,else
,,,,tpos[i-1]=find(text2 c[i] tpos[i-2]+c[i-1].len)
,,,if(loword= i+4)
,,,,sub.SetIndicator(indicBlue c[i] tpos[i-1])
,,,else
,,,,sub.SetIndicator(indicOrange c[i] tpos[i-1])    
ret 1

#sub RR v
function str'template ARRAY(str)'c str&r [&pos]
int i
ARRAY(POINT) b
findrx(template "┋(.+?)┋" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,if(empty(c[i+1]))
,,c[i+1]=a[0 i]
,r+c[i+1]
,j=p.y
r.geta(template j)

#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub DefineIndicator v
function indicator color
sub.Sci(SCI.SCI_INDICSETSTYLE indicator 16)
sub.Sci(SCI.SCI_INDICSETFORE indicator color)
sub.Sci(SCI.SCI_INDICSETUNDER indicator 1)
sub.Sci(SCI.SCI_INDICSETALPHA indicator 128)

#sub SetIndicator v
function indicator $s [spos]
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORFILLRANGE spos len(s))

#sub ClearIndicator v
function indicator
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORCLEARRANGE 0 SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0))

#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)

#sub SetFont
function hwnd [$fontName] [fontSize]
int h=hwnd
if(!empty(fontName)) SendMessage(h SCI.SCI_STYLESETFONT 32 fontName)
if(fontSize) SendMessage(h SCI.SCI_STYLESETSIZE 32 fontSize)
;save <code> styles
type __QDISTYLE colText colBack !bold !italic !underline !eol
ARRAY(__QDISTYLE) a.create(32)
int i
for i 1 18
,__QDISTYLE& r=a[i]
,r.colText=SendMessage(h SCI.SCI_STYLEGETFORE i 0)
,r.colBack=SendMessage(h SCI.SCI_STYLEGETBACK i 0)
,r.bold=SendMessage(h SCI.SCI_STYLEGETBOLD i 0)
,r.italic=SendMessage(h SCI.SCI_STYLEGETITALIC i 0)
,r.underline=SendMessage(h SCI.SCI_STYLEGETUNDERLINE i 0)
,r.eol=SendMessage(h SCI.SCI_STYLEGETEOLFILLED i 0)
;set other styles the same as the default style 32. It clears <code> styles etc, that is why we save/restore them.
SendMessage(h SCI.SCI_STYLECLEARALL 0 0)
;restore
for i 1 18
,&r=a[i]
,SendMessage(h SCI.SCI_STYLESETFORE i r.colText)
,SendMessage(h SCI.SCI_STYLESETBACK i r.colBack)
,SendMessage(h SCI.SCI_STYLESETBOLD i r.bold)
,SendMessage(h SCI.SCI_STYLESETITALIC i r.italic)
,SendMessage(h SCI.SCI_STYLESETUNDERLINE i r.underline)
,SendMessage(h SCI.SCI_STYLESETEOLFILLED i r.eol)
SendMessage(h SCI.SCI_STYLESETVISIBLE 31 0)
#14
@Kevin
Thanks for your help

Wrong location

[Image: aaa.gif]
#15
Code:
Copy      Help
out
str template=
;For ┋Counter Variable┋ = ┋Lower Limit┋ To ┋Upper Limit┋
;,$P[I]
;Next

ARRAY(str) a
if(!findrx(template "┋(.+?)┋" 0 4 a)) end
ARRAY(POINT) aa
if(!findrx(template "┋(.+?)┋" 0 4 aa)) end
ARRAY(int) tpos
for int'j 0 aa.len
,tpos[]= aa[0 j].x
ARRAY(str) c.create(a.len+1)
c[0]="5"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 490 %i ''Manual Text Input''[]" a.len*30+40)
int i idEdit(5) y(8)
for i 0 a.len
,dd.formata("%i Edit 0x54030080 0x200 8 %i 121 13[]" idEdit y)
,c[i+1]=a[0 i]
,if(i)
,,c[0].formata(" %i" idEdit)
,y+20
,idEdit+1
y+10
_s=
;1 Button 0x54030001 0x4 20 108 48 14 "OK"
;2 Button 0x54030000 0x4 80 108 48 14 "Cancel"
;3 Scintilla 0x54000000 0x20000 136 8 346 114 ""
;END DIALOG
dd.formata(_s)
;out dd
c.insert(i+1)
c[0].formata(" %i" 3)

int sci
int indicBlue(0) indicOrange(1)

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

mes c[c.len-1]

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.Sci(SCI.SCI_SETHSCROLLBAR 0 0);;hide horz scrollbar
,sub.SetFont(sci "Segoe UI" 12);;set font name and size
,sub.DefineIndicator(indicBlue 0xFF0000)
,sub.DefineIndicator(indicOrange 0x00e0ff)
,sub.SetText(template) ;;set e3 text
,;;;Customize the context menu
,sub.Sci(SCI.SCI_USEPOPUP 0 0)
,case WM_CONTEXTMENU
,sel GetDlgCtrlID(wParam)
,,case 3
,,sel ShowMenu("1 Copy[]2 Paste" hDlg)
,,,case 1 SendMessage wParam SCI.SCI_COPY 0 0
,,,case 2 SendMessage wParam SCI.SCI_PASTE 0 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case else
,word loword;  word hiword
,loword=wParam&0xFFFF
,hiword=wParam>>16
,sel hiword
,,case 768 ;;EN_CHANGE
,,DT_GetControls(hDlg)
,,sub.ClearIndicator(indicBlue)
,,sub.ClearIndicator(indicOrange)
,,sub.RR(template c _s)
,,sub.SetText(_s)
,,for i 1 c.len-1
,,,if(empty(c[i]))
,,,,DT_SetControl(hDlg loword a[0 i-1])
,,,,break
,,,if(i=1)
,,,,tpos[i-1]=find(_s c[i] tpos[i-1])
,,,else
,,,,tpos[i-1]=find(_s c[i] tpos[i-2]+c[i-1].len)
,,,if(loword= i+4)
,,,,sub.SetIndicator(indicBlue c[i] tpos[i-1])
,,,else
,,,,sub.SetIndicator(indicOrange c[i] tpos[i-1])    
,,case 256 ;;EN_SETFOCUS
,,DT_GetControls(hDlg)
,,sub.ClearIndicator(indicBlue)
,,sub.ClearIndicator(indicOrange)
,,for i 1 c.len-1
,,,str text2; sub.GetText(text2)
,,,if(i=1)
,,,,tpos[i-1]=find(text2 c[i] tpos[i-1])            
,,,else
,,,,tpos[i-1]=find(text2 c[i] tpos[i-2]+c[i-1].len)
,,,if(loword= i+4)
,,,,sub.SetIndicator(indicBlue c[i] tpos[i-1])
,,,else
,,,,sub.SetIndicator(indicOrange c[i] tpos[i-1])    
ret 1

#sub RR v
function str'template ARRAY(str)'c str&r [&pos]
int i
ARRAY(POINT) b
findrx(template "┋(.+?)┋" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,r+c[i+1]
,j=p.y
r.geta(template j)

#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub DefineIndicator v
function indicator color
sub.Sci(SCI.SCI_INDICSETSTYLE indicator 16)
sub.Sci(SCI.SCI_INDICSETFORE indicator color)
sub.Sci(SCI.SCI_INDICSETUNDER indicator 1)
sub.Sci(SCI.SCI_INDICSETALPHA indicator 128)

#sub SetIndicator v
function indicator $s [spos]
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORFILLRANGE spos len(s))

#sub ClearIndicator v
function indicator
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORCLEARRANGE 0 SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0))

#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)

#sub SetFont
function hwnd [$fontName] [fontSize]
int h=hwnd
if(!empty(fontName)) SendMessage(h SCI.SCI_STYLESETFONT 32 fontName)
if(fontSize) SendMessage(h SCI.SCI_STYLESETSIZE 32 fontSize)
;save <code> styles
type __QDISTYLE colText colBack !bold !italic !underline !eol
ARRAY(__QDISTYLE) a.create(32)
int i
for i 1 18
,__QDISTYLE& r=a[i]
,r.colText=SendMessage(h SCI.SCI_STYLEGETFORE i 0)
,r.colBack=SendMessage(h SCI.SCI_STYLEGETBACK i 0)
,r.bold=SendMessage(h SCI.SCI_STYLEGETBOLD i 0)
,r.italic=SendMessage(h SCI.SCI_STYLEGETITALIC i 0)
,r.underline=SendMessage(h SCI.SCI_STYLEGETUNDERLINE i 0)
,r.eol=SendMessage(h SCI.SCI_STYLEGETEOLFILLED i 0)
;set other styles the same as the default style 32. It clears <code> styles etc, that is why we save/restore them.
SendMessage(h SCI.SCI_STYLECLEARALL 0 0)
;restore
for i 1 18
,&r=a[i]
,SendMessage(h SCI.SCI_STYLESETFORE i r.colText)
,SendMessage(h SCI.SCI_STYLESETBACK i r.colBack)
,SendMessage(h SCI.SCI_STYLESETBOLD i r.bold)
,SendMessage(h SCI.SCI_STYLESETITALIC i r.italic)
,SendMessage(h SCI.SCI_STYLESETUNDERLINE i r.underline)
,SendMessage(h SCI.SCI_STYLESETEOLFILLED i r.eol)
SendMessage(h SCI.SCI_STYLESETVISIBLE 31 0)
#16
Works well
thank you so much Smile

About the following code, I don't quite understand,
Red word, how is the value obtained? If there are many other types of controls, do these values need to be changed?
Are there any references?

word loword;  word hiword
loword=wParam&0xFFFF
hiword=wParam>>16
sel hiword
case 768 ;;EN_CHANGE

case 256 ;;EN_SETFOCUS
#17
the numbers are from the breakdown of wParam.
wParam consists of two parts.
 a high word and a low word
for example
EN_CHANGE<<16|5
   
768 is the integer value of EN_CHANGE (example ---> out EN_CHANGE)
the low word is 5 
the high word broken down is EN_CHANGE

technically i should have done this
 
Code:
Copy      Help
,case else
,int loword=wParam&0xFFFF
,int hiword=wParam>>16
,sel hiword

you can if it is less confusing just do this
 
Code:
Copy      Help
out
str template=
;For ┋Counter Variable┋ = ┋Lower Limit┋ To ┋Upper Limit┋
;,$P[I]
;Next

ARRAY(str) a
if(!findrx(template "┋(.+?)┋" 0 4 a)) end
ARRAY(POINT) aa
if(!findrx(template "┋(.+?)┋" 0 4 aa)) end
ARRAY(int) tpos
for int'j 0 aa.len
,tpos[]= aa[0 j].x
ARRAY(str) c.create(a.len+1)
c[0]="5"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 490 %i ''Manual Text Input''[]" a.len*30+40)
int i idEdit(5) y(8)
for i 0 a.len
,dd.formata("%i Edit 0x54030080 0x200 8 %i 121 13[]" idEdit y)
,c[i+1]=a[0 i]
,if(i)
,,c[0].formata(" %i" idEdit)
,y+20
,idEdit+1
y+10
_s=
;1 Button 0x54030001 0x4 20 108 48 14 "OK"
;2 Button 0x54030000 0x4 80 108 48 14 "Cancel"
;3 Scintilla 0x54000000 0x20000 136 8 346 114 ""
;END DIALOG
dd.formata(_s)
;out dd
c.insert(i+1)
c[0].formata(" %i" 3)

int sci
int indicBlue(0) indicOrange(1)

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

mes c[c.len-1]

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.Sci(SCI.SCI_SETHSCROLLBAR 0 0);;hide horz scrollbar
,sub.SetFont(sci "Segoe UI" 12);;set font name and size
,sub.DefineIndicator(indicBlue 0xFF0000)
,sub.DefineIndicator(indicOrange 0x00e0ff)
,sub.SetText(template) ;;set e3 text
,;;;Customize the context menu
,sub.Sci(SCI.SCI_USEPOPUP 0 0)
,case WM_CONTEXTMENU
,sel GetDlgCtrlID(wParam)
,,case 3
,,sel ShowMenu("1 Copy[]2 Paste" hDlg)
,,,case 1 SendMessage wParam SCI.SCI_COPY 0 0
,,,case 2 SendMessage wParam SCI.SCI_PASTE 0 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case else
,int loword=wParam&0xFFFF
,int hiword=wParam>>16
,sel hiword
,,case EN_CHANGE;;or 768
,,DT_GetControls(hDlg)
,,sub.ClearIndicator(indicBlue)
,,sub.ClearIndicator(indicOrange)
,,sub.RR(template c _s)
,,sub.SetText(_s)
,,for i 1 c.len-1
,,,if(empty(c[i]))
,,,,DT_SetControl(hDlg loword a[0 i-1])
,,,,break
,,,if(i=1)
,,,,tpos[i-1]=find(_s c[i] tpos[i-1])
,,,else
,,,,tpos[i-1]=find(_s c[i] tpos[i-2]+c[i-1].len)
,,,if(loword= i+4)
,,,,sub.SetIndicator(indicBlue c[i] tpos[i-1])
,,,else
,,,,sub.SetIndicator(indicOrange c[i] tpos[i-1])
,,case EN_SETFOCUS;;or 256
,,DT_GetControls(hDlg)
,,sub.ClearIndicator(indicBlue)
,,sub.ClearIndicator(indicOrange)
,,for i 1 c.len-1
,,,str text2; sub.GetText(text2)
,,,if(i=1)
,,,,tpos[i-1]=find(text2 c[i] tpos[i-1])
,,,else
,,,,tpos[i-1]=find(text2 c[i] tpos[i-2]+c[i-1].len)
,,,if(loword= i+4)
,,,,sub.SetIndicator(indicBlue c[i] tpos[i-1])
,,,else
,,,,sub.SetIndicator(indicOrange c[i] tpos[i-1])
ret 1

#sub RR v
function str'template ARRAY(str)'c str&r [&pos]
int i
ARRAY(POINT) b
findrx(template "┋(.+?)┋" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,r+c[i+1]
,j=p.y
r.geta(template j)

#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub DefineIndicator v
function indicator color
sub.Sci(SCI.SCI_INDICSETSTYLE indicator 16)
sub.Sci(SCI.SCI_INDICSETFORE indicator color)
sub.Sci(SCI.SCI_INDICSETUNDER indicator 1)
sub.Sci(SCI.SCI_INDICSETALPHA indicator 128)

#sub SetIndicator v
function indicator $s [spos]
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORFILLRANGE spos len(s))

#sub ClearIndicator v
function indicator
sub.Sci(SCI.SCI_SETINDICATORCURRENT indicator)
sub.Sci(SCI.SCI_INDICATORCLEARRANGE 0 SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0))

#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)

#sub SetFont
function hwnd [$fontName] [fontSize]
int h=hwnd
if(!empty(fontName)) SendMessage(h SCI.SCI_STYLESETFONT 32 fontName)
if(fontSize) SendMessage(h SCI.SCI_STYLESETSIZE 32 fontSize)
;save <code> styles
type __QDISTYLE colText colBack !bold !italic !underline !eol
ARRAY(__QDISTYLE) a.create(32)
int i
for i 1 18
,__QDISTYLE& r=a[i]
,r.colText=SendMessage(h SCI.SCI_STYLEGETFORE i 0)
,r.colBack=SendMessage(h SCI.SCI_STYLEGETBACK i 0)
,r.bold=SendMessage(h SCI.SCI_STYLEGETBOLD i 0)
,r.italic=SendMessage(h SCI.SCI_STYLEGETITALIC i 0)
,r.underline=SendMessage(h SCI.SCI_STYLEGETUNDERLINE i 0)
,r.eol=SendMessage(h SCI.SCI_STYLEGETEOLFILLED i 0)
;set other styles the same as the default style 32. It clears <code> styles etc, that is why we save/restore them.
SendMessage(h SCI.SCI_STYLECLEARALL 0 0)
;restore
for i 1 18
,&r=a[i]
,SendMessage(h SCI.SCI_STYLESETFORE i r.colText)
,SendMessage(h SCI.SCI_STYLESETBACK i r.colBack)
,SendMessage(h SCI.SCI_STYLESETBOLD i r.bold)
,SendMessage(h SCI.SCI_STYLESETITALIC i r.italic)
,SendMessage(h SCI.SCI_STYLESETUNDERLINE i r.underline)
,SendMessage(h SCI.SCI_STYLESETEOLFILLED i r.eol)
SendMessage(h SCI.SCI_STYLESETVISIBLE 31 0)
#18
Thanks your detailed explanation extremely
#19
kevin
I deleted SCI control, now, how to output the modified template(str)
The method of replacement seems to be less stable, How to use the pointer method? 

Macro M1
Code:
Copy      Help
out
str template=
;For ┋Counter Variable┋ = ┋Lower Limit┋ To ┋Upper Limit┋
;,┋Counter Variable┋ ABC ┋Upper Limit┋
;Next
ARRAY(str) a
if(!findrx(template "┋(.+?)┋" 0 4 a)) end
ARRAY(str) c.create(a.len+1)
c[0]="5"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 137 %i ''Manual Text Input''[]" a.len*30)
int i idEdit(5) y(8)
for i 0 a.len
,dd.formata("%i Edit 0x54030080 0x200 8 %i 121 13[]" idEdit y)
,c[i+1]=a[0 i]
,if(i)
,,c[0].formata(" %i" idEdit)
,y+20
,idEdit+1
y+10
_s=
;1 Button 0x54030001 0x4 20 108 48 14 "OK"
;2 Button 0x54030000 0x4 80 108 48 14 "Cancel"
;END DIALOG
dd.formata(_s)

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

mes c[1]

;Todo: Output the modified template

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case else
,int loword=wParam&0xFFFF
,int hiword=wParam>>16
,sel hiword
,,case EN_CHANGE
,,DT_GetControls(hDlg)
,,for i 1 c.len-1
,,,if(empty(c[i]))
,,,,DT_SetControl(hDlg loword a[0 i-1])
,,,,break
ret 1
#20
Code:
Copy      Help
out
str template=
;For ┋Counter Variable┋ = ┋Lower Limit┋ To ┋Upper Limit┋
;,┋Counter Variable┋ ABC ┋Upper Limit┋
;Next
ARRAY(str) a
if(!findrx(template "┋(.+?)┋" 0 4 a)) end
ARRAY(str) c.create(a.len+1)
c[0]="5"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 137 %i ''Manual Text Input''[]" a.len*30)
int i idEdit(5) y(8)
for i 0 a.len
,dd.formata("%i Edit 0x54030080 0x200 8 %i 121 13[]" idEdit y)
,c[i+1]=a[0 i]
,if(i)
,,c[0].formata(" %i" idEdit)
,y+20
,idEdit+1
y+10
_s=
;1 Button 0x54030001 0x4 20 108 48 14 "OK"
;2 Button 0x54030000 0x4 80 108 48 14 "Cancel"
;END DIALOG
dd.formata(_s)

if(!ShowDialog(dd &sub.DlgProc &c[0])) end
str result
sub.RR(template c result)
mes result

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case else
,int loword=wParam&0xFFFF
,int hiword=wParam>>16
,sel hiword
,,case EN_CHANGE
,,DT_GetControls(hDlg)
,,for i 1 c.len-1
,,,if(empty(c[i]))
,,,,DT_SetControl(hDlg loword a[0 i-1])
,,,,break
ret 1

#sub RR
function str'template ARRAY(str)'c str&r
int i
ARRAY(POINT) b
findrx(template "┋(.+?)┋" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,r+c[i+1]
,j=p.y
r.geta(template j)
#21
worked well, thanks for your help!

I have another question,In sample code:
1.The text in the 1first edit box is the same as in the 4fourth edit box
2.The text in the 3third edit box is the same as in the 5fifth edit box
Is there a simple way to make the same text synchronous modify?
[Image: 1676505969]

Or another way, as in the image below:
Three edit boxes are displayed, but in the end, the same text synchronous modify
This may be a little difficult to achieve, but, This feature is useful in some cases


[Image: 1676507297]


Forum Jump:


Users browsing this thread: 7 Guest(s)