[RESOLVED] Problem of Trapping "Enter" in Cbutton
hi ,
i want to trap Enter Key when my Button has Focus..
how can i do this .. i have one way the in the PretranslateMessage.
trap the Mesage and check the "Focus" if so then fire the Event
is there any other way to do the same Job
or something general that can be applied to CStatic or CEdit, CcomboBox
thanks with regards
dingo
# 1 Re: [RESOLVED] Problem of Trapping "Enter" in Cbutton
i am still waiting
:)
dingo
# 2 Re: [RESOLVED] Problem of Trapping "Enter" in Cbutton
hi all
i tried with this code and the problem is Partially resolved
UINT CMyEdit::OnGetDlgCode()
{
return DLGC_WANTARROWS|DLGC_WANTALLKEYS|DLGC_WANTCHARS;
}
void CHoverButton::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == VK_RETURN || nChar == VK_SPACE)
{
//AfxMessageBox(_T("got it"));
}
return CBitmapButton::OnKeyDown(nChar,nRepCnt,nFlags);
}
but the problem is when i use tab Key, Focus does not move
dingo
:(
# 3 Re: [RESOLVED] Problem of Trapping "Enter" in Cbutton
Can you explain better what you want to do?
Are you using MFC?
By standard when a button has focus the ENTER key works the same way as a mouse click on the button. Is this what you want?
Regards,
Laitinen
# 4 Re: [RESOLVED] Problem of Trapping "Enter" in Cbutton
thanks for your reply
i am using MFC
and by default when My Button has focus it does not process "Enter" it processes VK_SPACE
and my problem is i want to handle it on "Enter Key"
by the Way i handled it like this , i am not sure to what extent it is right
BOOL CHoverButton::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->wParam == VK_RETURN)
{
GetOwner()->PostMessage(WM_COMMAND,GetDlgCtrlID());
return TRUE;
}
CBitmapButton::PreTranslateMessage(pMsg);
}
but this works
dingo
# 5 Re: [RESOLVED] Problem of Trapping "Enter" in Cbutton
and by default when My Button has focus it does not process "Enter" it processes VK_SPACE
and my problem is i want to handle it on "Enter Key"
Standard dialog procedure transforms Enter key pressing into click on default button - this is one of the most original UI design rule. The default button is featured with bold/highlighted border - visual sign of expecting Enter key pressing to be processed.
Hence, detouring the Enter key processing by intercepting/overriding behavior of current default button may be confusing for ordinary user, and for experienced one - even annoying :mad: (typically it makes user start finding the recycle bin at once ;)).
# 6 Re: [RESOLVED] Problem of Trapping "Enter" in Cbutton
thanks "Igor" for your information
i will make it Default "push Button" but the code i posted
is it right way to do .. .
dingo
# 7 Re: [RESOLVED] Problem of Trapping "Enter" in Cbutton
Yes, your code looks correct - for any other case but button.
Once you make the button default you never need any additional efforts - the system will work for you then. :D