Here is a simple function to set the background color of selected text in a RichEdit control.
’ ret„h SetColorBack rgb;r;g;b;h
[1] © Set Backgroud color of RichEdit selection
[2] © h=Œwi 'hwnd' of the RichEdit Control
[3] © r g b are red, green, blue values, 0-255.
[4] (r g b)„3†rgb
[5] :if 0=Œnc 'h' ª h„Œwi 'hwnd' ª :end © assumes Œwself„'rich edit control'
[6] ret„Œwcall 'EM_SETCHARFORMAT' h 'SCF_SELECTION' (Œav[Œio+1 6 1 56 1 1 1 17/84 0 4 0 r g b 0])
’
Here is a demonstration of the function:
’ RichEdit
[1]
[2] Œwself„'fm' Œwi 'Create' 'Form' ('size' 4 60)
[3] z„Œwi 'size'
[4] Œwself„'.red' Œwi 'Create' 'RichEdit'
[5] Œwi 'where' 0.5 1 , z-1 2
[6] Œwi 'text' 'This is a test of the RichEdit control'
[7]
[8] Œwi 'selection' 10 5
[9] SetColorBack 255 0 0 © red
[10]
[11] Œwi 'selection' 22 8
[12] SetColorBack 255 255 0 © yellow
[13]
[14] Œwi 'selection' 31 7
[15] SetColorBack 0 255 255 © aqua
’
This part of the code in SetColorBack is creating the CHARFORMAT2 Windows Structure, specifically to set the back ground color in this instance, it can be modified to change many other properties in the RichEdit control:
(Œav[Œio+1 6 1 56 1 1 1 17/84 0 4 0 r g b 0])