Coloring letters outputted by PRINT statements

Full BASIC does not supply with the faculty of coloring text output, some decorations can be done with dealing the Text output window as a RichEdit control of Windows if Decimal BASIC is later than ver. 5.3.2.
The following program colors the letters outpuyted red or blue.
100 DECLARE EXTERNAL SUB SetColor
110 FOR x=1 TO 10
120 CALL SetColor(255,0,0)
130 PRINT x,
140 CALL SetColor(0,0,255)
150 PRINT SQR(x)
160 NEXT x
170 END
180 
190 EXTERNAL SUB SetColor(R,G,B)
200 OPTION CHARACTER Byte
210 SUB SendMessage(hwnd,msg,wparam,lparam$)
220 ASSIGN "USER32.DLL","SendMessageA"
230 END SUB
240 LET EM_SETCHARFORMAT=BVAL("0444",16)
250 LET CHARFORMAT$=CHR$(60) & REPEAT$(CHR$(0),59)
260 LET CHARFORMAT$(8:8)=CHR$(64)
270 LET CHARFORMAT$(21:24)=CHR$(R) & CHR$(G) & CHR$(B) & CHR$(0)
280 CALL SendMessage(WinHandle("RICHEDIT"),EM_SETCHARFORMAT,1, CHARFORMAT$)
290 END sub

The parameters R, G, B in the external sub SetColor take integers between 0 and 255.

In the similar way, decorations such as underlined, bold faced, or oblique, can be done. Details are known by checking how Windows message EM_SETCHARFORMAT should be used.


Back