消息定製: 1) 建立消息號 #define MYMESSAGE WM_USER+106 2) 消息映射 ON_MESSAGE(MYMESSAGE, OnMyMessage) 3) 消息函數定義 afx_msg void OnMyMessage(WPARAM wParam,LPARAM lParam); 4) 實現消息函數 void CMainFrame::OnMyMessage(WPARAM wParam,LPARAM lParam) { CString prompt; prompt.Format("%s",lParam); AfxMessageBox(prompt); }
5) 發送消息 PostMessage異步的,需要外部定義,或者加上static. SendMessage同步的,等待消息處理完,可以在堆棧中定義. void CShhApp::OnAppAbout() { static char myParameter[]="my test"; CAboutDlg aboutDlg; aboutDlg.DoModal();
AfxGetMainWnd()->PostMessage(MYMESSAGE,0,(LPARAM)myParameter);//Asynchron // SendMessage(MYMESSAGE,1000,(LPARAM)myParameter);//Synchron }