ChildView.cpp; (class CChildView : public CWnd, OnPaint() is here)
MainFrm.cpp; (class CMainFrame : public CFrameWnd)
ImagePro.cpp;(class CImageProApp : public CWinApp)
I also create CModalLessDlg using the dialog template, which is defined in ModalLessDlg.cpp and ModalLessDlg.h
In the ModalLessDlg.cpp, I want to press the "Begin" button to send a text to the "view"
you can realize it like this:
1. in MainFrm.h, there is one protected variable:
protected: CChildView m_wndView;
change it as public variable:
public: CChildView m_wndView;
2. in ModalLessDlg.cpp:
#define WM_MY_DOSOME (WM_USER+1)
3. in ModalLessDlg.cpp:
void CModalLessDlg::OnBegin() //
{
// TODO: start
CMainFrame *pFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
char buf[]="I LOVE YOU";
(pFrame->m_wndView).SendMessage(WM_MY_DOSOME,(WPARAM)buf,0);
}
4. In ChildView.h, add the following:
afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);//before DECLARE_MESSAGE_MAP()
5. in ChildView.cpp, add the following:
BEGIN_MESSAGE_MAP(CChildView, CWnd) // ... ON_MESSAGE(WM_MY_DOSOME,OnMyMessage) //only need to add this line //... END_MESSAGE_MAP()//then realize the response function:
LRESULT CChildView::OnMyMessage(WPARAM iParam1,LPARAM iParam2)
{
char *buf=(char *)iParam1;
CString str;
str.Format("%s",buf);
MessageBox(str);
return 0L;
}
the function is only a test to see whether you can receive the text or not, you can also show it in the client area of the view through Invalidate() again in this OnMyMessage function.

No comments:
Post a Comment