Archived

This topic is now archived and is closed to further replies.

Xtremehobo

detecting clicks

Recommended Posts

Hi, I''ve got a list view control on a win32 dialog. How would I go about detecting when a user clicks it? I''ve tried hooking the WM_COMMAND message in the dialog''s message procedure, but it doesn''t ''fire'' when I click an item on the list view control. I''ve also tried hooking WM_LBUTTONUP and checking to see if the cursor was inside the list view control, but apparently WM_LBUTTONUP only fires when the button is clicked on the form, and not any of it''s child controls. Any ideas? Thanks, Matt

Share this post


Link to post
Share on other sites
The message you want to look into is LVN_ITEMCHANGED. It is sent for more than just selection changes so make sure to look at the documentation. The online MSDN documentation can be found here.

- Timothy S

[edited by - slepyii on August 9, 2003 11:20:13 PM]

Share this post


Link to post
Share on other sites
ahh... the wParam doesn''t contain the message ID sent from the control. it sends a pointer to a struct that contains it I guess. anyways,
if I have a "''type cast'' : cannot convert from ''long'' to ''struct tagNMHDR''" error on this line: "NMHDR hdr = (NMHDR)lParam;", how do I fix this? I''ve tried many different casting combinations and nothing works :-\

Share this post


Link to post
Share on other sites
ok, fixed that, but now I''ve got this problem. I recieve the WM_NOTIFY Message, and I get NM_CLICK from lparam (NM_CLICK) fires when someone clicks an item on my list control. MSDN says that the NM_CLICK message sends some extra data along with it;
lpnmitem = (LPNMITEMACTIVATE) lParam;

but problem is, NM_CLICK was sent through lParam. How can more data be sent through lParam?

Share this post


Link to post
Share on other sites
You are misunderstanding the docs. The NM_* messages are in the code member of the NMHDR structure that lParam points to. For some NM_* codes, lParam points to a different structure, one that extends the NMHDR structure. So for example the beginning of the NMITEMACTIVATE structure is actually identical to a NMHDR structure. So what you need to do is cast lParam first to a LPNMHDR, get the code from it to see what NM_* was passed, and then in the case of that code being NM_CLICK, cast lParam to a LPNMITEMACTIVATE and do whatever you need to do with the click info.

[edited by - Mastaba on August 10, 2003 2:46:28 AM]

Share this post


Link to post
Share on other sites