|
-
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.
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
|