我新建了一个类CPicListCtrl,重载了DrawItem()函数
头文件如下:
class CPicListCtrl : public CListCtrl
{
// Construction
public:
CPicListCtrl();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPicListCtrl)
//}}AFX_VIRTUAL// Implementation
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
virtual ~CPicListCtrl(); // Generated message map functions
protected:
//{{AFX_MSG(CPicListCtrl)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};
DrawItem()函数内容如下:
void CPicListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CRect rcClient,rcCol;
LV_COLUMN lvc;
CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
GetClientRect(&rcClient);
rcCol.right = rcClient.right;
CRgn rgn;
rgn.CreateRectRgnIndirect(&rcCol);
pDC->SelectClipRgn(&rgn);
rgn.DeleteObject();
pDC->FillRect(rcCol, &CBrush(RGB(255,255,108)));
for(int nColumn = 1; GetColumn(nColumn, &lvc);  nColumn++)
{
rcCol.left = rcCol.right;
rcCol.right += lvc.cx;
if( (nColumn) % 2 )
    pDC->FillRect(rcCol, &CBrush(RGB(255,255,108))); }
}然后在另外一个对话框中,有一个CListCtrl控件,为如下类型:CPicListCtrl  m_pduList;结果没有改变颜色,请问是哪里出错了.我跟踪发现好像DrawItem()根本没有调用.这个函数不是控件自己本身调用吗?哪位高手给我看看问题出在什么地方

解决方案 »

  1.   

    DrawItem()没有调用?? 加上允许扩充的属性
      

  2.   

    我把owner draw fixed 勾上了,但数据没有进去.那怎么把数据加进去呢?
    我是这样加的数据:
    CString strText;
    for(i=0;i< 5;i++)
    {
    strText.Format("%d ",i+1);
    m_pduList.InsertItem(LVIF_TEXT|LVIF_STATE,i,strText,0,LVIS_SELECTED,0,0);
    for(int j=1;j<g_iNumOfColumns;j++)
    {
    strText.Format(_T(" %d %d"),i,j);
    m_pduList.SetItemText(i,j,strText); }
    }
      

  3.   

    如果我把owner draw fixed 勾去掉了,就能显示数据了