Question on CWnd::PreTranslateMessage
Here’s my code sample,
Code:
BOOL XBaseWindow::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
switch (pMsg->message)
{
case WM_LBUTTONUP:
case WM_LBUTTONDOWN:
{
POINT pt = pMsg->pt;
this->ScreenToClient(&pt);
// do something with mouse position
int ret = this->preProcessMouseEvent(pt.x, pt.y);
// if should eat this event, stop its propagation
if (ret == RESULT_GOT_EATEN)
{
return TRUE;
}
}
break;
case WM_KEYDOWN:
case WM_KEYUP:
{
// do something with kb value
int ret = this->preProcessKbEvent((int32_t)pMsg->wParam);
if (ret == RESULT_GOT_EATEN)
{
return TRUE;
}
}
break;
default:
break;
}
return __super::PreTranslateMessage(pMsg);
}
My purpose was to handle those messages accordingly and prevent them from further propagation if necessary, so I have to use PreTranslateMessage to intercept mouse and kb messages.
At the first, it worked. But, if I constructed two XBaseWindow instances, and one was parent window of the other, the problem showed up. For example, when I clicked on the child window, the mouse LBD message was unexpectedly intercepted twice, one in child PreTranslateMessage and one in parent PreTranslateMessage.
I was thinking about that if I have misunderstanding of usage of PreTranslateMessage.
How could I fix it? Thx in advance.
Re: Question on CWnd::PreTranslateMessage
If my old memory is not wrong, this is expected behavior. Parent window will get child's message.
Re: Question on CWnd::PreTranslateMessage
Quote:
If my old memory is not wrong, this is expected behavior. Parent window will get child's message.
You are correct. I know that's expected behavior.
However, what I'd like to do is to handle mouse & kb messages before they get dispatched to target window and optionally determine if they should be further dispatched? Is there another way to get that expect PreTranslateMessage?
thx.
Re: Question on CWnd::PreTranslateMessage
SetWindowsHookEx with WH_MOUSE_LL.