我将Listctrl的Owner Draw Fixed属性设置为true, 重载了listctrl,为什么不能响应DrawItem虚函数?请高手帮帮忙,是不是还需要什么设置,我是在VS2008下开发的。

解决方案 »

  1.   

    virtual void DrawItem( 
    LPDRAWITEMSTRUCT lpDrawItemStruct ); 楼主看看是不是函数名,或者参数写错了。
      

  2.   

    ////////////////////////////////////////////////////////////////////
    .h头文件//
    class CListCtrlEx :
    public CListCtrl
    {
    public:
    CListCtrlEx(void);
    ~CListCtrlEx(void);
    virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
    protected:
    virtual void PreSubclassWindow();
    private:
    void DrawBackGround(CDC *pDC, CRect rect);
    };
    ////////////////////////////////////////////////
    .cpp文件
    #include "StdAfx.h"
    #include "ListCtrlEx.h"CListCtrlEx::CListCtrlEx(void)
    {
    }CListCtrlEx::~CListCtrlEx(void)
    {
    }void CListCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
    // TODO:  Add your code to draw the specified item ASSERT(lpDrawItemStruct); CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect rect = lpDrawItemStruct->rcItem;
    DrawBackGround(pDC, rect);}void CListCtrlEx::PreSubclassWindow()
    {
    // TODO: Add your specialized code here and/or call the base class ModifyStyle(NULL,LVS_OWNERDRAWFIXED, NULL); CListCtrl::PreSubclassWindow();
    }void CListCtrlEx::DrawBackGround(CDC *pDC, CRect rect)
    {
    CBrush brush;
    brush.CreateSolidBrush(RGB(255,0,0));
    pDC->FillRect(&rect, &brush);
    brush.DeleteObject();
    }//////////////////
    Listctrl的Owner Draw Fixed属性设置为true,怎么都不能进DrawItem函数,不知道是什么原因?高手帮忙解决啊,想了好几天了
      

  3.   

    用spy++看看CListCtrlEx这个窗口类的样式是不是真改成了Owner Draw Fixedvoid CListCtrlEx::PreSubclassWindow() 
    设断点跟一下这个函数调用了没有。
      

  4.   

    在CListCtrlEx::CListCtrlEx()前怎么少了:
    /////////////////////////////////////////////////////////////////////////////
    // CListCtrlExIMPLEMENT_DYNCREATE(CListCtrlEx, CListCtrl)BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl)
    //{{AFX_MSG_MAP(CListCtrlEx)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
      

  5.   

    创建list控件时添加LVS_OWNERDRAWFIXED风格,呵呵
      

  6.   

    消息循环中用ON_WM_DRAWITEM_REFLECT()代替ON_WM_DRAWITEM()
      

  7.   

    我是用的类向导添加的CListCtrlEx类,然后利用向导又重载了DrawItem和PreSubclassWindow两个虚函数,在PreSubclassWindow里面添加了ModifyStyle(NULL,LVS_OWNERDRAWFIXED, NULL)代码。结果设置断点后发现PreSubclassWindow函数可以进入,但是DrawItem函数不能进入,郁闷死了,都不知道是什么原因
      

  8.   

    原来变量m_List要从CListCtrl改为CListCtrlEx
      

  9.   

    我试了一下,把ListCtrl控件的类型改成Report时,可以进行DrawItem,但是我的ListCtrl是Small Icon,DrawItem就不能进入,不知道有没有人碰到过这种问题