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

bjxiaoye 2005-08-22 04:03:26
请问我如何知道鼠标点击在clistctrl的一行上时,具体点击在哪一列呢。
...全文
177 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
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;
...
}

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧