|
-
October 19th, 1999, 02:11 PM
#1
CEdit and Return Key
Hi,
I have an EditBox and a button control. I want changes in editBox to be applied (but calling OnButtonClick)
when the user hits the return key. The problem is that, as the Ok button is the default button, the dialog is closed
as soon as we press enter. I tried to change the button style (using BS_DEFPUSHBUTTON) but this doesn't
work. I tried also to subclass the edit control and trap the VK_RETURN in the onChar() member function but
this doesn't work either.
Can you help me?
--
Where there is a WISH, there is a WILL.
-
October 19th, 1999, 03:04 PM
#2
Re: CEdit and Return Key
Override PreTranslateMessage and add the following code
BOOL YourDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_ENTER)
{
OnBtnClicked(); // you could also use post message but this works
return TRUE;
}
}
return yourbaseclass::PreTranslateMessage(pMsg);
}
HTH,
Chris
-
October 19th, 1999, 03:06 PM
#3
Re: CEdit and Return Key
Sorry,
you need to test for the edit control being the window
so make the following change to the function
if (pMsg->wParam == VK_ENTER)
{
if (pMsg->hwnd == ::GetDlgItem(IDC_EDIT))
{
OnBtnClicked(); // you could also use post message but this works
return TRUE;
}
}
HTH,
Chris
-
October 19th, 1999, 03:31 PM
#4
Re: CEdit and Return Key
Thanks. The only problem is that ::GetDlgItem does not take one parameter and and don't know how to obtain the handle of a control (or dialog).
--
Where there is a WISH, there is a WILL.
-
October 19th, 1999, 03:57 PM
#5
Re: CEdit and Return Key
Try GetDlgItem without the scope resolution operator (: . Much simpler.
GetDlgItem(IDC_EDIT);
If, however, you must use ::GetDlgItem, you can get the HWND by calling GetSafeHwnd.
The code would then look like this:
::GetDlgItem(GetSafeHwnd(), IDC_EDIT);
-
October 19th, 1999, 04:05 PM
#6
Re: CEdit and Return Key
Thank you Rabit-toaster, thank you ChriD. I thank you a lot. Everything is working just fine now.
--
Where there is a WISH, there is a WILL.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|