// TODO: Change any attributes of the DC here if (pWnd == this) return brush; else if (pWnd == GetDlgItem(IDC_1)) return brush1; else if (pWnd == GetDlgItem(IDC_2)) return brush2; // TODO: Return a different brush if the default is not desired return hbr; } brush 代表背景画刷,brush1代表控件1画刷
// TODO: Change any attributes of the DC here if (pWnd->GetDlgCtrlID() == IDD_CBRUSHDEMO_DIALOG) return hbr; else if(pWnd->GetDlgCtrlID() == IDC_1) { //AfxMessageBox("11"); return blueBrush; } else if (pWnd->GetDlgCtrlID() == IDC_2) return redBrush;
// TODO: Return a different brush if the default is not desired}
// TODO: Change any attributes of the DC here if (pWnd == this) return brush; else if(pWnd->GetDlgCtrlID() == IDC_IDC_1) { //AfxMessageBox("11"); return blueBrush; } else if (pWnd->GetDlgCtrlID() == IDC_2) return redBrush;
// TODO: Return a different brush if the default is not desired}
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd == this)
return brush;
else if (pWnd == GetDlgItem(IDC_1))
return brush1;
else if (pWnd == GetDlgItem(IDC_2))
return brush2;
// TODO: Return a different brush if the default is not desired
return hbr;
}
brush 代表背景画刷,brush1代表控件1画刷
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
hbr = ::CreateSolidBrush ( m_crBk ); //m_crBk是我在别处定义的一个画刷。if (pWnd == this)
{
HBRUSH brush = ::CreateSolidBrush ( m_crBk );
MessageBox("123");//这里有反应,说明对话框背景已经发生了重绘。 return brush;
}
else if (pWnd == GetDlgItem(IDC_1))
{
HBRUSH brush = ::CreateSolidBrush ( RGB(255,255,255) );
MessageBox("456");//这里居然都弹不出来,说明根本没有执行这段程序。 return brush;
}
else if (pWnd == GetDlgItem(IDC_2))
{
HBRUSH brush = ::CreateSolidBrush ( RGB(0,0,0) );
return brush;
}return hbr;运行后我发现,整个对话框包括所有控件在内的背景都被绘制成了m_crBk 的颜色。
但是控件背景并没有被单独绘制。
原因何在?
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID() == IDD_CBRUSHDEMO_DIALOG)
return hbr;
else if(pWnd->GetDlgCtrlID() == IDC_1)
{
//AfxMessageBox("11");
return blueBrush;
}
else if (pWnd->GetDlgCtrlID() == IDC_2)
return redBrush;
// TODO: Return a different brush if the default is not desired}
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd == this)
return brush;
else if(pWnd->GetDlgCtrlID() == IDC_IDC_1)
{
//AfxMessageBox("11");
return blueBrush;
}
else if (pWnd->GetDlgCtrlID() == IDC_2)
return redBrush;
// TODO: Return a different brush if the default is not desired}