Solved

How highlight keywords in rich edit control?

Posted on 1997-09-21
3
263 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
[X]
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
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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 …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 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