Solved

How highlight keywords in rich edit control?

Posted on 1997-09-21
3
255 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now