在msdn上查了半天也没找到:( 
什么样的情况会触发WM_DRAWITEM消息呀

解决方案 »

  1.   

    CWnd::OnDrawItem
    This method is called by the framework for the owner of an owner-draw button control, combo-box control, list-box control, or menu when a visual aspect of the control or menu has changed. afx_msg void OnDrawItem( 
    int nIDCtl, 
    LPDRAWITEMSTRUCT lpDrawItemStruct ); 也就是说,如果你的ListCtrl如果是具有Owner Draw属性的,就会在窗体就会在这个ListCtrl需要重画的任何时候响应OnDrawItem
    在这里边可以处理
    ODT_BUTTON   Owner-drawn button 
    ODT_COMBOBOX   Owner-drawn combo box 
    ODT_LISTBOX   Owner-drawn list box 
    ODT_MENU   Owner-drawn menu 
    ODT_LISTVIEW   List view control 
    ODT_STATIC   Owner-drawn static control 
    ODT_TAB   Tab control 
    等类型的具有Owner Draw属性的控件。
      

  2.   

    如你在ListCtrl的属性页的Style页Owner Draw选中Fixed
    然后添加代码:
    void CListCtrlOwnerDrawDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    // TODO: Add your message handler code here and/or call default if (lpDrawItemStruct->CtlType == ODT_LISTBOX)
    {
    HBRUSH          hBrush ;
    hBrush=CreateSolidBrush(RGB(213,192,228));
    hBrush=(HBRUSH) SelectObject (lpDrawItemStruct->hDC,hBrush);
    SetBkColor(lpDrawItemStruct->hDC,RGB(213,192,228));
    SetTextColor(lpDrawItemStruct->hDC,RGB(0,0,255));
    Rectangle(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
    DeleteObject(SelectObject(lpDrawItemStruct->hDC,hBrush));
    }}点一下ListCtrl就可以看到结果了,这只是一个简单的示例,具体要你自己实现。
      

  3.   

    我选中了Owner_Draw风格,在OnDrawItem()函数中设置了断点,可调试的时候并没有停在我设断点的位置,怎么回事
      

  4.   

    只有当你的Owner Draw属性的控件需要重画的时候,才会进去
    ListCtrl的Item不为空就可以进去了。