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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

klausenAuthor Commented:
Edited text of question.
0
PIGCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.