Solved

Syntax Highlighting in an edit box

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

732 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