
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....