Solved

Colored Text w/ Edit Boxes (MSVC++)

Posted on 1998-01-19
9
250 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Does Microsoft Office 2016 support COM/ActiveX? 3 111
Handle Exceptions during instantiation 28 422
GUI: DIalog Stacking and Popping in MS C++ 4 80
windbg taking it's time 32 93
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

792 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