title: (MFC) How can a parent class receive a control's messages if the control is a private member?
body: <p>Let's say my main class has a private member that is a class derived from a CTreeView control.  How can I handle the messages from this tree view control on the main class itself?  </p>
  
  <p>This is similar to the MDI base application that Visual Studios builds for you, where you have two dockable tree view controls named CClassView and CFileView and each has a private member that's derived from CTreeView.</p>
  
  <p>Can I pass the message from the child member control CViewTree to my CFileView class with like this?</p>
  
  <pre><code>void CViewTree::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult)
  {
      GetParent()-&gt;SendMessage(WM_NOTIFY, 0, (LPARAM)pNMHDR);
  }
  </code></pre>
  
  <p>This code throws an exception, but if this does work, how would I handle the TVN_SELCHANGED message in the parent class?</p>
  
  <p>Edit:
  So I've tried the following suggestions but haven't had much luck with either one.</p>
  
  <pre><code>//First try, in the parent .h file:
  afx_msg BOOL OnSelChange(NMHDR *pNMHDR, LRESULT *pResult);
  
  //In the .cpp file:
  ON_NOTIFY_REFLECT_EX(TVN_SELCHANGED, OnSelChange)
  
  //and
  
  BOOL ParentClass::OnSelChange(NMHDR *pNMHDR, LRESULT *pResult)
  {
       AfxMessageBox(L"in handler");
       Return TRUE;
  }
  </code></pre>
  
  <p>Second try:</p>
  
  <pre><code>//in the parent .h file:
  afx_msg void OnSelChange(NMHDR *pNMHDR, LRESULT *pResult);
  
  //In the .cpp file:
  ON_NOTIFY(TVN_SELCHANGED, AFX_IDW_PANE_FIRST, OnSelChange)
  
  //and
  void  ParentClass::OnSelChange(NMHDR *pNMHDR, LRESULT *pResult)
  {
       AfxMessageBox(L"in handler");
  }
  </code></pre>