Handling KeyDown even on Dialog.
-
Why am I not able to handle WM_KEYDOWN on a dialog? Pretranslate is the only way? Also what's the reason the event is not getting dispatched to the dialog?
-
Why am I not able to handle WM_KEYDOWN on a dialog? Pretranslate is the only way? Also what's the reason the event is not getting dispatched to the dialog?
Probably because the control with focus is getting the messages, not the dialog. Add your WM_KEYDOWN handler and add this
PreTranslateMessage
override and you should be good, so long as your dialog is modal:BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
pMsg->hwnd = this->m_hWnd;return CDialog::PreTranslateMessage(pMsg);
}Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Probably because the control with focus is getting the messages, not the dialog. Add your WM_KEYDOWN handler and add this
PreTranslateMessage
override and you should be good, so long as your dialog is modal:BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
pMsg->hwnd = this->m_hWnd;return CDialog::PreTranslateMessage(pMsg);
}Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thanks for your reply Stuart.
Stuart Dootson wrote:
Add your WM_KEYDOWN handler and add this PreTranslateMessage override and you should be good, so long as your dialog is modal:
I could rather manipulate that the key in pretranslate() itself right?
Stuart Dootson wrote:
Probably because the control with focus is getting the messages, not the dialog.
That was my guess, Just to test that I tried deleting all the controls on the dialog. Just a plain dialog but still it's not getting the event. What could be the reason here?
-
Thanks for your reply Stuart.
Stuart Dootson wrote:
Add your WM_KEYDOWN handler and add this PreTranslateMessage override and you should be good, so long as your dialog is modal:
I could rather manipulate that the key in pretranslate() itself right?
Stuart Dootson wrote:
Probably because the control with focus is getting the messages, not the dialog.
That was my guess, Just to test that I tried deleting all the controls on the dialog. Just a plain dialog but still it's not getting the event. What could be the reason here?
grassrootkit wrote:
I could rather manipulate that the key in pretranslate() itself right?
Should be fine
grassrootkit wrote:
What could be the reason here?
I don't know - but Spy++ could tell you if the dialog's getting the WM_KEYDOWN messages?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
grassrootkit wrote:
I could rather manipulate that the key in pretranslate() itself right?
Should be fine
grassrootkit wrote:
What could be the reason here?
I don't know - but Spy++ could tell you if the dialog's getting the WM_KEYDOWN messages?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Okay I'll check them up. Thanks for your responses.