CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2004
    Location
    North Carolina, USA
    Posts
    54

    CDialog + VK_RETURN Problem

    I have a CDialog that I don't want to be closed when the <ENTER> key is pressed, but I can't figure out where to intercept the MFC auto-magic processing. I have tried overriding OnKeyDown, OnChar etc........ and many others, but I'm not getting it! Perhaps too little sleep. Anyhow, I'm sure this is simple, but just elusive right now. Can anyone help?

    Thanks in advance.

  2. #2
    Join Date
    Apr 2004
    Posts
    76
    Hi Koolski

    See below.

    Jeff


    Code:
    ////////////////////////////////////////////////////////
    //
    // Hook up F5 to Refresh
    //
    BOOL CLtrPrtMonDlg::PreTranslateMessage( MSG* pMsg ) {
    
        if( pMsg->message == WM_KEYDOWN ) {
    
            if( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE ) {
    
                // Do it here
    
                return TRUE;
            
            } else if( pMsg->wParam == VK_F5 ) {
        
                ////////////////////////////////////////////////////////
                //
                // Call our Refresh
                //
                RefreshListView();
    
                ////////////////////////////////////////////////////////
                //
                // Any Non-Zero will do
                //
                return TRUE;
            }
        }
    
        return CDialog::PreTranslateMessage(pMsg);
    }

  3. #3
    Join Date
    May 2004
    Location
    North Carolina, USA
    Posts
    54

    Smile

    Thanks! That did the trick.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,185
    Why don't just set an other button to default button??? (standard the default button is IDOK)....

    When you are in an editbox or richedit, just use WantReturn...

    Then the problem is solved too, without code

    Then you still keep the escape key to close the application (so you stay as close as possible to the microsoft styleguide)

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    The answer could have been found in the following FAQ

  6. #6
    Join Date
    Feb 2002
    Posts
    3,788
    Quote Originally Posted by jwalto1
    Hi Koolski

    See below.

    Jeff


    Code:
    ////////////////////////////////////////////////////////
    //
    // Hook up F5 to Refresh
    //
    BOOL CLtrPrtMonDlg::PreTranslateMessage( MSG* pMsg ) {
    
        if( pMsg->message == WM_KEYDOWN ) {
    
            if( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE ) {
    
                // Do it here
    
                return TRUE;
            
            } else if( pMsg->wParam == VK_F5 ) {
        
                ////////////////////////////////////////////////////////
                //
                // Call our Refresh
                //
                RefreshListView();
    
                ////////////////////////////////////////////////////////
                //
                // Any Non-Zero will do
                //
                return TRUE;
            }
        }
    
        return CDialog::PreTranslateMessage(pMsg);
    }
    No intention to be mean, but this is a hack and should not be used.
    See this FAQ for a reason.

  7. #7
    Join Date
    Apr 2004
    Posts
    76
    Hi Alin,

    I was not aware that was considered a hack. I love reading Paul DiLascias.

    Thanks,

    Jeff

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