如何在自定义消息里传递数据,并在处理函数中接收处理
我代码定义如下:
在 tyView.cpp中
static UINT WM_MY=RegisterWindowMessage("MY_PAINT");
IMPLEMENT_DYNCREATE(CTyphoonView, CView)
BEGIN_MESSAGE_MAP(CTyphoonView, CView)//{{AFX_MSG_MAP(CTyphoonView)ON_WM_PAINT()ON_WM_LBUTTONDOWN()//}}AFX_MSG_MAP// Standard printing commandsON_REGISTERED_MESSAGE(WM_MY,MyPaint)ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)END_MESSAGE_MAP()
在 tyView.h:
// Generated message map functionsprotected://{{AFX_MSG(CTyphoonView)afx_msg void OnPaint();afx_msg void OnLButtonDown(UINT nFlags, CPoint point);//}}AFX_MSGafx_msg void MyPaint(WPARAM wParam, LPARAM lParam);//afx_msg void MyPaint(CString wParam, CString lParam);DECLARE_MESSAGE_MAP()
我从一个模式对话框控件发消息给tyView.cpp中的MyPaint(.......),可是我接受参数是老是出错(参数),不知怎样接收处理?
发送消息函数:
void simalardalg::OnFound1() {// TODO: Add your control notification handler code hereUpdateData();//获取用户输入 CString m_typhoonname;m_typhoonname=m_cstext;//调用第一种查找方案AfxMessageBox(m_cstext);CFile mFile;mFile.Open("typhoonname.txt",CFile::modeCreate|CFile::modeWrite,NULL);mFile.Write(m_typhoonname,m_typhoonname.GetLength());mFile.Close();//调用第一种查询方案
CStdioFile mF;mF.Open("typhoonname.txt",CFile::modeRead,NULL);mF.ReadString(m_typhoonname);mF.Close();if( m_CwndA != NULL ){ m_CwndA->PostMessage(WM_MY_MESSAGE,0,(LPARAM)&m_typhoonname);}CMainFrame *fm;fm=(CMainFrame*)AfxGetApp()->m_pMainWnd;CView *cv;cv=fm->GetActiveView();if( cv != NULL ) cv->PostMessage(WM_MY,(WPARAM)0, (LPARAM)&m_typhoonname);
CDialog::OnCancel();}
接受消息函数:
void CTyphoonView::MyPaint(WPARAM wParam, LPARAM lParam){//CDC *pDC;CString *Para; CString str;CString *str1;char com[100];char year[5];char month[3];char day[4];char hour[3];CStdioFile mF;char *name;int i=0;int j=0;int number=0;Para=(CString *)wParam;//i=wParam;str1=(CString *)lParam;int length=str1->GetLength();char *tserial=new char(length);tserial=str1->GetBuffer(length);
CWnd cw;CRect rgn;cw.GetActiveWindow()->GetClientRect(&rgn); cw.GetActiveWindow()->UpdateWindow();cw.GetActiveWindow()->Invalidate(FALSE);cw.GetActiveWindow()->RedrawWindow(NULL,NULL,RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE);
}
求助!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!