0

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?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
diego2la
  • 97
  • 10
  • Why do you want to do that? The whole point of MFC's architecture is that it reflects messages from the parent to the control that generated the image in the first place, which promotes encapsulation, code reuse, and separation of responsibilities. – Cody Gray - on strike Apr 17 '12 at 17:43
  • My employer gives me that task. Want to redirect message stream because handler on CDialog are already written. I understand that this solution is not agree with encapsulation. But if I wuld redirect message stream the project will be almost ready. Have you got any ideas about this topic ? – diego2la Apr 17 '12 at 18:05
  • http://stackoverflow.com/questions/1506145/how-to-handle-cedit-mouse-click-in-parent-form – Flot2011 Apr 17 '12 at 19:55

1 Answers1

0

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();
} 
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Flot2011
  • 4,601
  • 3
  • 44
  • 61