MFC C++ Add Event Handler to items that user adds to a List Control help

Hi guys!

So I am having trouble with finding information about how to add a Event Handler to items that are added to a List Control by a user after the application has ran.

Essentially what I want to do is make the item that the user adds do something when it is double clicked.

I am finding it to be nearly impossible to find anything on this. On YouTube I can only find videos that are either 8-9 years old or in a different language. I have tried countless searches on google, no luck. I also went back through the two C++ books I have and they do not talk about this either. I have searched and searched and search and literally can not find one scrap of information about this anywhere at all.

I am certain that the way that you do this is not difficult, I just can not find anything on it.

Any advice or references anyone can point me to? Thank you in advance.
Items don't have event handlers since they are strings. You need to handle the events of the ListControl.

Try this:
Right-click on the ListControl and choose Add EventHandler. Then choose NM_DBLCLK under Message type and click Add and Edit. This creates an event handler that looks like:
1
2
3
4
5
6
void CMFCAppDlg::OnDoubleClick(NMHDR *pNMHDR, LRESULT *pResult)
{
  LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
  // TODO: Add your control notification handler code here
  *pResult = 0;
}
Thank you Thomas.

That is a step further for me.

However, I should have been a bit more specific about this. Every item that is on the list will do a different thing when double clicked. What you gave me above does now allow my List Control to receive double clicks but I can not see a way for it to differentiate between the multiple items that are on the list and take the right action depending on the item that was double clicked on.

Are you aware of any books on MFC? I can not find one that was released recently enough to be helpful. I find this stuff easy once I find information on it but I find that it is almost impossible to find information about it. That is the biggest challenge I see right now.
Last edited on
I found one. A relatively recent book that is. My long search for the holy grail is over. I do still welcome input from anyone reading this though.

For those who want to know:
https://www.amazon.com/Windows-MFC-Programming-Vic-Broquard/dp/1941415571/ref=sr_1_4?s=books&ie=UTF8&qid=1493048551&sr=1-4&keywords=MFC
Good that you found a book.

but I can not see a way for it to differentiate between the multiple items that are on the list
I think this gives you the item that was double clicked.
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774771(v=vs.85).aspx
Topic archived. No new replies allowed.