class CBdxListCtrl : public CListCtrl
{DECLARE_DYNCREATE(CBdxListCtrl)
// Construction
public:
CBdxListCtrl();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBdxListCtrl)
public: protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CBdxListCtrl(); // Generated message map functions
protected:
//{{AFX_MSG(CBdxListCtrl)
afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
private:
bool m_bAllowEdit;
bool m_bAllowDrag;
CRect m_rcEdit;
};
重载了DrawItem()函数并设置自画类型,为何
DrawItem()函数不被调用呢?
BOOL CBdxListCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~LVS_TYPEMASK;
cs.style |= LVS_REPORT | LVS_OWNERDRAWFIXED;
return CListCtrl::PreCreateWindow(cs);
}
{DECLARE_DYNCREATE(CBdxListCtrl)
// Construction
public:
CBdxListCtrl();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBdxListCtrl)
public: protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CBdxListCtrl(); // Generated message map functions
protected:
//{{AFX_MSG(CBdxListCtrl)
afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
private:
bool m_bAllowEdit;
bool m_bAllowDrag;
CRect m_rcEdit;
};
重载了DrawItem()函数并设置自画类型,为何
DrawItem()函数不被调用呢?
BOOL CBdxListCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~LVS_TYPEMASK;
cs.style |= LVS_REPORT | LVS_OWNERDRAWFIXED;
return CListCtrl::PreCreateWindow(cs);
}
问题1。需要坐标转换
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
LVHITTESTINFO pHitTestInfo; GetCursorPos(&pHitTestInfo.pt); m_CtlList.ScreenToClient(&pHitTestInfo.pt); pHitTestInfo.flags = LVHT_ONITEMLABEL;
pHitTestInfo.iItem = pNMListView->iItem;
m_CtlList.HitTest(&pHitTestInfo); if(pHitTestInfo.iItem != -1)
::AfxMessageBox("yeah");
int i = pHitTestInfo.iSubItem;
2.如果项选择子项时也激发这消息,需要设置以下属性
m_CtlList.SetExtendedStyle(LVS_EX_FULLROWSELECT);