CEdit And OnKeyDown [modified]
-
hi everybody, I m trying to capture a keypress from the user on a CEdit control (Edit TexT). So My Form is a CFormView Based and I have an Edit Texton it. I Added a WM_KEYDOWN ("OnKeyDown" function) via the Windows Message Wizard But still when i press a key nothing will happen here is my code
void CMy65465View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case VK_RETURN:
MessageBox("You pressed Enter");
break;
case VK_F1:
MessageBox("Help is not available at the moment");
break;
case VK_DELETE:
MessageBox("Can't Delete This");
break;
default:
MessageBox("Whatever");
}CFormView::OnKeyDown(nChar, nRepCnt, nFlags);
}
Where is the prob :omg:
"The Ultimate Limit Is Only Your Imagination."
modified on Tuesday, June 8, 2010 11:49 AM
-
hi everybody, I m trying to capture a keypress from the user on a CEdit control (Edit TexT). So My Form is a CFormView Based and I have an Edit Texton it. I Added a WM_KEYDOWN ("OnKeyDown" function) via the Windows Message Wizard But still when i press a key nothing will happen here is my code
void CMy65465View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case VK_RETURN:
MessageBox("You pressed Enter");
break;
case VK_F1:
MessageBox("Help is not available at the moment");
break;
case VK_DELETE:
MessageBox("Can't Delete This");
break;
default:
MessageBox("Whatever");
}CFormView::OnKeyDown(nChar, nRepCnt, nFlags);
}
Where is the prob :omg:
"The Ultimate Limit Is Only Your Imagination."
modified on Tuesday, June 8, 2010 11:49 AM
That key handler (provided you've got a message map entry for it) will only trap key downs for the form view. The edit control is a different window. Your choices here are: - find a WM_COMMAND from the edit control that does what you want and handle that in the form view - derive a class from CEdit and reflect messages from the form view into the control. Do a search for MFC message reflection to see how this works. (This[^] isn't too bad about message reflection but it might be out of date). Cheers, Ash
-
That key handler (provided you've got a message map entry for it) will only trap key downs for the form view. The edit control is a different window. Your choices here are: - find a WM_COMMAND from the edit control that does what you want and handle that in the form view - derive a class from CEdit and reflect messages from the form view into the control. Do a search for MFC message reflection to see how this works. (This[^] isn't too bad about message reflection but it might be out of date). Cheers, Ash
i did add the WM_KDOWN but still nbothing happen when i press a key. I tried it with an application Based on CEditView and it works. It seems a prob with The FormView Class :((
"The Ultimate Limit Is Only Your Imagination."
-
i did add the WM_KDOWN but still nbothing happen when i press a key. I tried it with an application Based on CEditView and it works. It seems a prob with The FormView Class :((
"The Ultimate Limit Is Only Your Imagination."
Isn't CEditView "just" and edit control? Any messages from the edit control will be processed by the CEditView. An edit control on a form view has an additional window involved. Key down message will be processed by the edit control and not the form view. Cheers, Ash
-
Isn't CEditView "just" and edit control? Any messages from the edit control will be processed by the CEditView. An edit control on a form view has an additional window involved. Key down message will be processed by the edit control and not the form view. Cheers, Ash
Ok, what u said is great and means that my edit control, normally, can implement the OnKeyDow function even if my form is CFormView Class. but based on my code (first message) nothing is happening. :sigh:
"The Ultimate Limit Is Only Your Imagination."
-
Isn't CEditView "just" and edit control? Any messages from the edit control will be processed by the CEditView. An edit control on a form view has an additional window involved. Key down message will be processed by the edit control and not the form view. Cheers, Ash
what about PreTranslateMessage ?? how could i know the key pressed by the user ??
"The Ultimate Limit Is Only Your Imagination."
-
Ok, what u said is great and means that my edit control, normally, can implement the OnKeyDow function even if my form is CFormView Class. but based on my code (first message) nothing is happening. :sigh:
"The Ultimate Limit Is Only Your Imagination."
Yep, but your code for the handler is in your CFormView overide, not in a CEdit override. What I'd do is... - Derive a class from CEdit - Add ON_WM_KEYDOWN to its message map - Implement OnKeyDown Snip, snip, Bob's yer Aunty. Cheers, Ash PS: If you do implement it this way remember to call CEdit::OnKeyDown to allow the normal window procedure to handle the keystroke otherwise you'll cripple the behaviour of the edit control.
-
what about PreTranslateMessage ?? how could i know the key pressed by the user ??
"The Ultimate Limit Is Only Your Imagination."
-
Yep, but your code for the handler is in your CFormView overide, not in a CEdit override. What I'd do is... - Derive a class from CEdit - Add ON_WM_KEYDOWN to its message map - Implement OnKeyDown Snip, snip, Bob's yer Aunty. Cheers, Ash PS: If you do implement it this way remember to call CEdit::OnKeyDown to allow the normal window procedure to handle the keystroke otherwise you'll cripple the behaviour of the edit control.
It seems the best way, after all spending 4 hours looking for a function or a sample code is stupid ;P I created a CEdit based class, called CTest in whhich i add the OnKeyDown(...) Now how could call it from the OnChangeEdit1 Function of my CFormView? PS: I need to pass the 3 parameters UINT of OnKeyDown << Newbie question sorry
"The Ultimate Limit Is Only Your Imagination."
modified on Tuesday, June 8, 2010 1:36 PM