Key messages in Dialog app
-
Hi guys :-O, the other day i was developing a game(the snake game, as in Nokia cellphones) in a dialog based application. I encountered a serious problem X| , when i wasn't able to track the keyoard events for the arrow keys(VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN). I have used all possible means, like OnKeyDown() and OnChar() but there is no result:eek:. Can anyone tell me where i am going wrong. ;)Thanx in advance.;) AslFunky
-
Hi guys :-O, the other day i was developing a game(the snake game, as in Nokia cellphones) in a dialog based application. I encountered a serious problem X| , when i wasn't able to track the keyoard events for the arrow keys(VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN). I have used all possible means, like OnKeyDown() and OnChar() but there is no result:eek:. Can anyone tell me where i am going wrong. ;)Thanx in advance.;) AslFunky
Hint: Handle
PreTranslateMessage(MSG* pMsg)
filter the messageWM_KEYDOWN
:cool: ARSALAN MALIK -
Hint: Handle
PreTranslateMessage(MSG* pMsg)
filter the messageWM_KEYDOWN
:cool: ARSALAN MALIKThankx for replying. I think i am understanding what you are talking about. I have checked the MSDN and it has three versions of PreTranslateMessage(), namely: CWinApp, CWinThread and CWnd. It certainly cannot be CWinThread. Which of the remaining two should I handle? I hope it is the CWinApp! Can i do it as: BOOL bHandleNow = FALSE; switch (lpmsg->message) { case WM_KEYDOWN: switch (lpmsg->wParam) { case VK_UP: case VK_DOWN: case VK_LEFT: case VK_RIGHT: bHandleNow = TRUE; break; } if (bHandleNow) OnKeyDown(lpmsg->wParam, LOWORD(lpmsg ->lParam), HIWORD(lpmsg->lParam)); break; } return bHandleNow; Please, it would be a lot of help. ;)Thanx in advance;)! AslFunky
-
Hi guys :-O, the other day i was developing a game(the snake game, as in Nokia cellphones) in a dialog based application. I encountered a serious problem X| , when i wasn't able to track the keyoard events for the arrow keys(VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN). I have used all possible means, like OnKeyDown() and OnChar() but there is no result:eek:. Can anyone tell me where i am going wrong. ;)Thanx in advance.;) AslFunky
maybe u dont get the keyz coz u have some other (control or) window on ut dialog box...... that can be the reason,have u tried SetFocus()??? hope that helpz..... happy programmin..... cheerz..... :-D
-
Thankx for replying. I think i am understanding what you are talking about. I have checked the MSDN and it has three versions of PreTranslateMessage(), namely: CWinApp, CWinThread and CWnd. It certainly cannot be CWinThread. Which of the remaining two should I handle? I hope it is the CWinApp! Can i do it as: BOOL bHandleNow = FALSE; switch (lpmsg->message) { case WM_KEYDOWN: switch (lpmsg->wParam) { case VK_UP: case VK_DOWN: case VK_LEFT: case VK_RIGHT: bHandleNow = TRUE; break; } if (bHandleNow) OnKeyDown(lpmsg->wParam, LOWORD(lpmsg ->lParam), HIWORD(lpmsg->lParam)); break; } return bHandleNow; Please, it would be a lot of help. ;)Thanx in advance;)! AslFunky
For dialog based MFC application, add
PreTranslateMessage
as virtual function from class menu. ARSALAN MALIK -
maybe u dont get the keyz coz u have some other (control or) window on ut dialog box...... that can be the reason,have u tried SetFocus()??? hope that helpz..... happy programmin..... cheerz..... :-D
Hi, thanx for replying. Yes, i have tried using SetFocus(), but that doesn't work. Anyway, Arsalan Malik has given the right solution. We must override the virtual function
PreTranslateMessage()
of the CWnd class. In this code we have to return aTRUE
for the keydown messages if they are VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT. These are stored in the HIWORD and LOWORD of the message of the lpMsg paramater. Please refer to MSDN if you cannot get this. It is quite clear there. Thanx anyway. Bye /--------\ |AslFunky| \--------/ -
For dialog based MFC application, add
PreTranslateMessage
as virtual function from class menu. ARSALAN MALIKOh, you got it all wrong. What i meant was, which class's
PreTranslateMessage()
should i override, since PreTranslateMessage() is a virtual function in three classes. Anyway, i have got the answer, we must override the CWnd class's function. ;) Thanx a lot for helping me out. That was a real relief ;) /--------\ |AslFunky| \--------/