I've got some control like CtrlTree on CMyDialog. I want to handle messages like ON_WM_LBUTTONDOWN() from CTreeCtrl in the CMyDialog class.

Is there any way in MFC to redirect message stream to parent?

有帮助吗?

解决方案

The simplest way to redirect your messages is just sending a custom (WM_USER + xxx) message from your control's ON_WM_LBUTTONDOWN handler to the parent class.

Place parent's WM_LBUTTONDOWN handler code in a separate method and call this method directly.

Something like that (pseudo code), presuming that your existing code sits in HandleTreeCtrlLBDown()

CMyTreeCtrl::OnLButtonDown(..)
{
   pParent ->SendMessage(WM_TREECTRLLBDOWN, 0, (LPARAM)this);
}

CControlParentDialog::OnTreeCtrlLBDown(wParam, lParam)
{
   HandleTreeCtrlLBDown();
} 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top