Solved

Syntax Highlighting in an edit box

Posted on 2003-10-22
4
307 Views
Last Modified: 2013-11-20
I have an edit box which is displaying piped output from an external process.  I would like to get some syntax highlighting into the text.  I have been messing around with this module http://www.codeguru.com/richedit/SyntaxColorizer.html.  It works fine with my test case executable, but when I use it with my actual executable it does not work(it's a simple swap of executables or recoding on the MFC app side of things).  I was wondering if anyone knows what I need to do or if there are other alternatives to change colors or certain words in an edit box.

Note: the output is not source code, I just need to highlight error messages and certain values displayed.

thanks in advance
0
Comment
Question by:Logick
  • 2
4 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9604800
An edit box only has one font and one colour at any one time.  Use a RichEdit control for multiple font/colour display.
0
 
LVL 3

Expert Comment

by:komar
ID: 9607074
Check the article at link: http://www.codeproject.com/wtl/wtleditor.asp

The article introduces a library called CodeMax that can be used for syntax highlighting. There you can find some demo project and documentation for the library.

- Khalid Omar
0
 

Author Comment

by:Logick
ID: 9608425
To AndyAinscow:
I am aware that I need to use RichEdit which is what I am using, but still I have not found a way to highlight certain words in my program.

To komar:
Thanks for the link it seems useful but codemax seems a bit of overkill for what I need it for, anything simpler?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 125 total points
ID: 9608522
Hi Logick, an excerpt from your question:
I have an edit box


This is a snippet from a RichEdit view based app I did some time ago.  It could be of use
      CRichEditCtrl& ctlREdt = GetRichEditCtrl();

      CHARFORMAT cf, cfOld;
      cf.cbSize = sizeof(CHARFORMAT);
      cfOld.cbSize = sizeof(CHARFORMAT);

      ctlREdt.GetSelectionCharFormat(cfOld);

      cf.dwMask = CFM_COLOR | CFM_SIZE | CFM_FACE;
      cf.crTextColor = RGB(0, 0, 0);
      cf.yHeight = 10 * 20;      //Heights are in 1/20 'th of a point
      _tcscpy(cf.szFaceName, _T("Arial"));

      ctlREdt.SetSelectionCharFormat(cf);
      ctlREdt.ReplaceSel(szMessage);

      ctlREdt.SetSelectionCharFormat(cfOld);



and another snippet
      CRichEditCtrl& ctlREdt = GetRichEditCtrl();

      //Force it to append to the end of the edit control if the user has selected anything with the mouse
      int iLastLine = ctlREdt.GetLineCount() - 1;
      if(iLastLine > 0)
      {
            long lLastChar = ctlREdt.LineIndex(iLastLine) + ctlREdt.LineLength(iLastLine);
            ctlREdt.SetSel(lLastChar, lLastChar);
      }

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

947 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

19 Experts available now in Live!

Get 1:1 Help Now