Make Enter Key Work Tab Key in CEdit, PreTranslateMessage(MSG* pMsg) question.
I'm try to override the Enter Key and make it act like a Tab Key to go to the next control but it's not working. How can I return TabKey excution in the following code?
TIA
BOOL CEditCustom::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// ENTER key
if((pMsg->message == WM_KEYDOWN) &&
(pMsg->wParam == VK_RETURN))
{
// Enter key was hit -> do whatever you want
AfxMessageBox("The Enter Key was Hit");
pMsg->wParam = VK_TAB;
//this->SendMessage(WM_KILLFOCUS);
return TRUE;
}
return CEdit::PreTranslateMessage(pMsg);
}
[727 byte] By [
ADSOFT] at [2007-11-20 1:35:28]

# 1 Re: Make Enter Key Work Tab Key in CEdit, PreTranslateMessage(MSG* pMsg) question.
Changing the Behavior of Enter with DLGKEYS Sample App? ( http://msdn.microsoft.com/msdnmag/issues/0700/c/default.aspx)
Alin at 2007-11-10 23:18:01 >

# 2 Re: Make Enter Key Work Tab Key in CEdit, PreTranslateMessage(MSG* pMsg) question.
Somebody said:
Using PreTranslateMessage is similar to a aspirin prescription from the doctor who does not know what is wrong with you.
You should not use PreTranslateMessage. You can use code as in the sample below:
UINT CAllKeysEdit::OnGetDlgCode()
{
return /*CEdit::OnGetDlgCode()*/ DLGC_WANTALLKEYS;
}
void CAllKeysEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(VK_RETURN == nChar || VK_TAB == nChar)
{
CDialog *pParent = (CDialog*)GetParent();
pParent->NextDlgCtrl();
return;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
JohnCz at 2007-11-10 23:18:56 >

# 3 Re: Make Enter Key Work Tab Key in CEdit, PreTranslateMessage(MSG* pMsg) question.
The following works
BOOL CEditCustom::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// ENTER key
if((pMsg->message == WM_KEYDOWN) &&
(pMsg->wParam == VK_RETURN))
{
// Enter key was hit -> do whatever you want
AfxMessageBox("The Enter Key was Hit");
pMsg->wParam = VK_TAB;
return CEdit::PreTranslateMessage(pMsg);
return TRUE;
}
return CEdit::PreTranslateMessage(pMsg);
}
I placed ' return CEdit::PreTranslateMessage(pMsg); ' in the section where you trap the VK_TAB key.
ADSOFT at 2007-11-10 23:20:01 >

# 4 Re: Make Enter Key Work Tab Key in CEdit, PreTranslateMessage(MSG* pMsg) question.
Somebody said:
Using PreTranslateMessage is similar to a aspirin prescription from the doctor who does not know what is wrong with you.
You should not use PreTranslateMessage. You can use code as in the sample below:
UINT CAllKeysEdit::OnGetDlgCode()
{
return /*CEdit::OnGetDlgCode()*/ DLGC_WANTALLKEYS;
}
void CAllKeysEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(VK_RETURN == nChar || VK_TAB == nChar)
{
CDialog *pParent = (CDialog*)GetParent();
pParent->NextDlgCtrl();
return;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
I got that to work too. Thanks.
ADSOFT at 2007-11-10 23:20:55 >

# 5 Re: Make Enter Key Work Tab Key in CEdit, PreTranslateMessage(MSG* pMsg) question.
The following works
BOOL CEditCustom::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// ENTER key
if((pMsg->message == WM_KEYDOWN) &&
(pMsg->wParam == VK_RETURN))
{
// Enter key was hit -> do whatever you want
AfxMessageBox("The Enter Key was Hit");
pMsg->wParam = VK_TAB;
return CEdit::PreTranslateMessage(pMsg);
return TRUE;
}
return CEdit::PreTranslateMessage(pMsg);
}
I placed ' return CEdit::PreTranslateMessage(pMsg); ' in the section where you trap the VK_TAB key.
In addition to JohnCz, take a look at When to use or not use PreTranslateMessage (http://www.flounder.com/messaging.htm)
Ejaz at 2007-11-10 23:21:59 >
