我在一个dialogbar上放了两个listbox,dialogbar停靠在顶部,现在我想改变这两个listbox的背景色和里面的字体色,该怎么做?
我试着获得了两个listbox得指针,然后调用setbkcolor改变背景色,但不行!
请高手指教!

解决方案 »

  1.   

    写个继承类
    ,使用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 ()
    }
      

  2.   

    获得了两个listbox得指针后,CDC dc(pList);
    dc.SetBkColor(..).不行?我不信。
      

  3.   

    完全可以的吗?我试过了.
    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;
    }
      

  4.   

    可是我用的不是dlg,我用的是SDI,请问如何对SDI得dialogbar重载OnCtlColor
      

  5.   

    tonyswe(tong) ( )应该也可以的
      

  6.   

    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
      

  7.   

    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));
    }
    可以的.
    (上面一段英文贴错了,不好意思)
      

  8.   

    可是我用的不是dlg,我用的是SDI,请问如何对SDI得dialogbar重载OnCtlColor
    关注
      

  9.   

    子类化listbox,使用ClassWizard 处理反射的WM_CTLCOLOR(=WM_CTLCOLOR)消息
    此消息对应函数如上我写的.
      

  10.   

    就是继承啊!使用ClassWizard,new class---输入你的类名,下面选择基类(就是CListBox)
      

  11.   

    我这样做了,是这样:
    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参数,而且实现不了预计的功能
      

  12.   

    有两个WM_CTLCOLOR,使用那个有等号的(=WM_CTLCOLOR)
      

  13.   

    我重载了=WM_CTLCOLOR,按照你说的方法还是不行呀?!
      

  14.   

    [email protected]
    我看看,能解决我会回复你明天,不能的话,只能说对不起了.
      

  15.   

    我重载了=WM_CTLCOLOR
    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));
    }
    在*号处设置间断,调试,发现窗口生成时,根本就没有经过这里!
      

  16.   

    没受到收到邮件!
    可能你根本没使用你的类.
    你的控件变量要用Mylist类.而不是CListBox类
      

  17.   

    关于控件的风格,最好用自绘的方式重载DrawItem函数
      

  18.   

    我是在cdialogbar上用了两个clistbox,好像无法给他们映射变量?