Zhu051200
asked on
NM_SETFOCUS in ListCtrl
I use a ListCtrl in a dialog. I map the NM_SETFOCUS message like this:
void CMainDlg::OnSetfocusFileli st(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int i = pNMListView->iItem;
*pResult = 0;
}
I think i is the item number that be set focus. But it can't work. I can't get the right number. why?
BTW, if I click a item to select it, can I still get the item's selected state after the control is not in the ListCtrl? I hope to click some items in the ListCtrl and press a button, then my program will know which items I have selected . what is the better way to implement this?
Thank you very much.
void CMainDlg::OnSetfocusFileli
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int i = pNMListView->iItem;
*pResult = 0;
}
I think i is the item number that be set focus. But it can't work. I can't get the right number. why?
BTW, if I click a item to select it, can I still get the item's selected state after the control is not in the ListCtrl? I hope to click some items in the ListCtrl and press a button, then my program will know which items I have selected . what is the better way to implement this?
Thank you very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great!
I use ch_vasu's second way. It worked perfectly. It looks like that though the ListCtrl loses it's focus, it still remembers which items have been selected.
I use ch_vasu's second way. It worked perfectly. It looks like that though the ListCtrl loses it's focus, it still remembers which items have been selected.
void CMainDlg::OnSetfocusFileli
{
DWORD pos = ::GetMessagePos();
CPoint point((int)LOWORD(pos),(in
m_ListCtrl.ScreenToClient(
int itemno = m_ListCtrl.HitTest(point);
///////////////////
// if (itemno == -1)
// No item selected
}
m_ListCtrl is a variable of type CListCtrl for the List Control
For the selection of items to remain after the listctrl has lost focus use the style LVS_SHOWSELALWAYS (Select the Show Selection Always on the Styles tab of list control)