Article ID: 117778
Article Last Modified on 11/21/2006
// editdlg.h : header file
//
////////////////////////////////////////////////////////////////////////
///
// CEditDialog dialog
class CEditDialog : public CDialog
{
// Construction
public:
CEditDialog(CWnd* pParent = NULL); // standard constructor
// Add a CBrush* to store the new background brush for edit controls.
CBrush* m_pEditBkBrush;
// Dialog Data
//{{AFX_DATA(CEditDialog)
enum { IDD = IDD_EDITDIALOG };
// NOTE: The ClassWizard will add data members here.
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEditDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CEditDialog)
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnDestroy();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
// editdlg.cpp : implementation file
//
#include "stdafx.h"
#include "mdi.h"
#include "editdlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////////////////////////////////////
// CEditDialog dialog
CEditDialog::CEditDialog(CWnd* pParent /*=NULL*/)
: CDialog(CEditDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CEditDialog)
// NOTE: The ClassWizard will add member initialization here.
//}}AFX_DATA_INIT
// Instantiate and initialize the background brush to black.
m_pEditBkBrush = new CBrush(RGB(0, 0, 0));
}
void CEditDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEditDialog)
// NOTE: The ClassWizard will add DDX and DDV calls here.
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEditDialog, CDialog)
//{{AFX_MSG_MAP(CEditDialog)
ON_WM_CTLCOLOR()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////
// CEditDialog message handlers
HBRUSH CEditDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
switch (nCtlColor) {
case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
// Set color to green on black and return the background
brush.
pDC->SetTextColor(RGB(0, 255, 0));
pDC->SetBkColor(RGB(0, 0, 0));
return (HBRUSH)(m_pEditBkBrush->GetSafeHandle());
default:
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
}
void CEditDialog::OnDestroy()
{
CDialog::OnDestroy();
// Free the space allocated for the background brush
delete m_pEditBkBrush;
}Additional query words: CEdit
Keywords: kbhowto kbuidesign kbcode KB117778