OnCtlColor will not be called for the list box of a drop-down combo box because the drop-down list box is actually a child of the combo box and not a child of the window. To change the color of the drop-down list box, create a CComboBox with an override of OnCtlColor that checks for CTLCOLOR_LISTBOX in the nCtlColor parameter. In this handler, the SetBkColor member function must be used to set the background color for the text.我try it
,使用ClassWizard 处理反射的WM_CTLCOLOR(=WM_CTLCOLOR)消息并指定新的绘画
属性。
HBRUSH CMyListBox : : CtlColor (CDC* pDC, UINT nCtlColor )
{
pDC—>SetTextColor (m_clrFore);
pDC—>SetBkColor (m_clrBack);
return (HBRUSH) m_brush.GetSafeHandle ()
}
dc.SetBkColor(..).不行?我不信。
HBRUSH CListDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(::GetDlgItem(this->m_hWnd,IDC_LIST1)==pWnd->m_hWnd)
{
pDC->SetTextColor(RGB(0,145,0));
pDC->SetBkColor(RGB(121,0,0));
}
return hbr;
}
{
pDC->SetTextColor (RGB(130,0,0));
pDC->SetBkColor (RGB(0,130,0)); return CreateSolidBrush(RGB(0,0,130));
}
可以的.
(上面一段英文贴错了,不好意思)
关注
此消息对应函数如上我写的.
HBRUSH CMylist::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
pDC->SetTextColor (RGB(130,0,0));
pDC->SetBkColor (RGB(0,130,0)); return CreateSolidBrush(RGB(0,0,130));}
我这个函数,怎么多一个CWnd* pWnd参数,而且实现不了预计的功能
我看看,能解决我会回复你明天,不能的话,只能说对不起了.
HBRUSH Mylist::CtlColor(CDC* pDC, UINT nCtlColor)
{
pDC->SetTextColor (RGB(130,0,0));
* pDC->SetBkColor (RGB(0,130,0)); return CreateSolidBrush(RGB(0,0,130));
}
在*号处设置间断,调试,发现窗口生成时,根本就没有经过这里!
可能你根本没使用你的类.
你的控件变量要用Mylist类.而不是CListBox类