DWORD dwPos = ::GetMessagePos(); CPoint point((int)LOWORD(dwPos), (int)HIWORD(dwPos)); ListCtrl.ScreenToClient( &point ); LONG iSelectionIndex = ListCtrl.HitTest( point ); ListCtrl为你的列表控件 iSelectionIndex为所选的行
可以用CListCtrl类的成员函数GetFirstSelectedItemPosition(),及GetNextSelectedItem(pos) 例子如下: // CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_YOURLISTCONTROL); ASSERT(pListCtrl != NULL);POSITION pos = pList->GetFirstSelectedItemPosition(); if (pos == NULL) TRACE0("No items were selected!\n"); else { while (pos) { int nItem = pList->GetNextSelectedItem(pos); TRACE1("Item %d was selected!\n", nItem); // you could do your own processing on nItem here } }
CPoint point((int)LOWORD(dwPos), (int)HIWORD(dwPos));
ListCtrl.ScreenToClient( &point );
LONG iSelectionIndex = ListCtrl.HitTest( point );
ListCtrl为你的列表控件
iSelectionIndex为所选的行
例子如下:
// CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_YOURLISTCONTROL);
ASSERT(pListCtrl != NULL);POSITION pos = pList->GetFirstSelectedItemPosition();
if (pos == NULL)
TRACE0("No items were selected!\n");
else
{
while (pos)
{
int nItem = pList->GetNextSelectedItem(pos);
TRACE1("Item %d was selected!\n", nItem);
// you could do your own processing on nItem here
}
}