Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sets the color for specific text within the RichEdit control
#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)


Messages In This Thread
RE: Sets the color for specific text within the RichEdit control - by Davider - 09-03-2022, 12:08 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)