Handling 'Enter' in Edit Control 
Author Message
 Handling 'Enter' in Edit Control

hi,
can anyone help me how "Enter" key stroke can be handled in an edit control.

I have a control subclassed from CEdit. I have overridden CWnd::OnChar().
But the handler is not being called when Enter key is pressed(while the
focus is in the control!).

Also, I tried to handle ON_NOTIFY message  with NM_RETURN as notification
code. But it turned out that the handler doesn't get called not only for
NM_RETURN, but also for all notification codes common for all the win32
controls.

Thanks in advance,
Raj



Sat, 24 Jun 2000 03:00:00 GMT  
 Handling 'Enter' in Edit Control

Quote:

> hi,
> can anyone help me how "Enter" key stroke can be handled in an edit control.

> I have a control subclassed from CEdit. I have overridden CWnd::OnChar().
> But the handler is not being called when Enter key is pressed(while the
> focus is in the control!).

> Also, I tried to handle ON_NOTIFY message  with NM_RETURN as notification
> code. But it turned out that the handler doesn't get called not only for
> NM_RETURN, but also for all notification codes common for all the win32
> controls.

> Thanks in advance,
> Raj

UINT CExampleEdit::OnGetDlgCode()
{
        return  CEdit::OnGetDlgCode()|DLGC_WANTMESSAGE;

Quote:
}

void CExampleEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
        if (nChar == VK_TAB)    // Handle the TAB key
                {
                if (::GetKeyState(VK_SHIFT) < 0)
                        {
                        (CDialog *)GetParentOwner()->GetNextDlgTabItem(this,
TRUE)->SetFocus();
                        }
                else
                        {
                        (CDialog *)GetParentOwner()->GetNextDlgTabItem(this)->SetFocus();
                        }

                return;
                }

        if (nChar == VK_RETURN)
                {
                // Do whatever you want to do here... how about tab to the next
control:

                (CDialog *)GetParentOwner()->GetNextDlgTabItem(this)->SetFocus();

                return;
                }

        if (nChar == VK_ESCAPE)
                {
                //  Need to cancel the dialog
                (CDialog *)GetParentOwner()->SendMessage(WM_CLOSE);
                return;
                }

        CEdit::OnChar(nChar, nRepCnt, nFlags);

Quote:
}

        Rail
--
        Recording Engineer/Software Developer
        Rail Jon Rogut Software
        http://home.earthlink.net/~railro



Sat, 24 Jun 2000 03:00:00 GMT  
 Handling 'Enter' in Edit Control


Quote:
> hi,
> can anyone help me how "Enter" key stroke can be handled in an edit
control.

Hi Raj

An easy way to hadle this is to override th OnOK function. This is how I
handle the problen in a password dialog.

void CPrototypeDlg::OnOK()
{
        CWnd* m_CurrentCtrl = GetFocus();
        int ID = m_CurrentCtrl->GetDlgCtrlID();

        if (ID == IDC_USER_NAME)
                MoveToPassword();
        if (ID == ID_LOGON || ID == IDC_PASSWORD)
                OnLogOn();

Quote:
}

Hope this helps

Ben



Sun, 25 Jun 2000 03:00:00 GMT  
 Handling 'Enter' in Edit Control

Handle it in the OnOK.  In OnOK check if the current control id is IDOK -
if so then do the 'normal' handling.  Else, return.


Quote:
> hi,
> can anyone help me how "Enter" key stroke can be handled in an edit
control.

> I have a control subclassed from CEdit. I have overridden CWnd::OnChar().
> But the handler is not being called when Enter key is pressed(while the
> focus is in the control!).

> Also, I tried to handle ON_NOTIFY message  with NM_RETURN as notification
> code. But it turned out that the handler doesn't get called not only for
> NM_RETURN, but also for all notification codes common for all the win32
> controls.

> Thanks in advance,
> Raj



Mon, 26 Jun 2000 03:00:00 GMT  
 Handling 'Enter' in Edit Control


says...

Quote:

>Handle it in the OnOK.  In OnOK check if the current control id is IDOK -
>if so then do the 'normal' handling.  Else, return.


>> hi,
>> can anyone help me how "Enter" key stroke can be handled in an edit
>control.

What if the edit control is in a property sheet/page?  My non-modal
property page OnOK (which does not have OK/apply/cancel buttons)
never gets called!


Mon, 26 Jun 2000 03:00:00 GMT  
 Handling 'Enter' in Edit Control

Quote:

>can anyone help me how "Enter" key stroke can be handled in an edit control.

>I have a control subclassed from CEdit. I have overridden CWnd::OnChar().
>But the handler is not being called when Enter key is pressed(while the
>focus is in the control!).

>Also, I tried to handle ON_NOTIFY message  with NM_RETURN as notification
>code. But it turned out that the handler doesn't get called not only for
>NM_RETURN, but also for all notification codes common for all the win32
>controls.

Just set the control's "want return" property in the resource editor.

= Warren -- http://www.{*filter*}port.com/~tangent/
=
= Remove the SPAMCATCHER to email. -- Finger me!



Mon, 26 Jun 2000 03:00:00 GMT  
 Handling 'Enter' in Edit Control



Quote:

> >can anyone help me how "Enter" key stroke can be handled in an edit
control.

> >I have a control subclassed from CEdit. I have overridden
CWnd::OnChar().
> >But the handler is not being called when Enter key is pressed(while the
> >focus is in the control!).

> >Also, I tried to handle ON_NOTIFY message  with NM_RETURN as
notification
> >code. But it turned out that the handler doesn't get called not only for
> >NM_RETURN, but also for all notification codes common for all the win32
> >controls.

> Just set the control's "want return" property in the resource editor.

> = Warren -- http://www.{*filter*}port.com/~tangent/
> =
> = Remove the SPAMCATCHER to email. -- Finger me!

Remember - it's gotta be a MULTILINE control for "want return" to work.

Harley



Tue, 27 Jun 2000 03:00:00 GMT  
 Handling 'Enter' in Edit Control

have a look at KB article PSS ID Number: Q102589
Using ENTER Key from Edit Controls in a Dialog Box

--

----------------------------------------------------------------------------
Raejsh Parikh - Microsoft Certified Solution Developer
Madras - India
Voice : 91 (44) 642360

----------------------------------------------------------------------------


Quote:
>says...

>>Handle it in the OnOK.  In OnOK check if the current control id is IDOK -
>>if so then do the 'normal' handling.  Else, return.


>>> hi,
>>> can anyone help me how "Enter" key stroke can be handled in an edit
>>control.

>What if the edit control is in a property sheet/page?  My non-modal
>property page OnOK (which does not have OK/apply/cancel buttons)
>never gets called!



Tue, 27 Jun 2000 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. newbie question: 'handling' handle/callback

2. Placing a control in an edit control's NC area

3. Entering the '-' character in an edit control.

4. capture 'enter key'

5. Dialogs and 'Enter' button problem

6. Bell sound when ENTER is pressed in an EDIT control child of an ATL control

7. Can't change background color of edit control

8. CAxWindow - Hosted Control's Window Handle

9. Can't Tab to Subclassed Edit Control

10. Get the handle of a windowed activex control in a method of it's interface

11. Wang's Image Edit Control -- Problem?

12. Tree Control Edit Boxes Don't Work Properly

 

 
Powered by phpBB® Forum Software