成员变量 CBrush m_Brush; COLORREF m_BackColor;添加viturl function virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult);BOOL CTttView::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) { // TODO: Add your specialized code here and/or call the base class if (message != WM_CTLCOLOREDIT) { return CEditView::OnChildNotify(message, wParam, lParam, pLResult); } HDC hdcChild = (HDC)wParam; // Text is black – you can modify this by adding another variable for text color SetTextColor(hdcChild, m_txtColor); SetBkColor(hdcChild, m_BackColor); return TRUE; return CEditView::OnChildNotify(message, wParam, lParam, pLResult); } 处理WM_ERASEBKGNDBOOL CTttView::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default CBrush brush (m_BackColor );// Select the brush into the device context . CBrush* pOldBrush = pDC->SelectObject (&brush);// Get the area that needs to be erased . CEdit *pedit=&(GetEditCtrl()); CRect reClip ; pedit->GetClientRect(&reClip); pedit->ClientToScreen(&reClip); ScreenToClient(&reClip); //pDC->GetClipBox(&reClip);//Paint the area. pDC-> PatBlt (reClip.left , reClip.top , reClip.Width ( ) , reClip.Height ( ) , PATCOPY );//Unselect brush out of device context . pDC->SelectObject (pOldBrush );return TRUE; return CEditView::OnEraseBkgnd(pDC); }初始化m_BackColor,m_txtColor void CTttView::OnInitialUpdate() { CEditView::OnInitialUpdate(); m_BackColor=RGB(255,0,0); m_txtColor=RGB(0,0,255); // TODO: Add your specialized code here and/or call the base class
CBrush m_Brush;
COLORREF m_BackColor;添加viturl function
virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult);BOOL CTttView::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
{
// TODO: Add your specialized code here and/or call the base class
if (message != WM_CTLCOLOREDIT)
{
return CEditView::OnChildNotify(message, wParam, lParam, pLResult);
}
HDC hdcChild = (HDC)wParam;
// Text is black – you can modify this by adding another variable for text color
SetTextColor(hdcChild, m_txtColor);
SetBkColor(hdcChild, m_BackColor);
return TRUE; return CEditView::OnChildNotify(message, wParam, lParam, pLResult);
}
处理WM_ERASEBKGNDBOOL CTttView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CBrush brush (m_BackColor );// Select the brush into the device context .
CBrush* pOldBrush = pDC->SelectObject (&brush);// Get the area that needs to be erased .
CEdit *pedit=&(GetEditCtrl());
CRect reClip ;
pedit->GetClientRect(&reClip);
pedit->ClientToScreen(&reClip);
ScreenToClient(&reClip);
//pDC->GetClipBox(&reClip);//Paint the area.
pDC-> PatBlt (reClip.left , reClip.top ,
reClip.Width ( ) , reClip.Height ( ) , PATCOPY );//Unselect brush out of device context .
pDC->SelectObject (pOldBrush );return TRUE;
return CEditView::OnEraseBkgnd(pDC);
}初始化m_BackColor,m_txtColor
void CTttView::OnInitialUpdate()
{
CEditView::OnInitialUpdate();
m_BackColor=RGB(255,0,0);
m_txtColor=RGB(0,0,255);
// TODO: Add your specialized code here and/or call the base class
}
可以通过改变m_BackColor,m_txtColor来设定背景色