coloring text in CEdit or....? 
Author Message
 coloring text in CEdit or....?

hello, could anyone "point" me in the right direction to learn how to
"colorize" text in a
 CEdit ctrl...... have been looking at CRichEditCtrl but cant seem to
assimilate any direction
  as to setting text color.... have looked at  The Code Project samples for
colorizing
  text but damn the code is fairly intimidating for a self taught rookie!
    If "dynamically" changing text color does truly take that much coding I
will have to "hack"
     my way through it I guess.... however a starting point would be greatly
appreciated as
      as I dont like to use code "verbatim" .... "re inventing the wheel" I
find truly helps me
       understand the code.  thx in advance D.Moore


Wed, 23 Nov 2005 19:59:03 GMT  
 coloring text in CEdit or....?
Hello,
The problem is CEdit (and Windows edit ctrl) does not supports not only
coloring, but also any intervation in drawing, other than complete
OwnerDraw. Using richedit does not solve the problem, since it very slow on
text bigger than 10 Kb. So most common way to do it is writing edit control
from the ground, from CWnd, handling all drawing and control tasks yourself.
This is not an easy deal, I can recommend you look for Crystal Edit control,
you can find it in CodeProject. From all such controls I have seen (and I
have seen a lot :-), this one have most clean code and approach. During my
work I had to modify and complete understand the code, and this impression
has not changed. But be prepared for hours of looking through 100Kb of
source code :-)

Igor Green,
Grig Software.
www.grigsoft.com
Compare It! + Synchronize It! : files and folders comparison never was
easier!

Quote:
----- Original Message -----

Newsgroups: microsoft.public.vc.mfc
Sent: Saturday, June 07, 2003 9:59 PM
Subject: coloring text in CEdit or....?

> hello, could anyone "point" me in the right direction to learn how to
> "colorize" text in a
>  CEdit ctrl...... have been looking at CRichEditCtrl but cant seem to
> assimilate any direction



Wed, 23 Nov 2005 17:40:25 GMT  
 coloring text in CEdit or....?
You can only set one text color for all the text in CEdit. I have found when trying to
learn the CRichEditCtrl that the most expedient route is to take the WordPad source and
study it, usually with the de{*filter*}.

If changing text color takes as much code as you say, it is unlikely you will ever be able
to "hack" together a solution that works. This is because the code shown probably *is* the
minimal solution.

Send me email and I'll send you a module I used for doing simple text formatting as I
added lines to an output file. I would boldface certain lines, and put others that
indicated errors in red. All it does is use the CHARFORMAT structure to change these
properties. It is too many lines to post here.
                                        joe

Quote:

>hello, could anyone "point" me in the right direction to learn how to
>"colorize" text in a
> CEdit ctrl...... have been looking at CRichEditCtrl but cant seem to
>assimilate any direction
>  as to setting text color.... have looked at  The Code Project samples for
>colorizing
>  text but damn the code is fairly intimidating for a self taught rookie!
>    If "dynamically" changing text color does truly take that much coding I
>will have to "hack"
>     my way through it I guess.... however a starting point would be greatly
>appreciated as
>      as I dont like to use code "verbatim" .... "re inventing the wheel" I
>find truly helps me
>       understand the code.  thx in advance D.Moore

Joseph M. Newcomer [MVP]

Web: http://www.*-*-*.com/
MVP Tips: http://www.*-*-*.com/


Wed, 23 Nov 2005 18:02:16 GMT  
 coloring text in CEdit or....?
If all you need is coloring of small amount of text (ex. in about box, or as
comments in other dialogs), richedit can be fine. However if you need full
text file coloring, try searching for another solution. Of course, try
richedit first, just in case I missed something in it's features :-)

--
Igor Green,
Grig Software.
www.grigsoft.com
Compare It! + Synchronize It! : files and folders comparison never was
easier!



Quote:
> You can only set one text color for all the text in CEdit. I have found
when trying to
> learn the CRichEditCtrl that the most expedient route is to take the
WordPad source and
> study it, usually with the de{*filter*}.

> If changing text color takes as much code as you say, it is unlikely you
will ever be able
> to "hack" together a solution that works. This is because the code shown
probably *is* the
> minimal solution.



Wed, 23 Nov 2005 18:23:45 GMT  
 coloring text in CEdit or....?
// MandatoryEdit.cpp : implementation file
//

#include "stdafx.h"

#include "MandatoryEdit.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

///////////////////////////////////////////////////////////
//////////////////
// CMandatoryEdit

CMandatoryEdit::CMandatoryEdit() : m_brush( RGB
(123,255,255))
{
        bCancelled = false;
        bValidationNoCheck = false;

Quote:
}

CMandatoryEdit::~CMandatoryEdit()
{

Quote:
}

BEGIN_MESSAGE_MAP(CMandatoryEdit, CEdit)
        //{{AFX_MSG_MAP(CMandatoryEdit)
        ON_WM_CTLCOLOR_REFLECT()
        ON_WM_SETFOCUS()
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()

///////////////////////////////////////////////////////////
//////////////////
// CMandatoryEdit message handlers

HBRUSH CMandatoryEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
        pDC->SetBkColor( RGB(248,248,255) );

        return m_brush;

Quote:
}

void CMandatoryEdit::OnKillFocus(CWnd* pNewWnd)
{
        CEdit::OnKillFocus(pNewWnd);

/*      if( bValidationNoCheck )
                return;

        if( ! pNewWnd )
                return;

        // if we are cancelling, no validation....
        if( pNewWnd && pNewWnd->GetDlgCtrlID() ==
IDCANCEL )
                return;

        // if user has pressed esc
        if( bCancelled )
                return;

        CString keyval;
        GetWindowText( keyval );

        bValidationNoCheck = true;

        if( keyval.IsEmpty() )
        {
                MessageBox( "Mandatory Field, Please enter
data", "Input error", MB_ICONSTOP|MB_OK  );
                SetFocus();
        }

        bValidationNoCheck = false;*/

Quote:
}

void CMandatoryEdit::OnSetFocus(CWnd* pOldWnd)
{
        CEdit::OnSetFocus(pOldWnd);

        SetCancel( false );    

Quote:
}

bool CMandatoryEdit::CheckValid( bool setfocus )
{
        CString keyval;
        GetWindowText( keyval );

        if( keyval.IsEmpty() )
        {
                MessageBox( "Mandatory Field, Please enter
data", "Input error", MB_ICONSTOP|MB_OK  );

                if( setfocus )
                        SetFocus();

                return false;
        }
        return true;

Quote:
}

BOOL CMandatoryEdit::PreCreateWindow(CREATESTRUCT& cs)
{
        cs.style &= ES_UPPERCASE;
        return CEdit::PreCreateWindow(cs);
Quote:
}

void CMandatoryEdit::SetBackColor( COLORREF rgb )
{
        m_EnableColor = true;
        m_brush.DeleteObject();
        m_brush.CreateSolidBrush( rgb );

Quote:
}

***************************************************
.h file...

#if !defined
(AFX_MANDATORYEDIT_H__AF4B2E69_66A6_11D3_93D7_00400551C439_
_INCLUDED_)
#define
AFX_MANDATORYEDIT_H__AF4B2E69_66A6_11D3_93D7_00400551C439__
INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MandatoryEdit.h : header file
//

///////////////////////////////////////////////////////////
//////////////////
// CMandatoryEdit window

class CMandatoryEdit : public CEdit
{
        CBrush m_brush;
        bool bCancelled;
// Construction
public:
        CMandatoryEdit();

// Attributes
public:
        bool bValidationNoCheck;

// Operations
public:
        void SetCancel( bool flg ) { bCancelled = flg; }

// Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CMandatoryEdit)
        protected:
        virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
        //}}AFX_VIRTUAL

// Implementation
public:
        bool CheckValid( bool setfocus = true);
        virtual ~CMandatoryEdit();
        void SetBackColor( COLORREF rgb );
          bool m_EnableColor;
        // Generated message map functions
protected:
        //{{AFX_MSG(CMandatoryEdit)
        afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
        afx_msg void OnKillFocus(CWnd* pNewWnd);
        afx_msg void OnSetFocus(CWnd* pOldWnd);
        //}}AFX_MSG

        DECLARE_MESSAGE_MAP()

Quote:
};

///////////////////////////////////////////////////////////
//////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional
declarations immediately before the previous line.

#endif // !defined
(AFX_MANDATORYEDIT_H__AF4B2E69_66A6_11D3_93D7_00400551C439_
_INCLUDED_)

In the dialog class use CMandatoryEdit instead of CEdit.
then you can play with that....



Wed, 23 Nov 2005 21:59:28 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Colored text in CEdit derived control

2. Background & Text color CEdit

3. CEdit text color

4. Changing text color in a CEdit box

5. Changing Background Color of CEdit - Problem With Double Clicking On Texts

6. Question on changing text color in CEdit Control

7. CEdit text color

8. CEdit text color

9. Disabled CEdit Text Color

10. CEdit and text color

11. CEdit Disabled Text Color

12. Colored text in MultiLine CEdit

 

 
Powered by phpBB® Forum Software