View类下动态创建的CStatic m_StaticCtrl如何设置背景色
创建了单文档程序MyApp,在MyAppView类下,手动创建了CStatic m_StaticCtrl,请问如何设置m_StaticCtrl背景色
[解决办法]
响应 WM_CTLCOLOR
HBRUSH MyAppView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(pWnd->GetDlgCtrlID() == m_StaticCtrl.GetDlgCtrlID())
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(200, 0, 0));
hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
}
// TODO: Return a different brush if the default is not desired
return hbr;
}