|
-
June 18th, 2010, 02:30 AM
#1
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.
Last edited by LifeIsSuffering; June 18th, 2010 at 02:33 AM.
-
June 18th, 2010, 11:51 AM
#2
Re: Question on CWnd::PreTranslateMessage
If my old memory is not wrong, this is expected behavior. Parent window will get child's message.
henky
----------------------------------
[email protected] is not my email address anymore...
Jangan Pernah Menyerah
-
June 18th, 2010, 08:43 PM
#3
Re: Question on CWnd::PreTranslateMessage
 Originally Posted by [email protected]
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.
-
June 19th, 2010, 04:57 AM
#4
Re: Question on CWnd::PreTranslateMessage
SetWindowsHookEx with WH_MOUSE_LL.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|