NM_RETURN

Hi
I have a RichEdit control and I want to capture the NM_RETURN notification

I cant seem to find it in the WM_NOTIFY message anywhere .
Can anyone help
RinoHAsked:
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.

RinoHAuthor Commented:
Please - no abstractions I want code.
0
nietodCommented:
You get this notification when the control doesn't "use" the return.  It is sent to the parent so the parent can move the focus to the next control (if desired).  But if the control uses the return, like a richedit control, then the notification is made.  Otherwise, everytime you started a new paragraph, you would move to the next control.
0
nietodCommented:
You might try looking for a NM_KEYDOWN for a return instead.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

NickRepinCommented:
All ways are listed here


Q102589 - HOWTO: Use the ENTER Key from Edit Controls in a Dialog Box

http://support.microsoft.com/support/kb/articles/q102/5/89.asp
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
NickRepinCommented:
Actually, you have to subclass richedit control and handle WM_KEYDOWN,WM_KEYUP,WM_CHAR messages.
NM_RETURN is not for rich edit.
0
TryCommented:
WM_NOTIFY messages have two parameters to them, the wParam which is an 'int' containing the ID of the Control sending the message, and the second parameter, lParam, is a pointer to a structure.  In the case of NM_RETURN, that structure is NMHDR and is defined as:

typedef struct tagNMHDR
{
   HWND  hwndFrom  // Window handle of the of the Control Window
                   // making the notification
   UNIT  idFrom   // Control ID of Control Window
                  // making the notification
   UNIT  code     //  the notification code
}  NMHDR;


Because NM_RETURN subscribes to this structure, it means that if you want to obtain any information about what Control Window  the user might be currently in when NM_RETURN was sent, you'll have to obtain that information from this structure; the Control ID and the notification code likewise.

NM_RETURN is sent when the Control has the input focus, and the user has pressed the "Enter" key.

Some notification messages have larger structures of which NMHDR is contained inside them, but for NM_RETURN, the structure you want to reference is the one shown above.


If you have any further questions, don't hesitate.
0
NickRepinCommented:
Here is the sample code for subclassing.

// Global var.
WNDPROC oldProc;  


// Subclassing. hRE is the window handle of rich edit control.
oldProc=(WNDPROC)SetWindowLong(hRE,GWL_WNDPROC,LONG(newProc));

// Now the parent of hRE will receive NM_RETURN notification.


// New rich edit window proc.
LRESULT CALLBACK newProc(HWND hWnd,UINT uMsg,WPARAM wP,LPARAM lP)
{
   switch (uMsg) {
   case WM_DESTROY:
      SetWindowLong(hWnd,GWL_WNDPROC,LONG(oldProc));
      break;
   case WM_KEYDOWN:
   case WM_KEYUP:
      // Do whatever you want.
      break;
   case WM_CHAR:
      // Do whatever you want, for example, simulate NM_RETURN:
      NMNOTIFY  n;
      n.hwndFrom=hWnd;
      n.idFrom=GetWindowLong(hWnd,GWL_ID);
      n.code=NM_RETURN;
      SendMessage(GetParent(hWnd),WM_NOTIFY,n.idFrom,LPARAM(&n));
      break;
   }

   return CallWindowProc(oldProc,hWnd,uMsg,wP,lP);
}

0
TryCommented:
Rich-Text Edit Controls do use NM_RETURN, particularly the EN_CORRECTTEXT code value.

Here's a bit of sample code:

LRESULT  OnNotify(HWND hwnd, int id, NMHDR* nmhdr)
{
   switch(id)
      {
       case ID_CONTROL:
             return  OnMyControl(hwnd, nmhdr);
       ...
       }
}

LRESULT  OnMyControl(HWND hwnd, NMHDR* nmhdr)
{
    switch(nmhdr->code)
       {
        case NM_RETURN:
              // here you can access any info in the structure
              // e.g. nmhdr->hwndFrom
        ...
        }
}


Hope this helps.
0
NickRepinCommented:
<<Rich-Text Edit Controls do use NM_RETURN, particularly the EN_CORRECTTEXT code value. >>

Sorry, but it sounds strange enough.
Try, did you try your solution?
I did, and as far as I know, RE doesn't send NM_RETURN notification.
As to EN_CORRECTTEXT, it doesn't contain any information about which key was pressed.


RinoH,

instead of sublassing, you can also use EN_MSGFILTER notification message which notifies a rich edit control's parent window of a keyboard or mouse event in the control.

SendMessage(hRE,EM_SETEVENTMASK,0,ENM_KEYEVENTS);

 case WM_NOTIFY:
    // Check if message is from the RE.
    ...
    if(code==EN_MSGFILTER) {
       MSGFILTER* pmf=(MSGFILTER*)lParam;
       pf(pmf->msg==WM_KEYDOWN && pmf->wParam==VK_RETURN) {
           // Enter was pressed.
       }

    }


0
RinoHAuthor Commented:
Hi Nick

Thanks for the reply
Actually the code you suggested

case WM_NOTIFY:
    // Check if message is from the RE.
    ...
    if(code==EN_MSGFILTER) {
       MSGFILTER* pmf=(MSGFILTER*)lParam;
       pf(pmf->msg==WM_KEYDOWN && pmf->wParam==VK_RETURN) {
           // Enter was pressed.
       }

    }


Is EXACLY what I have been doing. Its just that I dont like it so much and someone told me there was a better way to get a 'Real' Return notification from the Edit control .
I will Explain :
I have to support Japanese OS and in japanese - in one of the modes when you type text in an edit field and press 'Return' the text is translated (into Kanji) meaning it is a Return which must not be processed by me. Only the second Return must be processed.(a Real 'Return' for me)  Luckily I can differentiate between them because the first return produces a WM_KEYDOWN but with a VK_PROCESSKEY instead of a VK_RETURN, only the second return produces a WM_KEYDOWN with a VK_RETURN , so it works - However someone told me that there is a way to receive a notification from the Edit which tells you when a 'real' return has occured , He couldnt remember what it was and he said he did it for an Edit control not a Rich Edit however when I found the NM_RETURN it seemed  like  that was the correct way to do it however it didnt work.

So can you tell me what the deal is with the NM_RETURN and is processing the WM_KEYDOWN e.t.c the only way to monitor Returns from RichEdit controls -how about Edit Controls. ??
Why doesnt a RichEdit produce an NM_RETURN ??
0
NickRepinCommented:
Well, according to my experience, NM_RETURN doesn't work with Edit and RichEdit.
If I am not wrong, it doesn't work for the standard controls like button and static as well.

Moreother, MS docs doesn't state that it does. MS says that NM_RETURN works for all common controls.
But Edit and RichEdit are not located in comctl32.dll and they are not the common controls. Just search for the NM_RETURN in the MSDN Library and you'll see.

As to Return key and Edit control, look at the knowledge base article I mentioned above in my initial answer.

As to Return key and RichEdit, see my comments above.

I can add only that VK_PROCESSKEY is generated by IME (input method editor).
I think if you specify ES_NOIME, then you'll get "pure" VK_RETURN, but of course RE will not have IME features.
In other words, VK_PROCESS key is not generated by Rich Edit and, strictly to say, it's really VK_PROCESS, but not VK_RETURN (but physically, of course, it's the same key).

I hope I fully answered on your question.
0
TryCommented:
What structure was you 'lParam' pointing to?
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
Microsoft Development

From novice to tech pro — start learning today.