Solved

Syntax Highlighting in an edit box

Posted on 2003-10-22
4
306 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

746 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

11 Experts available now in Live!

Get 1:1 Help Now