vc中如何改变对话框控件的颜色
1个回答
展开全部
pDC->SetTextColor(RGB(255, 0, 0));}// TODO: 在此更改 DC 的任何特性 // TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
} 但是按钮控件是个例外,要想改变按钮控件的颜色或者是字体颜色,需要自己从CButton派生出自己的BUTTON类,然后再这个派生类中重写DrawItem函数,最后在对话框中按钮控件关联派生类对象,具体代码如下,这里是把对话框背景设为绿色,文字设为红色 void CCMDaButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{ // TODO: 添加您的代码以绘制指定项 UINT uStyle = BS_DEFPUSHBUTTON ;//DFCS_BUTTONPUSH; // This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON); // If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED; // Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
DFC_BUTTON, uStyle); CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); // Get the button's text.
CString strText;
GetWindowText(strText); // Draw the button text using the text color red.
CBrush B;CRect rect;
CRect focusRect;
focusRect.CopyRect(&lpDrawItemStruct->rcItem);
DrawFocusRect(lpDrawItemStruct->hDC, (LPRECT)&focusRect);
focusRect.left += 4;
focusRect.right -= 4;
focusRect.top += 4;
focusRect.bottom -= 4; rect.CopyRect(&lpDrawItemStruct->rcItem);
pDC->Draw3dRect(rect, ::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_BTNHILIGHT));
//画刷为绿色
B.CreateSolidBrush(RGB(0,255,0));
::FillRect(lpDrawItemStruct->hDC,&rect, (HBRUSH)B.m_hObject);
::SetBkMode(lpDrawItemStruct->hDC,TRANSPARENT);
//文本为红色
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询