Solved

Colored Text w/ Edit Boxes (MSVC++)

Posted on 1998-01-19
9
252 Views
Last Modified: 2013-12-03

  Currently in my windows program I need to "color" certain
letters in a read-only edit box I have in my dialog
based application.  So far, I've just been creating
objects of type CFont the same font as the dialog box,
figuring out the height/width of the font, and calling the GetDC function of the edit box, then over-writing the
appropriate text in the edit box with portions of the text
in different colors.

   As one could imagine this can be very tedious and its
hard to get everything lined up correctly!  The CEdit class
has a function for returning the topmost line which
is being viewed, so I can find that and make the changes
in my painting function, however CEdit has no function
for returning the horizontal scroll position.  And Horizontally, Edit boxes can be scrolled by pixel, not by column, and lining text up would be very tricky anyway.

  Soo, my question is, Is there any public domain class or
existic mfc class that I can use to just display text and
scroll through it just like CEdit does, and be able to
specify RGB values for characters/lines of text??  I DON'T
need the user to be able to input in such an object.

  Thanks in advance..
0
Comment
Question by:tcola
[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
  • 5
  • 3
9 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1410150
Why don't you use the Rich Edit control? That gives you more flexibility in controlling the colors of each character if you need it.
0
 

Author Comment

by:tcola
ID: 1410151
  I forgot about that!  I never really looked close enough
into the its class functions though to realize you can control
it that much.  I guess one would have to select the text
to be "colored" with the SetSel function and then
call the SetSelAttrib(?) function to change it.

   When I put a Rich Edit box in the MSCV Editor in my dialog and then go into the class wizard, I can't associate a CString variable with it??  How do I put text into the edit box??

  thanks
0
 

Author Comment

by:tcola
ID: 1410152
Since you don't seem to be responding to this I'm going to reopen the question.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 4

Accepted Solution

by:
tflai earned 50 total points
ID: 1410153
Look at the example Rich Edit Control codes at:
http://www.codeguru.com/richedit/richedit_toc.shtml
0
 

Author Comment

by:tcola
ID: 1410154
 How do I associate an object with my rich edit box in the
resource editor?  I tried doing it in the class editor but
the ID for the rich edit box only shows up in the events tab
and not the member variables tab, so I can't pick it to associate
a control object with it (?).
0
 
LVL 4

Expert Comment

by:tflai
ID: 1410155
Take the Rich Edit control out of the dialog
(with the resource editor), and then create the Rich edit control
using the Create method:
1) create a separate class for the rich edit control
2) define a variable (m_ctl) of the rich edit control class
3) call Create, like m_ctl.Create(...)
0
 

Author Comment

by:tcola
ID: 1410156
 Then you can't edit it in the resource editor, which is
something I want to be able to do so I don't have to recompile,
then modify, etc.
0
 
LVL 4

Expert Comment

by:tflai
ID: 1410157
Okay, if you have MSVC 5.0, there is Rich Edit Control on resource editor.  With MSVC 4.2-, you would have to add Rich Edit OLE control, or dynamically create one as shown below:
(Very little work is required.  All you need is some static control to be a placeholder for the rich edit control.  That way you would know exactly what position/size is will be as shown on the resource editor.)

// IDC_EDIT static box is a placeholder for the rich edit control
CWnd* pwnd = GetDlgItem( IDC_EDIT);
ASSERT( pwnd );

// Convert the screen co-ordinates to client co-ordinates
CRect rect;
pwnd->GetWindowRect( &rect );
ScreenToClient( &rect );
VERIFY( m_ctrlRichEdit.Create( ES_MULTILINE | ES_AUTOVSCROLL |
  ES_SUNKEN | ES_NOHIDESEL | WS_VISIBLE | WS_TABSTOP | WS_CHILD |
WS_BORDER, rect, this, IDC_EDIT ) );
0
 

Author Comment

by:tcola
ID: 1410158
I have MSVC++ 5.0
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Enable Clear Text in Win 8.1 7 47
Windows Process running 3 62
Is AWS.RDS considered a part of "Big Data"? 4 133
WPF issue with Trigger 2 130
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
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…

726 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