Edit Box and Return Key 
Author Message
 Edit Box and Return Key

I have an edit box, but whenever i type stuff in it and hit return, the
program closes. Instead I want it to asign whatever was in the edit box
(m_strInfo) to another variable (m_strScr).  I know how to do the
reasigning, I just need to know how to make it do it when i hit return.



Fri, 24 Oct 2003 09:30:46 GMT  
 Edit Box and Return Key

Quote:

> I have an edit box, but whenever i type stuff in it and hit return, the
> program closes. Instead I want it to asign whatever was in the edit box
> (m_strInfo) to another variable (m_strScr).  I know how to do the
> reasigning, I just need to know how to make it do it when i hit return.

hello joe,
In a dialog the return key 'clicks' the default button.  That's normal
Windows behavior.  I guess you have an OK default button, which closes
the dialog, which closes your program.  You can intercept the return
key like this:

BOOL CSomeDlg::PreTranslateMessage(MSG* pMsg)
{
        if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
        {       // Return key was hit.
                DoSomething(); // Take some action
                return TRUE;   // Bypass default handling
        }
        return CDialog::PreTranslateMessage(pMsg);

Quote:
}

By returning TRUE when the key comes in you prevent it from being
passed on to the default button.

--
Scott McPhillips [VC++ MVP]



Fri, 24 Oct 2003 11:47:52 GMT  
 Edit Box and Return Key
Derive a class from CEdit to use for your control, and handle the WM_KEYDOWN
message (OnKeyDown).  When the char is VK_RETURN, do your assignment, otherwise
call the base class for other keys.


Fri, 24 Oct 2003 12:01:54 GMT  
 Edit Box and Return Key
As Scott says, this is normal Windows behavior that most experienced Windows
users will consider normal. You can use it that way and just put some
processing in an OnOk override. To create the override, use the ClassWizard
and add a handler for the IDOK command. If you need to customize the
processing of the enter key further, you do not need to override
PreTranslateMessage. See:

http://www.cpp.atfreeweb.com/KbdMessagesControls.html
http://www.cpp.atfreeweb.com/DerivedControls.html
http://www.cpp.atfreeweb.com/SubclassingControls.html


Quote:

> I have an edit box, but whenever i type stuff in it and hit return, the
> program closes. Instead I want it to asign whatever was in the edit box
> (m_strInfo) to another variable (m_strScr).  I know how to do the
> reasigning, I just need to know how to make it do it when i hit return.



Fri, 24 Oct 2003 17:01:07 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Dialog box disappears on an Edit box carriage return

2. Edit control and return key

3. Edit Contorl Want return key

4. Edit control and return key

5. Handling ESC and RETURN keys in Tree Control label edit

6. adding accelator key to edit box

7. <ENTER>-key and edit box

8. Tab key in edit box

9. Edit Box with Enter Key down

10. Enter Key in Edit Box!!!

11. Mapping Enter key to Tab in edit boxes

12. VC edit box and trapping function keys...

 

 
Powered by phpBB® Forum Software