控件消息送至父窗口处理

来源:互联网 发布:leggings知乎 编辑:程序博客网 时间:2024/05/18 07:38

如果因为变量问题,而不便在控件本身的消息处理函数中处理消息,可将消息发到父窗口处理。如鼠标消息 :

BOOL COwnBitmapBtn::PreTranslateMessage(MSG* pMsg)
{
 // TODO: 在此添加专用代码和/或调用基类
if ((pMsg->message >= WM_MOUSEFIRST) && (pMsg->message <= WM_MOUSELAST))
{
   //dispatch mouse message to parent window 
    CWnd *pParent = GetParent();
    if (pParent != NULL)
    {
     pParent->SendMessage(pMsg->message, pMsg->wParam,
      MAKELPARAM(pMsg->pt.x, pMsg->pt.y));
    }
    return TRUE;
}
 
 return CBitmapButton::PreTranslateMessage(pMsg);
}

原创粉丝点击