Solved

How highlight keywords in rich edit control?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

864 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

18 Experts available now in Live!

Get 1:1 Help Now