文本颜色和文本字体以及文本编辑框的背景色可以在父类的OnCtlColor中设置
HBRUSH CMFCDlgDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_MYEDIT)
{
pDC->SetTextColor(RGB(0,0,255)); //设置字体颜色
pDC->SelectObject(&m_Font); //设置字体样式
//设置背景色
pDC->SetBkMode(TRANSPARENT);
return CreateSolidBrush(RGB(0,255,0));
}
return hbr;
}
==============
CFont m_EditFontTime;
//编辑框内容设置字体---------------------------------------
m_EditFontTime.CreateFont(120, 0, 0, 0, 700,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS, _T("楷体"));
CEdit *m_EditTime=(CEdit *)GetDlgItem(IDC_EDIT1);
m_EditTime->SetFont(&m_EditFontTime);
CFont m_EditFontTime;
//编辑框内容设置字体---------------------------------------
m_EditFontTime.CreateFont(120, 0, 0, 0, 700,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS, _T("楷体"));
CEdit *m_EditTime=(CEdit *)GetDlgItem(IDC_EDIT1);
m_EditTime->SetFont(&m_EditFontTime);
需要响应对话框的WM_CTLCOLOR消息
编辑框的颜色就在CTLCOLOR_EDIT分支中进行处理
SetTextColor
改变画笔的颜色即可
aColor = RGB(255,0,180);
if(!aPen.CreatePen( PS_SOLID,this->m_Pen,aColor))
{
AfxMessageBox(_T("Pen creation faild drawing a cure"),MB_OK);
AfxAbort();
}
CPen * pOldPen = pDC->SelectObject(&aPen);