locked
PreTranslateMessage(MSG* pMsg) RRS feed

  • Question

  • i make in MFC 7 dialog with many CEdit controls some of them need wantreturn, and i use the function PreTranslateMessage(MSG* pMsg) with this code

    if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )

                   NextDlgCtrl();

                             return TRUE;

    }

    return CDialog::PreTranslateMessage(pMsg);

    but with this code i lost the kill focus and the setfocus

    what i have to do to enable the return key to work like the TAB and when focus to the edit which want the retun ( disable the return working like TAB )

    Wednesday, February 22, 2006 8:00 PM

Answers

  • Looks like this is what you meant to do :-

    BOOL CSomeDlg::PreTranslateMessage(MSG* pMsg)
    {
        if(pMsg->message==WM_KEYDOWN)
        {
            if(pMsg->wParam==VK_RETURN)
                pMsg->wParam=VK_TAB;
        } 
        return CDialog::PreTranslateMessage(pMsg);
    }

     mido1971 wrote:

    i make in MFC 7 dialog with many CEdit controls some of them need wantreturn, and i use the function PreTranslateMessage(MSG* pMsg) with this code

    if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )

                   NextDlgCtrl();

                             return TRUE;

    }

    return CDialog::PreTranslateMessage(pMsg);

    but with this code i lost the kill focus and the setfocus

    what i have to do to enable the return key to work like the TAB and when focus to the edit which want the retun ( disable the return working like TAB )

    Wednesday, February 22, 2006 8:06 PM

All replies

  • Looks like this is what you meant to do :-

    BOOL CSomeDlg::PreTranslateMessage(MSG* pMsg)
    {
        if(pMsg->message==WM_KEYDOWN)
        {
            if(pMsg->wParam==VK_RETURN)
                pMsg->wParam=VK_TAB;
        } 
        return CDialog::PreTranslateMessage(pMsg);
    }

     mido1971 wrote:

    i make in MFC 7 dialog with many CEdit controls some of them need wantreturn, and i use the function PreTranslateMessage(MSG* pMsg) with this code

    if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )

                   NextDlgCtrl();

                             return TRUE;

    }

    return CDialog::PreTranslateMessage(pMsg);

    but with this code i lost the kill focus and the setfocus

    what i have to do to enable the return key to work like the TAB and when focus to the edit which want the retun ( disable the return working like TAB )

    Wednesday, February 22, 2006 8:06 PM
  • thanks for the replay but the pMsg->wParam=VK_TAB is like the code

    NextDlgCtrl() for me and that do the TAB but in CEdit controls with multy line you can't use the tab you need the enter and that is the problem .

     

     

    Wednesday, February 22, 2006 8:51 PM
  • I don't fully get your requirement. You said you want a "tab-to-next-control" effect when the user hits ENTER, didn't you? Do you only want it for non-multiline edits?

     mido1971 wrote:

    thanks for the replay but the pMsg->wParam=VK_TAB is like the code

    NextDlgCtrl() for me and that do the TAB but in CEdit controls with multy line you can't use the tab you need the enter and that is the problem .

     

     

    Thursday, February 23, 2006 12:13 AM
  • yes that it is , only for non-multiline edits?
    Thursday, February 23, 2006 12:29 PM
  •  mido1971 wrote:
    yes that it is , only for non-multiline edits?

    Okay, use this code then :-

    BOOL CSomeDlg::PreTranslateMessage(MSG* pMsg)
    {
        if(pMsg->message==WM_KEYDOWN)
        {
            if(pMsg->wParam==VK_RETURN)
            {
                if(!(GetWindowLong(pMsg->hwnd, GWL_STYLE) & ES_WANTRETURN))
                    pMsg->wParam=VK_TAB;
            }
        }
        return CDialog::PreTranslateMessage(pMsg); 
    }

    Thursday, February 23, 2006 2:41 PM
  • thanks its working
    Thursday, February 23, 2006 8:21 PM