Tuesday, March 22, 2016

ON_NOTIFY vs. OnNotify

It is not always easy to catch WM_NOTIFY send from control to its parent window. 

In this case they want to notify parent CFileView from control CViewTree with WM_NOTIFY TVN_SELCHANGED message. And here message map just doesn't work:

ON_NOTIFY(TVN_SELCHANGED, 4, OnItemsSelChanged)

They should do it in virtual OnNotify function, not using message map. If OnNotify doesn't met correct handler, message would go to parent CMainFrame, and there you can use message map.

BOOL CFileView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
   if (nmHdr->idFrom != 4)
      return CDockablePane::OnNotify(wParam, lParam, pResult);
   if (nmHdr->code == TVN_SELCHANGED)
   {
      OnItemsSelChanged((NMHDR*)lParam, pResult);
      return TRUE;
   }
   return FALSE;
}

No comments:

Post a Comment