我是在SDK下开发的,使用CreateWindow创建了一个COMBOBOX窗体,如何给它的背景帖幅图片呢?
Windows注册了的窗体有个默认的WndProc,处理了各种消息,所以我在外面无法处理WM_PAINT消息了.另外,如何给这个Combobox添加\删除项?谢谢!!!

解决方案 »

  1.   

    图片是一个很麻烦的问题,对于COMBOBOX的按钮和边框可以参照
    http://www.vckbase.com/document/viewdoc/?id=522 实现自绘
    使用子类化可以取得ComboBox中Edit控件的窗口
    对于Edit控件的背景可以参照
    http://www.vckbase.com/document/viewdoc/?id=360对于 ComboBox 添加/删除项可以向其
    ::SendMessage(hComboBox, CB_DELETESTRING, ...

    ::SendMessage(hComboBox, CB_INSERTSTRING, ...
    来处理
      

  2.   

    you can include 'windowsx.h' file in your project, search the string 'ComboBox_AddString', it's a marco and there are many powerful marcos in the file.
      

  3.   

    Processing the WM_DRAWITEM Message
    An owner-drawn combo box sends the WM_DRAWITEM message to its parent window or dialog box procedure each time the application must repaint a list item. The lParam parameter is a pointer to a DRAWITEMSTRUCT structure that identifies the control and list item. It also contains information needed to paint the item. The example in Creating a Square Meal Dialog Box displays the list-item text and the bitmap associated with the food group. 
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/usingcomboboxes.asp
      

  4.   

    这种情况派生类实现:.h
    class CComboBoxColor : public CComboBox
    {
        afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
    }
    -------------.cpp
    HBRUSH CComboBoxColor::CtlColor(CDC* pDC, UINT nCtlColor) 
    {
        pDC->SetBkColor(RGB(192,192,192));
        return NULL;
    }
    ---------------
      

  5.   

    映射WM_CTLCOLOR消息即可(设ComboBox的ID为IDC_COMBO1)
    HBRUSH CCb3Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    static HBRUSH cbhdr = ::CreateSolidBrush(RGB(255, 192, 150));
    CWnd *pParent = pWnd->GetParent(); if(pWnd->GetDlgCtrlID() == IDC_COMBO1 || 
       (pParent && pParent->GetDlgCtrlID() == IDC_COMBO1))
    {
    pDC->SetBkColor(RGB(255, 192, 150));
    return cbhdr;
    }
    return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    }
      

  6.   

    关键是子类化了也不能自己处理消息啊注意前提:我是在SDK下使用CreateWindow创建的COMBOBOX窗体,而不是MFC下的CComboBox!
    COMBOBOX是Windows自己注册的一种窗体,有一个自己的WndProc,所以虽然我自己分发了窗口消息,但是纤细还是没有进到我写的这个窗口函数里,是进了默认的WndProc,而这个默认的WndProc又不能像MFC里那么重载,所以没有办法处理楼上各位所说的消息。至于添加项的已经解决了!谢谢!
      

  7.   

    try the function SetWindowLong to override the control's message procedure.
      

  8.   

    SetWindowLong 我也试过,但是我把我自己的窗口函数名WndProc作为第3个参数总是编译不过去!很是郁闷!