Solved

Syntax Highlighting in an edit box

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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