Solved

Colored Text w/ Edit Boxes (MSVC++)

Posted on 1998-01-19
9
249 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
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

772 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