API and Coloration of a part of text
Posted: Fri Apr 29, 2005 3:28 pm
Hello, I'm french.
I want to colorize some text But I want to use buffers, because now I use the highlighting.
I arrived here , thanks to Cederavic.
I want to colorize some text But I want to use buffers, because now I use the highlighting.
I arrived here , thanks to Cederavic.
Code: Select all
ProcedureDLL Editor_ColorTest(Gadget,ydeb,xdeb,yfin,xfin,Color)
; Set the Text color for the Selection
; in RGB format
format.CHARFORMAT
format\cbSize = SizeOf(CHARFORMAT)
format\dwMask = #CFM_COLOR
format\crTextColor = Color
sel.CHARRANGE
; we get the old sélection
oldsel.CHARRANGE
SendMessage_(GadgetID(Gadget), #EM_GETSEL, @oldsel\cpMin, @oldsel\cpMax)
sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, ydeb, 0) + xdeb - 1
If yfin = -1
yfin = SendMessage_(GadgetID(Gadget), #EM_GETLINECOUNT, 0, 0)-1
EndIf
sel\cpMax =SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, yfin, 0)
If xfin = -1
sel\cpMax + SendMessage_(GadgetID(Gadget), #EM_LINELENGTH, sel\cpMax, 0)
Else
sel\cpMax + xfin - 1
EndIf
; we select the text that we want to colorize
SendMessage_(GadgetID(Gadget), #EM_SETSEL, sel\cpMin, sel\cpMax)
; wParam wait for the formatting mode, and not the position
SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION,@format)
; we replace the selection where it was
SendMessage_(GadgetID(Gadget), #EM_SETSEL, oldsel\cpMin, oldsel\cpMax)
EndProcedure
If OpenWindow(0,0,0,800,600,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0))
EditorGadget (30,8,8,400,500,#PB_Container_Raised)
For a=0 To 5
AddGadgetItem(30,a,"Line "+Str(a))
Next
ButtonGadget(2,610,10,150,50,"Change the COlor of the Text",#PB_Button_MultiLine)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 2
rgb=RGB(Random(255),Random(255),Random(255))
Editor_ColorTest(30,2,1,3,5,rgb)
SetGadgetText(2,"Text (RGB) : "+Str(Red(rgb))+","+Str(Green(rgb))+","+Str(Blue(rgb)))
EndSelect
EndIf
Until EventID=#PB_Event_CloseWindow
End
EndIf