why OnKeyDown & OnKeyUp different when they meet "Enter"?
-
I was writing a control "CColorEdit" which is derived from CEdit. I have override its OnKeyUp() and OnKeyDown. When I pressed the key "Enter", the OnKeyDown was invoked, but OnKeyUp wasn't invoked. I feel very confused. Does anyone have ever occured this kind of think. Waiting for answer. Best Regards.
-
I was writing a control "CColorEdit" which is derived from CEdit. I have override its OnKeyUp() and OnKeyDown. When I pressed the key "Enter", the OnKeyDown was invoked, but OnKeyUp wasn't invoked. I feel very confused. Does anyone have ever occured this kind of think. Waiting for answer. Best Regards.
For sure you have put the messagebox code in OnKeyDown. Since the messagebox pops up in OnKeyDown, the focus is gained by the messagebox, so the OnKeyUp will not be handled on the edit box. I tested myself without the messagebox, and for me both keydown and keyup are working fine on a derived class of CEdit.
Habeeballah Hasnoddin :rose:
-
For sure you have put the messagebox code in OnKeyDown. Since the messagebox pops up in OnKeyDown, the focus is gained by the messagebox, so the OnKeyUp will not be handled on the edit box. I tested myself without the messagebox, and for me both keydown and keyup are working fine on a derived class of CEdit.
Habeeballah Hasnoddin :rose:
I think my code is OK. But it still doesn't work. void CTestEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if ( nChar == 13 ) { //MessageBox("Down"); SetWindowText( "Bye Bye Bye" ); } CEdit::OnKeyDown(nChar, nRepCnt, nFlags); }
-
I think my code is OK. But it still doesn't work. void CTestEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if ( nChar == 13 ) { //MessageBox("Down"); SetWindowText( "Bye Bye Bye" ); } CEdit::OnKeyDown(nChar, nRepCnt, nFlags); }
I got the point. ==> You must have "Multiline" and "WantReturn" properties set on this edit box. As I observed while testing, the following is true. --> If you set just the "Multiline" then only keydown gets fired and not the keyup. --> If you set just the wantreturn and not the Multiline then only keyup gets fired and not keydown. thats it.
Habeeballah Hasnoddin
-
I got the point. ==> You must have "Multiline" and "WantReturn" properties set on this edit box. As I observed while testing, the following is true. --> If you set just the "Multiline" then only keydown gets fired and not the keyup. --> If you set just the wantreturn and not the Multiline then only keyup gets fired and not keydown. thats it.
Habeeballah Hasnoddin
Thank you very much. You are so kind.:-D