Solved

How highlight keywords in rich edit control?

Posted on 1997-09-21
3
261 Views
Last Modified: 2013-12-03
This is a question relating to a program being written in C (Win32SDK) for Win95/NT4. I want to set up a rich edit control so that if the user types one of a number of keywords, the word will change color - much as in a program script. Initial thoughts are that a lot of programming will be involved - a new thread to stream out the text on each change/update, a routine to check for keywords, select them (selection hidden) and use a CHARFORMAT on the selection before restoring caret to where it was. Or is there a simpler way?! I feel it probably needs a thread because if there is a lot of text, it may take a while to check it all. But streaming it out on each change seems over the top; however WM_GETTEXT would only get the first 64kb or so. Any ideas? Thanks!
0
Comment
Question by:McKean
  • 2
3 Comments
 
LVL 4

Expert Comment

by:davmarc
ID: 1406954
I strongly suggest you to buy Stingray Software's "Objective Edit". It does what you want, and it is certainly worth the money it costs.

Coding it yourself would likely drive you crazy. There is a lot of work to do for every keystroke typed by the user, worry about the modification of existing words and, last but not least, speed. The VisualStudio IDE doesn't even use a RichEdit control (in the source editor) mostly for performance issues!

Davide Marcato.
0
 

Author Comment

by:McKean
ID: 1406955
Thanks Davide - I checked out Objective Edit, but it's MFC only; my code is in straight C, so I don't think it can be used. Thanks for help though!
0
 
LVL 4

Accepted Solution

by:
davmarc earned 200 total points
ID: 1406956
This is an excerpt of the response Mike Blaszczak gave to a similar question some time ago (coming from the MFC-l mailing list):

-------------------------------------------------------

Your code needs to:
    turn off redraw for the control
    programatically save the user's selection
    select the code you'd like to format
    format it
    restore the users selection
    turn on redraw
    force a redraw
And it needs to do this for every bit of formatting you'd like to enforce. Since you're doing this interactively with the user, you'll need to do it as the user types every single keystroke!  That means you'll end up with code like this:
    get the user's character
    parse the code with the new character added
    if the syntax changes
       do the code above

-------------------------------------------------------

This should point you on the right direction. Now work on each step...good luck.

Davide Marcato.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question