CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2002
    Posts
    1

    Question CEdit Box Question

    Hey there!

    I just started playing around with VC++ .net and already discovered a problem I can't explain
    When I create a Dialog-Based Application with only one CEdit Editbox on the Dialog, the compiled Application will close as soon as I press RETURN. How can I prevent/suppress that?
    The CEdit property "Want Return" set to "true" does not seem to work here ... any suggestions?
    Thanks in advance ...

  2. #2
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    This is rather MFC question.

    RETURN is automatically translated to WM_COMMAND with ID 0x00000001 – equivalent of pressing OK button. Even if you get rid of the IDOK framework will still supply this message to a dialog and in turn dialog will close.

    There is many ways of changing that behavior: deriving own CEdit based class and handle PreTranslateMessage, override PreTranslateMessage in dialog or overriding OnOK virtual member of the CDialog class:

    Code:
    void CDlgReturnFix::OnOK(void)
    {
    	CWnd* pWnd = GetFocus();
    	if(GetDlgItem(IDOK) == pWnd)
    	{
    		CDialog::OnOK();
    		return;
    	}
    	NextDlgCtrl(); //will move focus to next control in tab order
    }
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  3. #3
    Join Date
    Dec 2003
    Location
    Belgrade
    Posts
    15
    You need to set "Default button" option for OK button to FALSE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured