CListCtrl and NM_RETURN 
Author Message
 CListCtrl and NM_RETURN

I am using VC 5.0, MFC and STL on NT 4.0 platform.
The documentation of list control says that CListCtrl sends notification
messages to its parent window whenever the user takes some action like
clicking a header or pressing the enter key.
For example NM_RETURN notifies a list view control's parent window that the
control has the input focus and that the user has pressed the ENTER key.
I have MFC list control inside the dialog box. I have created the class for
the dialog box using class wizard. Also using class wizard I have added
handler to process NM_RETURN notification, but when the item in my ClistCtrl
is highlighted and I press the "Enter" key I don't get any message
whatsoever - I have verified that with "Spy++" tool.
Is there any explanation to that?
Janusz


Tue, 04 Dec 2001 03:00:00 GMT  
 CListCtrl and NM_RETURN

Quote:
>.. Also using class wizard I have added
>handler to process NM_RETURN notification, but when the item in my ClistCtrl
>is highlighted and I press the "Enter" key I don't get any message
>whatsoever - I have verified that with "Spy++" tool.

Janusz,

Using Spy++ you should be able to see which window the WM_NOTIFY
NM_RETURN message is going to.

Dave
----
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Tue, 04 Dec 2001 03:00:00 GMT  
 CListCtrl and NM_RETURN
The dialog manager code intercepts the "Enter" key before it gets to the control.  Try putting a list control on a
window that is not a dialog box, and you'll find you get the notification.  You might be able to route the "Enter"
key to your control on a dialog by intercepting the WM_GETDLGCODE message.  You could also look into overriding
CDialog::PreTranslateMessage to look for that key.  By default in MFC, the "Enter" key will call CDialog::OnOK.

--
_______________________________________________________________
"And the transistor shall inherit the Earth."
-  A. C. Clarke, 1956
_______________________________________________________________

Timothy J. Ebben
Levon's Wake, Inc.

Web: www.LevonsWake.com

----- Paul Bunyan - Best Damn Logger There EVER Was!
_______________________________________________________________

Quote:

>I am using VC 5.0, MFC and STL on NT 4.0 platform.
>The documentation of list control says that CListCtrl sends notification
>messages to its parent window whenever the user takes some action like
>clicking a header or pressing the enter key.
>For example NM_RETURN notifies a list view control's parent window that the
>control has the input focus and that the user has pressed the ENTER key.
>I have MFC list control inside the dialog box. I have created the class for
>the dialog box using class wizard. Also using class wizard I have added
>handler to process NM_RETURN notification, but when the item in my ClistCtrl
>is highlighted and I press the "Enter" key I don't get any message
>whatsoever - I have verified that with "Spy++" tool.
>Is there any explanation to that?
>Janusz



Thu, 06 Dec 2001 03:00:00 GMT  
 CListCtrl and NM_RETURN

1. I have implemented OnGetDlgCode using Class Wizard it did not work.
UINT CEventsPropPage::OnGetDlgCode()
{
        // TODO: Add your message handler code here and/or call default
        return DLGC_WANTMESSAGE;

Quote:
}

 - does not get called by framework

2. I have tried PreTranslateMessage:
BOOL CEventsPropPage::PreTranslateMessage(MSG* pMsg)
{
        // TODO: Add your specialised code here and/or call the  base class
        if (WM_NOTIFY == pMsg->message)
        {
                // Do some processing
                return CPropertyPage::PreTranslateMessage(pMsg);
        }

Quote:
}

 - it doesn't even get WM_NOTIFY msg so it never enters above if statement.
3. I tried to use OnNotify, like:
BOOL CEventsPropPage::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
        // TODO: Add your specialized code here and/or call the base class
        LPNMHDR pnmh = (LPNMHDR) lParam; //NM_RETURN
        if (NM_DBLCLK == pnmh->code)
        {
                // Do some processing;
        }
        else if (NM_RETURN == pnmh->code)
        {
                // Do some processing;
        }

        return CPropertyPage::OnNotify(wParam, lParam, pResult);

Quote:
}

- for NM_DBLCLK message it works fine but it does not work for NM_RETURN it never gets there.

Is there anything else I can try?
Janusz

Quote:

>The dialog manager code intercepts the "Enter" key before it gets to the control.  Try putting a list control on a
>window that is not a dialog box, and you'll find you get the notification.  You might be able to route the "Enter"
>key to your control on a dialog by intercepting the WM_GETDLGCODE message.  You could also look into overriding
>CDialog::PreTranslateMessage to look for that key.  By default in MFC, the "Enter" key will call CDialog::OnOK.

>--
>_______________________________________________________________
>"And the transistor shall inherit the Earth."
>-  A. C. Clarke, 1956
>_______________________________________________________________

>Timothy J. Ebben
>Levon's Wake, Inc.

>Web: www.LevonsWake.com

>----- Paul Bunyan - Best Damn Logger There EVER Was!
>_______________________________________________________________


>>I am using VC 5.0, MFC and STL on NT 4.0 platform.
>>The documentation of list control says that CListCtrl sends notification
>>messages to its parent window whenever the user takes some action like
>>clicking a header or pressing the enter key.
>>For example NM_RETURN notifies a list view control's parent window that the
>>control has the input focus and that the user has pressed the ENTER key.
>>I have MFC list control inside the dialog box. I have created the class for
>>the dialog box using class wizard. Also using class wizard I have added
>>handler to process NM_RETURN notification, but when the item in my ClistCtrl
>>is highlighted and I press the "Enter" key I don't get any message
>>whatsoever - I have verified that with "Spy++" tool.
>>Is there any explanation to that?
>>Janusz

-----------------** -- Posted from CodeGuru -- **-----------------
http://www.codeguru.com/    The website for Visual C++ programmers.


Fri, 07 Dec 2001 03:00:00 GMT  
 CListCtrl and NM_RETURN
As I tried to explain previously, since the "Enter" key is intercepted by the dialog manager code, it never gets to
the control to be translated into a WM_NOTIFY message.  Check for message == WM_KEYDOWN with wParam == VK_ENTER in
PreTranslateMessage.  Note that you'll probably want to determine whether the list control has the focus since the
control probably shouldn't respond to the enter key otherwise.  Also note that essentially the same thing is
accomplished simply by overriding CDialog::OnOK and determining if the list has the focus.

For OnGetDlgCode to work, you'll have to sub-class the control and handle it there.  This is a conceptually
superior implementation since the enter key will be routed to the control and translated into a WM_NOTIFY message
in the same fashion as it would in a non-dialog window.  But of course it's more work, since you have to derive a
class from CListCtrl, and then still handle the NM_RETURN notification in the parent (or the control itself by
message reflection).

Have fun.

--
_______________________________________________________________
"And the transistor shall inherit the Earth."
-  A. C. Clarke, 1956
_______________________________________________________________

Timothy J. Ebben
Levon's Wake, Inc.

Web: www.LevonsWake.com

----- Paul Bunyan - Best Damn Logger There EVER Was!
_______________________________________________________________

Quote:

>1. I have implemented OnGetDlgCode using Class Wizard it did not work.
>UINT CEventsPropPage::OnGetDlgCode()
>{
> // TODO: Add your message handler code here and/or call default
> return DLGC_WANTMESSAGE;
>}
> - does not get called by framework

>2. I have tried PreTranslateMessage:
>BOOL CEventsPropPage::PreTranslateMessage(MSG* pMsg)
>{
> // TODO: Add your specialised code here and/or call the  base class
> if (WM_NOTIFY == pMsg->message)
> {
> // Do some processing
> return CPropertyPage::PreTranslateMessage(pMsg);
>        }
>}
> - it doesn't even get WM_NOTIFY msg so it never enters above if statement.
>3. I tried to use OnNotify, like:
>BOOL CEventsPropPage::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
>{
> // TODO: Add your specialized code here and/or call the base class
> LPNMHDR pnmh = (LPNMHDR) lParam; //NM_RETURN
> if (NM_DBLCLK == pnmh->code)
> {
> // Do some processing;
> }
> else if (NM_RETURN == pnmh->code)
> {
> // Do some processing;
> }

> return CPropertyPage::OnNotify(wParam, lParam, pResult);
>}
>- for NM_DBLCLK message it works fine but it does not work for NM_RETURN it never gets there.

>Is there anything else I can try?
>Janusz


>>The dialog manager code intercepts the "Enter" key before it gets to the control.  Try putting a list control on
a
>>window that is not a dialog box, and you'll find you get the notification.  You might be able to route the
"Enter"
>>key to your control on a dialog by intercepting the WM_GETDLGCODE message.  You could also look into overriding
>>CDialog::PreTranslateMessage to look for that key.  By default in MFC, the "Enter" key will call CDialog::OnOK.


>>>I am using VC 5.0, MFC and STL on NT 4.0 platform.
>>>The documentation of list control says that CListCtrl sends notification
>>>messages to its parent window whenever the user takes some action like
>>>clicking a header or pressing the enter key.
>>>For example NM_RETURN notifies a list view control's parent window that the
>>>control has the input focus and that the user has pressed the ENTER key.
>>>I have MFC list control inside the dialog box. I have created the class for
>>>the dialog box using class wizard. Also using class wizard I have added
>>>handler to process NM_RETURN notification, but when the item in my ClistCtrl
>>>is highlighted and I press the "Enter" key I don't get any message
>>>whatsoever - I have verified that with "Spy++" tool.
>>>Is there any explanation to that?
>>>Janusz

>-----------------** -- Posted from CodeGuru -- **-----------------
>http://www.codeguru.com/    The website for Visual C++ programmers.



Sat, 08 Dec 2001 03:00:00 GMT  
 CListCtrl and NM_RETURN

Thank you very much. It works beautifully with sub-classing.
The only other problem I have with this ClistCtrl is that when I subclass it to handle Enter key (by returning from OnGetDlgCode the value CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS), my list control does not seem to recognise and process TAB characters any more when I press TAB while one of the items in ClistCtrl has focus it should move to the Property sheet Tab control(there are no other controls on the property page) but it doesnt. Is there any fix for that ?.
Janusz

Quote:

>As I tried to explain previously, since the "Enter" key is intercepted by the dialog manager code, it never gets to
>the control to be translated into a WM_NOTIFY message.  Check for message == WM_KEYDOWN with wParam == VK_ENTER in
>PreTranslateMessage.  Note that you'll probably want to determine whether the list control has the focus since the
>control probably shouldn't respond to the enter key otherwise.  Also note that essentially the same thing is
>accomplished simply by overriding CDialog::OnOK and determining if the list has the focus.

>For OnGetDlgCode to work, you'll have to sub-class the control and handle it there.  This is a conceptually
>superior implementation since the enter key will be routed to the control and translated into a WM_NOTIFY message
>in the same fashion as it would in a non-dialog window.  But of course it's more work, since you have to derive a
>class from CListCtrl, and then still handle the NM_RETURN notification in the parent (or the control itself by
>message reflection).

>Have fun.

>--
>_______________________________________________________________
>"And the transistor shall inherit the Earth."
>-  A. C. Clarke, 1956
>_______________________________________________________________

>Timothy J. Ebben
>Levon's Wake, Inc.

>Web: www.LevonsWake.com

>----- Paul Bunyan - Best Damn Logger There EVER Was!
>_______________________________________________________________


>>1. I have implemented OnGetDlgCode using Class Wizard it did not work.
>>UINT CEventsPropPage::OnGetDlgCode()
>>{
>> // TODO: Add your message handler code here and/or call default
>> return DLGC_WANTMESSAGE;
>>}
>> - does not get called by framework

>>2. I have tried PreTranslateMessage:
>>BOOL CEventsPropPage::PreTranslateMessage(MSG* pMsg)
>>{
>> // TODO: Add your specialised code here and/or call the  base class
>> if (WM_NOTIFY == pMsg->message)
>> {
>> // Do some processing
>> return CPropertyPage::PreTranslateMessage(pMsg);
>>        }
>>}
>> - it doesn't even get WM_NOTIFY msg so it never enters above if statement.
>>3. I tried to use OnNotify, like:
>>BOOL CEventsPropPage::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
>>{
>> // TODO: Add your specialized code here and/or call the base class
>> LPNMHDR pnmh = (LPNMHDR) lParam; //NM_RETURN
>> if (NM_DBLCLK == pnmh->code)
>> {
>> // Do some processing;
>> }
>> else if (NM_RETURN == pnmh->code)
>> {
>> // Do some processing;
>> }

>> return CPropertyPage::OnNotify(wParam, lParam, pResult);
>>}
>>- for NM_DBLCLK message it works fine but it does not work for NM_RETURN it never gets there.

>>Is there anything else I can try?
>>Janusz


>>>The dialog manager code intercepts the "Enter" key before it gets to the control.  Try putting a list control on
>a
>>>window that is not a dialog box, and you'll find you get the notification.  You might be able to route the
>"Enter"
>>>key to your control on a dialog by intercepting the WM_GETDLGCODE message.  You could also look into overriding
>>>CDialog::PreTranslateMessage to look for that key.  By default in MFC, the "Enter" key will call CDialog::OnOK.


>>>>I am using VC 5.0, MFC and STL on NT 4.0 platform.
>>>>The documentation of list control says that CListCtrl sends notification
>>>>messages to its parent window whenever the user takes some action like
>>>>clicking a header or pressing the enter key.
>>>>For example NM_RETURN notifies a list view control's parent window that the
>>>>control has the input focus and that the user has pressed the ENTER key.
>>>>I have MFC list control inside the dialog box. I have created the class for
>>>>the dialog box using class wizard. Also using class wizard I have added
>>>>handler to process NM_RETURN notification, but when the item in my ClistCtrl
>>>>is highlighted and I press the "Enter" key I don't get any message
>>>>whatsoever - I have verified that with "Spy++" tool.
>>>>Is there any explanation to that?
>>>>Janusz

>>-----------------** -- Posted from CodeGuru -- **-----------------
>>http://www.codeguru.com/    The website for Visual C++ programmers.

-----------------** -- Posted from CodeGuru -- **-----------------
http://www.codeguru.com/    The website for Visual C++ programmers.


Sun, 09 Dec 2001 03:00:00 GMT  
 CListCtrl and NM_RETURN
Quote:

>Thank you very much. It works beautifully with sub-classing.
>The only other problem I have with this ClistCtrl is that when I subclass it to handle Enter key (by returning

from OnGetDlgCode the value CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS), my list control does not seem to
recognise and process TAB characters any more when I press TAB while one of the items in ClistCtrl has focus it
should move to the Property sheet Tab control(there are no other controls on the property page) but it doesnt.
Is there any fix for that ?.

Quote:
>Janusz

You'll have to intercept the tab key in the control and forward it to the property sheet.  Note that you're
disabling all the other normal dialog keys, too.  The "Enter" normally activates the default button in a dialog,
but you're using it for another purpose.  To be sure you're not blocking other functionality, you'll probably have
to handle each keystroke and if you don't want it, forward it to the parent or other appropriate window.  I've not
done this in a dialog or property sheet, and frankly it looks pretty messy.  Now that you've got it, are you sure
you really need that "Enter" key?

--
_______________________________________________________________
"And the transistor shall inherit the Earth."
-  A. C. Clarke, 1956
_______________________________________________________________

Timothy J. Ebben
Levon's Wake, Inc.

Web: www.LevonsWake.com

----- Paul Bunyan - Best Damn Logger There EVER Was!
_______________________________________________________________

Quote:

>>As I tried to explain previously, since the "Enter" key is intercepted by the dialog manager code, it never gets
to
>>the control to be translated into a WM_NOTIFY message.  Check for message == WM_KEYDOWN with wParam == VK_ENTER
in
>>PreTranslateMessage.  Note that you'll probably want to determine whether the list control has the focus since
the
>>control probably shouldn't respond to the enter key otherwise.  Also note that essentially the same thing is
>>accomplished simply by overriding CDialog::OnOK and determining if the list has the focus.

>>For OnGetDlgCode to work, you'll have to sub-class the control and handle it there.  This is a conceptually
>>superior implementation since the enter key will be routed to the control and translated into a WM_NOTIFY message
>>in the same fashion as it would in a non-dialog window.  But of course it's more work, since you have to derive a
>>class from CListCtrl, and then still handle the NM_RETURN notification in the parent (or the control itself by
>>message reflection).

>>Have fun.

>>--
>>_______________________________________________________________
>>"And the transistor shall inherit the Earth."
>>-  A. C. Clarke, 1956
>>_______________________________________________________________

>>Timothy J. Ebben
>>Levon's Wake, Inc.

>>Web: www.LevonsWake.com

>>----- Paul Bunyan - Best Damn Logger There EVER Was!
>>_______________________________________________________________


>>>1. I have implemented OnGetDlgCode using Class Wizard it did not work.
>>>UINT CEventsPropPage::OnGetDlgCode()
>>>{
>>> // TODO: Add your message handler code here and/or call default
>>> return DLGC_WANTMESSAGE;
>>>}
>>> - does not get called by framework

>>>2. I have tried PreTranslateMessage:
>>>BOOL CEventsPropPage::PreTranslateMessage(MSG* pMsg)
>>>{
>>> // TODO: Add your specialised code here and/or call the  base class
>>> if (WM_NOTIFY == pMsg->message)
>>> {
>>> // Do some processing
>>> return CPropertyPage::PreTranslateMessage(pMsg);
>>>        }
>>>}
>>> - it doesn't even get WM_NOTIFY msg so it never enters above if statement.
>>>3. I tried to use OnNotify, like:
>>>BOOL CEventsPropPage::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
>>>{
>>> // TODO: Add your specialized code here and/or call the base class
>>> LPNMHDR pnmh = (LPNMHDR) lParam; //NM_RETURN
>>> if (NM_DBLCLK == pnmh->code)
>>> {
>>> // Do some processing;
>>> }
>>> else if (NM_RETURN == pnmh->code)
>>> {
>>> // Do some processing;
>>> }

>>> return CPropertyPage::OnNotify(wParam, lParam, pResult);
>>>}
>>>- for NM_DBLCLK message it works fine but it does not work for NM_RETURN it never gets there.

>>>Is there anything else I can try?
>>>Janusz


>>>>The dialog manager code intercepts the "Enter" key before it gets to the control.  Try putting a list control
on
>>a
>>>>window that is not a dialog box, and you'll find you get the notification.  You might be able to route the
>>"Enter"
>>>>key to your control on a dialog by intercepting the WM_GETDLGCODE message.  You could also look into overriding
>>>>CDialog::PreTranslateMessage to look for that key.  By default in MFC, the "Enter" key will call CDialog::OnOK.


>>>>>I am using VC 5.0, MFC and STL on NT 4.0 platform.
>>>>>The documentation of list control says that CListCtrl sends notification
>>>>>messages to its parent window whenever the user takes some action like
>>>>>clicking a header or pressing the enter key.
>>>>>For example NM_RETURN notifies a list view control's parent window that the
>>>>>control has the input focus and that the user has pressed the ENTER key.
>>>>>I have MFC list control inside the dialog box. I have created the class for
>>>>>the dialog box using class wizard. Also using class wizard I have added
>>>>>handler to process NM_RETURN notification, but when the item in my ClistCtrl
>>>>>is highlighted and I press the "Enter" key I don't get any message
>>>>>whatsoever - I have verified that with "Spy++" tool.
>>>>>Is there any explanation to that?
>>>>>Janusz

>>>-----------------** -- Posted from CodeGuru -- **-----------------
>>>http://www.codeguru.com/    The website for Visual C++ programmers.

>-----------------** -- Posted from CodeGuru -- **-----------------
>http://www.codeguru.com/    The website for Visual C++ programmers.



Wed, 12 Dec 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. CListCtrl and NM_RETURN

2. CListCtrl Notification: NM_RETURN

3. Getting NM_RETURN from CListCtrl

4. NM_RETURN in CListCtrl

5. NM_RETURN, CListCtrl, and CTreeCtrl

6. How to Send "NM_RETURN" ather Apprication

7. NM_RETURN does not work

8. NM_RETURN event from RcihEdit

9. NM_RETURN and CTreeCtrl

10. CTreeCtrl NM_RETURN Problem

11. RichEdit and NM_RETURN

12. Q: Child Comobox notifies parent window of NM_RETURN

 

 
Powered by phpBB® Forum Software