CStatic

动态修改控件风格

CStatic* pWndAli = (CStatic*)GetDlgItem(IDC_STATIC_ALIPAY);//WS_EX_DLGMODALFRAME
if (0 == pWndAli->ModifyStyleEx(WS_EX_DLGMODALFRAME, WS_EX_CLIENTEDGE, SWP_DRAWFRAME| SWP_FRAMECHANGED))
{
int iREt = GetLastError();
OutputDebugString(L"modify style failed.\n");
}
pWndAli->Invalidate();

修改字体和颜色

CBrush m_brush;
CFont m_font;

m_font.CreatePointFont(150,"华文行楷");//代表15号字体,华文行楷
m_font.CreatePointFont(270, _T("SimSun"));
m_brush.CreateSolidBrush(RGB(0,255,0));//画刷为绿色

添加WM_CTLCOLOR 消息响应

HBRUSH CYourDlg::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_STATICText)
{
pDC->SetBkColor(RGB(0,255,0));//文字背景色为绿色 需要返回对应颜色画刷,才能填充没有文字的背景
pDC->SetTextColor(RGB(255, 0, 0));//文字为红色
pDC->SelectObject(&m_font);//文字为15号字体,华文行楷
return m_brush; // 需要返回对应颜色画刷,才能画满完全的背景
}
// TODO: Return a different brush if the default is not desired
return hbr;
}