Hello
i am using a CEdit control single line inwhich i need to process the data only on enter key hit, currently i have catch the enter hit by using the
WM_KEYDOWN
in the
PreTranslateMessage
and it works but i am catching the OnKillFocus event too so when the control loses focus i can reset the text to some default text i have.
Problem is that the kill focus message always comes first that the
WM_KEYDOWN
message with the enter key, how can i make the kill focus event ocurr when user hits enter?
Thanks
this is the code i am using now when user hits ENTER WM_KEYDOWN gets generated but at the same time OnKillFocus is called.
BOOL CEditExt::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN || pMsg->wParam == VK_TAB))
{
bool abortEdit = false;
if(pMsg->wParam != VK_RETURN)
{
abortEdit = true;
}
EndEdit(abortEdit);
if(abortEdit == true) return 0;
}
return CEdit::PreTranslateMessage(pMsg);
}
void CEditExt::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
EndEdit(true);
}
void CEditExt::EndEdit(bool cancelEdit)
{
ShowWindow(SW_HIDE);
CString text;
GetWindowTextW(text);
InfoEdit info;
info.setText(text);
::SendMessage( this->GetParent()->GetSafeHwnd(), M_ENDEDIT, (WPARAM)&info, cancelEdit );
SetWindowTextW(_T(""));
}
Oh no!, i just figured out that the call
ShowWindow(SW_HIDE);
was calling the killfocus event so i just move that call down
SetWindowTextW
and is working now
:p