看看下面msdn2008中的一个代码段,CMyDlg::OnCtlColor函数传递进来的参数nctlcolor好像没有用到呀,另外return的HBRUSH)m_RedBrush.GetSafeHandle()或(HBRUSH)m_BlueBrush.GetSafeHandle()跟hbr这个句柄怎么联系起来的??
//change the background color of an edit control on the dialog
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->GetDlgCtrlID() == IDC_MYEDIT)
{
if (pWnd->IsWindowEnabled())
{
// Red brush for the background...
pDC->SetBkColor(RGB(255, 0, 0));
// m_pRedBrush is the CBrush object initialized with a red brush
// using CreateSolidBrush
return(HBRUSH)m_RedBrush.GetSafeHandle();
}
else
{
// Blue brush for the background...
pDC->SetBkColor(RGB(0, 0, 255));
// m_pBlueBrush is the CBrush object initialized with a blue
// brush using CreateSolidBrush
return (HBRUSH)m_BlueBrush.GetSafeHandle();
}
} return hbr;
}
//change the background color of an edit control on the dialog
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->GetDlgCtrlID() == IDC_MYEDIT)
{
if (pWnd->IsWindowEnabled())
{
// Red brush for the background...
pDC->SetBkColor(RGB(255, 0, 0));
// m_pRedBrush is the CBrush object initialized with a red brush
// using CreateSolidBrush
return(HBRUSH)m_RedBrush.GetSafeHandle();
}
else
{
// Blue brush for the background...
pDC->SetBkColor(RGB(0, 0, 255));
// m_pBlueBrush is the CBrush object initialized with a blue
// brush using CreateSolidBrush
return (HBRUSH)m_BlueBrush.GetSafeHandle();
}
} return hbr;
}
// This OnCtlColor handler will change the color of a static control
// with the ID of IDC_MYSTATIC. The code assumes that the CPenWidthsDlg
// class has an initialized and created CBrush member named m_brush.
// The control will be painted with red text and a background
// color of m_brush.
HBRUSH CPenWidthsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// Call the base class implementation first! Otherwise, it may
// undo what we're trying to accomplish here.
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // Are we painting the IDC_MYSTATIC control? We can use
// CWnd::GetDlgCtrlID() to perform the most efficient test.
if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
{
// 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); // Return handle to our CBrush object
hbr = m_brush;
} return hbr;
}
那么是否是应该这样:
hbr=(HBRUSH)m_RedBrush.GetSafeHandle();hbr=(HBRUSH)m_BlueBrush.GetSafeHandle();
然后再return hbr!??