[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
[371 byte] By [dingo_kasper] at [2007-11-20 7:07:01]
# 1 Re: [RESOLVED] Problem of Trapping "Enter" in Cbutton
i am still waiting
:)
dingo
dingo_kasper at 2007-11-10 23:00:04 >
# 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
:(
dingo_kasper at 2007-11-10 23:00:59 >
# 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
laitinen at 2007-11-10 23:01:57 >
# 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
dingo_kasper at 2007-11-10 23:02:57 >
# 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 ;)).
Igor Vartanov at 2007-11-10 23:04:07 >
# 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
dingo_kasper at 2007-11-10 23:05:01 >
# 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
Igor Vartanov at 2007-11-10 23:06:05 >