Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How highlight keywords in rich edit control?

Posted on 1997-09-21
3
260 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…

829 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