-2

I have searched on the Internet how to do this, but I can't find how.

I need to colour specific words in RichEdit, such as the words false and true.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
whispereq
  • 65
  • 1
  • 1
  • 7
  • Pro tip: google your subject line (after spelling it correctly). – Jesper Juhl Jun 02 '17 at 17:01
  • Aside from what Jesper had to say you should provide [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) when asking questions about a codding issue. If you have not tried any code thus far then you are asking your question a bit prematurely. – Mike - SMT Jun 02 '17 at 20:33
  • @SierraMountainTech I wanted something better then Memo editor so I needed full control over rendered and edited stuff so I have my own text editor class which renders to bitmap (and catches mouse and keyboard events) and mimics Borland IDE editor features (rectangular select included). I represent Syntax highlight like this: [missing syntax-highlighting for x86 assembly](https://meta.stackoverflow.com/q/348110/2521214) So in case you want to code it on your own create similar tables , then decode which type of string you got and chose its color for rendering accordingly – Spektre Jun 07 '17 at 08:39

1 Answers1

1

TRichEdit is not well-suited for syntax highlighting (use something more like SynEdit instead), but it can be done. Basically, you need to highlight the desired text, and then set the selected text's attributes, like color and formatting. You can do that with the TRichEdit::SelStart, TRichEdit::SelLength, and TRichEdit::SelAttributes properties. Or you can use the corresponding Win32 API EM_EXSETSEL and EM_SETCHARFORMAT messages directly.

See Robert Dunn's excellent article on this very topic: "Faster Rich Edit Syntax Highlighting". The Original article first appeared in the C++Builder Journal in October 1999, and is also available for download on Robert's "Yet Another Code Site" website (which is archived on my website).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770