CListCtl - handling clicks and selection
Gerry Sweeney -- gerry@hornbill.com
Tuesday, May 21, 1996
Environment: NT3.51 SP3, MSVC20, MFC
Dear Listers,
I am in the process of porting some 16bit server code over to 32bit.
I have implemented a view which has a CListCtl in it. This list just
displays a list of users currently connected to the server and has various
bits of information like a username, ip address, socket no ect. In the 16
bit code I had a menu option that allowed me to display communications
statistics of the selected user. Using the CListCtl I have been unable to
figure out weather or not an item is selected or what item is selected. I
have created the control with the WS_VISIBLE | WS_CHILD | LVS_REPORT |
LVS_SINGLESEL options. This only allows me to select one item at a time
which is what I wanted. I have tried overriding the OnNotify member function
of my view or get notifications from the control. This works but there does
not seem to be the notifications I need. I have looked at the samples on the
MSDN but have not found an answer.
What I am trying to achieve is the equivalent functionality to the
CListBox messages:-
ON_CLICK
ON_DBLCLICK
GetCurSel();
Any ideas, pointers to examples ect..
Kind Regards
Gerry Sweeney
gerry@hornbill.com
Terry Wellmann -- wellmatl@cs.purdue.edu
Monday, May 27, 1996
[Mini-digest: 6 responses]
Gerry,
Just a couple of ideas. After reading your post here are a few ideas that
came to mind. I'm not sure if they will work or how easily they can be
implemented but it may be worth looking into. If it helps, forward the
result to the mailing list. I'm not going to send it through there if I'm
way off track.
Try capture the messages: WM_LBUTTONDBLCLK, WM_LBUTTONDOWN.
You may need to subclass the CListCtrl and add these messages yourself.
The handlers for the messages above include the point of the mouse click.
If you call the member function HitTest() it should return the index number
of the item that was clicked on. From there you should be off and running.
Good luck.
Terry
-----From: Mario Contestabile
Eg1
void mlistview::OnLButtonDblClk(UINT nFlags, CPoint point)
or
void mlistview::OnRButtonDown(UINT nFlags, CPoint point)
then
LV_HITTESTINFO lvh;
lvh.pt = point;
if(m_ListCtrl.HitTest(&lvh) == -1) return;
CString FileName = m_ListCtrl.GetItemText(lvh.iItem, 0); // get text from
column 0
Eg2
case WM_NOTIFY:
NMHDR* Head = (NMHDR*)lParam;
if(head->code == NM_DBLCLICK)
mcontest@universal.com
-----From: "Tim Swetonic (Starwave)"
This is what you need to use:
int nSelItem = CListCtrl::GetNextItem(-1, LVNI_SELECTED);
-----From: Ken Freeman
Look at NM_CLICK, NM_DBLCLK, and CListCtrl::GetItem.
Ken
-----From: Niels Ull Jacobsen
I think you'll have to trap the WM_NOTIFY yourself=20
in VC 2.0. The details should be in the SDK documentation.
>ON_DBLCLICK
ON_NOTIFY(NM_DBLCLK, ID_MYLIST, OnListNmClick)
>GetCurSel();
GetNextItem(-1, LVNI_SELECTED)
>
>Any ideas, pointers to examples ect..
>
>Kind Regards
>
>Gerry Sweeney
>gerry@hornbill.com
>
>
>
Niels Ull Jacobsen, Kr=FCger A/S (nuj@kruger.dk)
Everything stated herein is THE OFFICIAL POLICY of the entire Kruger grou=
p
and should be taken as legally binding in every respect. Pigs will grow
wings and fly.
-----From: "Frederic Steppe"
You receive standard notification for click events : NM_CLICK, NM_DBLCLICK,
NM_RCLICK
You get item change notification by trapping LVN_ITEMCHANGED (WM_NOTIFY)
You can figure out which item is selected by using MyList.GetNextItem(-1,
LVNI_SELECTED)
I think the easiest way to work on that is to use the VC++ 4 and ClassWizard
to get the notification (for example : create a form view with a list control
in it, declare a CListCtrl member variable using ClassWizard and you'll have a
quite complete list of notifications available).
Frederic Steppe (frederics@msn.com)
| Вернуться в корень Архива
|