// TODO: Change any attributes of the DC here if( pWnd->GetDlgCtrlID()==IDC_EDIT1 ) { pDC->SetTextColor( colorSelect ); pDC->SetBkColor( colorSelect ); HBRUSH hBr = CreateSolidBrush(colorSelect); // 背景色 return (HBRUSH) hBr;}; // TODO: Return a different brush if the default is not desired return hbr; }
HBRUSH CAboutBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if( pWnd->GetDlgCtrlID()==IDC_EDIT1 )
{
pDC->SetTextColor( colorSelect );
pDC->SetBkColor( colorSelect );
HBRUSH hBr = CreateSolidBrush(colorSelect); // 背景色
return (HBRUSH) hBr;};
// TODO: Return a different brush if the default is not desired
return hbr;
}
HBRUSH hBr = CreateSolidBrush(colorSelect); // 背景色
一句是否有必要。小子也是初学者,请指教。
CTLCOLOR_DLG dialog box
CTLCOLOR_EDIT edit control
CTLCOLOR_LISTBOX list box
CTLCOLOR_MSGBOX message box
CTLCOLOR_SCROLLBAR scroll bar
CTLCOLOR_STATIC static text, frame, or rectangle现在为了突出显示文本框的显示号码,我们将文本框的文字背景设为黄色。步骤1、添加一个成员变量 HBRUSH m_hBrush;
步骤2、用Class Wizard为CGuessDlg加入WM_CTLCOLOR消息,并编辑OnCtlColor函数:HBRUSH CGuessDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(nCtlColor==CTLCOLOR_EDIT){
pDC->SetBkColor (RGB(255,255,0));//EDIT控件文字背景为黄色
return m_hBrush;
}
return CDialog::OnCtlColor (pDC,pWnd,nCtlColor);
}编译运行,怎么样,文本框内的文字均变为黄底了。关于对话框的外观我们将在以后再说。
可以直接改成你需要的颜色:(RGB(255,255,0))
用我提供的办法试试吧,很简单。。
在dialog类中加入变量 CFont m_editFont,然后在OnInitialDialog中加入如下语句:
m_editFont.CreateFont(-14, 0, 0, 0, 400, TRUE, FALSE, 0,\
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, \
DEFAULT_QUALITY, DEFAULT_PITCH|FF_SWISS, "Arial"); //设置了斜体
CEdit* pEdit=(CEdit*)GetDlgItem(YOUR_EDIT_ID);
pEdit->SetFont(&editFont);
就可以了。
pDC->SetBkColor( colorSelect ); //设置文字背景颜色
HBRUSH hBr = CreateSolidBrush(colorSelect); // 设置EDIT 编辑框底色