CDialog and NM_RETURN

I have made a Dialog based application, which includes a CListCtrl. I want to handle, when the user presses the return button, while having an item in the listbox selected.
I have done this by handling the NM_RETURN from the ClistCtrl, in the dialog, but the function that handles the NM_RETURN is never called.
The only thing that happens, is that the dialog ends, because the dialog receives the IDOK when I press ENTER, even when the CListCtrl has the focus and an item is selected...

Does anyone know, if I need to do some special handling ?
klausenAsked:
Who is Participating?
 
PIGConnect With a Mentor Commented:
Have a three methods for that.
1. Set Your OK button with other ID. Of BN_CLICKED for IDOK handle function and do nothing and BN_CLICKED for Your OK button affter own code call CDialog::OnOK(). Your OK button must not be default button.
2. In You OnOK() member function check focus and if he is in ListCtrl run You code for NM_RETURN.
3. In Your Dialog overwrite PreTranslateMessage and when get WM_KEYDOWN check focus. If he is in ListCtrl run You code for NM_RETURN.
0
 
klausenAuthor Commented:
Edited text of question.
0
 
PIGCommented:
Sorry! First method don't work propertly. I thik that You must use method three.
0
 
klausenAuthor Commented:
I would have preferred to handle this with the NM_RETURN message, because I thin it looks much nicer.
0
All Courses

From novice to tech pro — start learning today.