请问我如何知道鼠标点击在clistctrl的一行上时,具体点击在哪一列呢。

bjxiaoye 2005-08-22 04:03:26
请问我如何知道鼠标点击在clistctrl的一行上时,具体点击在哪一列呢。
...全文
125 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
goodboyws 2005-08-22
NM_CLICK就可以
回复
快乐鹦鹉 2005-08-22
用subitemhittest函数判断。
回复
lixiaosan 2005-08-22
void CTest6Dlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)

{

/****************************************/

/* 方法1 */

/****************************************/



DWORD dwPos = GetMessagePos();

CPoint point( LOWORD(dwPos), HIWORD(dwPos) );



m_list.ScreenToClient(&point);



LVHITTESTINFO lvinfo;

lvinfo.pt = point;

lvinfo.flags = LVHT_ABOVE;



int nItem = m_list.SubItemHitTest(&lvinfo);

if(nItem != -1)

{

CString strtemp;

strtemp.Format("单击的是第%d行第%d列", lvinfo.iItem, lvinfo.iSubItem);

AfxMessageBox(strtemp);

}


/****************************************/

/* 方法2 */

/****************************************/



NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

if(pNMListView->iItem != -1)

{

CString strtemp;

strtemp.Format("单击的是第%d行第%d列",

pNMListView->iItem, pNMListView->iSubItem);

AfxMessageBox(strtemp);

}



*pResult = 0;

}
回复
kvls 2005-08-22
给你一个函数做参考,其中Point为鼠标位置,nSubItem返回列,函数返回行
int CXXXX::HitTestEx(CPoint &Point, int &nSubItem)
{
nSubItem = 0;
int ColumnNum = 0;
int Row = HitTest (Point, NULL);

// Make sure that the ListView is in LVS_REPORT
if ((GetWindowLong (m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
return Row;

// Get the top and bottom row visible
Row = GetTopIndex();
int Bottom = Row + GetCountPerPage();
if (Bottom > GetItemCount())
Bottom = GetItemCount();

// Get the number of columns
CHeaderCtrl* pHeader = (CHeaderCtrl*) GetDlgItem(0);
int nColumnCount = pHeader->GetItemCount();

// Loop through the visible rows
for(; Row <= Bottom; Row++)
{
// Get bounding rect of item and check whether point falls in it.
CRect Rect;
GetItemRect (Row, &Rect, LVIR_BOUNDS);
if (Rect.PtInRect (Point))
{
// Now find the column
for (ColumnNum = 0; ColumnNum < nColumnCount; ColumnNum++)
{
int ColWidth = GetColumnWidth (ColumnNum);
if (Point.x >= Rect.left && Point.x <= (Rect.left + ColWidth))
{
nSubItem = ColumnNum;
return Row;
}
Rect.left += ColWidth;
}
}
}

return -1;
}
回复
DentistryDoctor 2005-08-22
void CXXXlDialog::OnNMClickListChannels(NMHDR *pNMHDR, LRESULT *pResult)
{
LV_HITTESTINFO* pHitTestInfo = (LV_HITTESTINFO*)pNMHDR;
int item = pHitTestInfo->iItem;
int column = pHitTestInfo->iSubItem;
...
}
回复
相关推荐
发帖
界面
创建于2007-09-28

1.5w+

社区成员

VC/MFC 界面
申请成为版主
帖子事件
创建了帖子
2005-08-22 04:03
社区公告
暂无公告