RE: Sending Registered Windows Message from one View to another
"Anders Eriksson" wrote:
Hello,
I have an MFC SDI FormView application. I have then added a CSplitterWnd to
MainFrame and created a new CView.
So now I have an MFC SDI app with two views, one CFormView and one CView.
How do I send a Registered Windows Message from the CView to the CFormView
(or the other way)?
The easiest thing you could do, is to pass the correct view type pointers to
each other after creating them [inside CMainFrame]. Then you would be able to
call methods of a view from another one directly. Anyway, this design has an
extra coupling and thus is not the best solution, I think.
Another way [which I think is more correct], is to send a user defined
message. In this case, you have to pass the HWND handlers of views to each
other after their creation. Then from a view you can do:
PostMessage(m_hWndMyFormView, UWM_DOSMTH, 0, 0);
Inside your another view class, there should be a handler;
ON_MESSAGE(UWM_DOSMTH, &OnMyFormView::OnDoSmth)
// ...inside BEGIN/END message map macros
LRESULT OnMyFormView::OnDoSmth(WPARAM, LPARAM)
{
// whatever
}
Of course, you should have your UWM_DOSMTH constant defined (registered).
Yet another way, which almost removes coupling, is to do upward/downward
messaging; first you get the main frame and post a message to it;
AfxGetMainWnd()->PostMessage(UWM_DOSMTH);
....then inside the handler of CMainFrame;
pTheView->PostMassege(UWM_DOSMTH);
Of course, you should have a handler function inside the view class as before.
--
=====
Arman
An internal error has occured while showing an internal error!
-- eclipse