Consume events in MFC's CStatic and pass them to the parent

好久不见. 提交于 2019-12-07 15:23:29

No, you're misunderstanding. SS_NOTIFY does not cause your CStatic to receive messages, it causes the CStatic to relay messages back to the parent. So "Now I am able to receive message events through message map directly in MyStatic" is based on a false premise.

This is an important point to make because a control can only receive messages for itself, not for its children, unless those children 'play along' by relaying messages or by doing other tricks (global hooking, ...) ; but those cases are the exception, the 'normal' way is that each window receives messages for itself.

So that answers your question: no, there is no way to let both a parent (your CDialog) and a child (your CStatic) receive mouse events without doing so 'manually' or getting involved in tedious message routing hacks. So in your case, what you need to do is GetParent()->SendMessage(WM_LBUTTONDOWN, ...) etc, manually recreating the WPARAM and LPARAM values; or calling OnLButtonDown directly on the CDialog: GetParent()->OnLButtonDown(...). You'll have to think about what mouse coordinates you pass back to CDialog though, you may need to translate them to the CDialog's client coordinates.

If you call the base OnLButtonDown handler, the message should be sent to the parent.

CMyStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
    CStatic::OnLButtonDown(nFlags, point);

    // custom handling
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!