ListCtrl重载问题 我将Listctrl的Owner Draw Fixed属性设置为true, 重载了listctrl,为什么不能响应DrawItem虚函数?请高手帮帮忙,是不是还需要什么设置,我是在VS2008下开发的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ); 楼主看看是不是函数名,或者参数写错了。 ////////////////////////////////////////////////////////////////////.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函数,不知道是什么原因?高手帮忙解决啊,想了好几天了 用spy++看看CListCtrlEx这个窗口类的样式是不是真改成了Owner Draw Fixedvoid CListCtrlEx::PreSubclassWindow() 设断点跟一下这个函数调用了没有。 在CListCtrlEx::CListCtrlEx()前怎么少了://///////////////////////////////////////////////////////////////////////////// CListCtrlExIMPLEMENT_DYNCREATE(CListCtrlEx, CListCtrl)BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl) //{{AFX_MSG_MAP(CListCtrlEx) //}}AFX_MSG_MAPEND_MESSAGE_MAP() 创建list控件时添加LVS_OWNERDRAWFIXED风格,呵呵 消息循环中用ON_WM_DRAWITEM_REFLECT()代替ON_WM_DRAWITEM() 我是用的类向导添加的CListCtrlEx类,然后利用向导又重载了DrawItem和PreSubclassWindow两个虚函数,在PreSubclassWindow里面添加了ModifyStyle(NULL,LVS_OWNERDRAWFIXED, NULL)代码。结果设置断点后发现PreSubclassWindow函数可以进入,但是DrawItem函数不能进入,郁闷死了,都不知道是什么原因 原来变量m_List要从CListCtrl改为CListCtrlEx 我试了一下,把ListCtrl控件的类型改成Report时,可以进行DrawItem,但是我的ListCtrl是Small Icon,DrawItem就不能进入,不知道有没有人碰到过这种问题 求矩形绕中心旋转一定角度的代码 如何在多文档下去掉menubar? 一个线程结束后怎么重新执行 API编程 添加快捷键(键盘加速键)不成功 关于获得其它窗口DC等 急问!!!word开发问题(禁止拷贝和保存、另存为以及右键菜单) 动态二维结构数组,急 RichEdit问题,回答马上给分 谁用过DirectShow,给点指导或建议。 走投无路,还请高手搭救(急急急急急) button贴图问题 MFC DLL中的CFileDlg使用问题。(此DLL已经注入到游戏,用Home键呼出我们的窗口,在此窗口下有“加载”按钮调用CFileDlg)
LPDRAWITEMSTRUCT lpDrawItemStruct ); 楼主看看是不是函数名,或者参数写错了。
.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函数,不知道是什么原因?高手帮忙解决啊,想了好几天了
设断点跟一下这个函数调用了没有。
/////////////////////////////////////////////////////////////////////////////
// CListCtrlExIMPLEMENT_DYNCREATE(CListCtrlEx, CListCtrl)BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl)
//{{AFX_MSG_MAP(CListCtrlEx)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()