HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor==CTLCOLOR_EDIT){
pDC->SetBkColor(RGB(255,0,0));
return m_hYellowBrush;
}
if (nCtlColor==CTLCOLOR_DLG){
pDC->SetBkColor(RGB(255,255,0));
return m_hRedBrush;
} HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
return hbr;
}在OnInitDialog()中初始化m_hRedBrush和m_hYellowBrush如下:
CBrush m_YellowBrush(RGB(255,255,0));
CBrush m_RedBrush(RGB(255,0,0));
HBRUSH m_hYellowBrush=(HBRUSH)m_YellowBrush;
HBRUSH m_hRedBrush=(HBRUSH)m_RedBrush;还是改变不了~为什么~简单问题50分相赠
{
if (nCtlColor==CTLCOLOR_EDIT){
pDC->SetBkColor(RGB(255,0,0));
return m_hYellowBrush;
}
if (nCtlColor==CTLCOLOR_DLG){
pDC->SetBkColor(RGB(255,255,0));
return m_hRedBrush;
} HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
return hbr;
}在OnInitDialog()中初始化m_hRedBrush和m_hYellowBrush如下:
CBrush m_YellowBrush(RGB(255,255,0));
CBrush m_RedBrush(RGB(255,0,0));
HBRUSH m_hYellowBrush=(HBRUSH)m_YellowBrush;
HBRUSH m_hRedBrush=(HBRUSH)m_RedBrush;还是改变不了~为什么~简单问题50分相赠
// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_DLG)
{
// Set the text color to red
pDC->SetTextColor(RGB(255, 0, 0));
// Set the background mode for text to transparent
// so background will show thru.
pDC->SetBkMode(TRANSPARENT);
pDC->SetBkColor(RGB(255,255,0));
// Return handle to our CBrush object
hbr = m_brush;
}
// TODO: Return a different brush if the default is not desired
return hbr;