MFC下如何定製消息

消息定製:
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 }

LRESULT SendMessage(   HWND hWnd,      // handle of destination window 窗口句柄,例中爲當前窗口,不需要此參數   UINT Msg,       // message to send   WPARAM wParam,  // first message parameter   16位   LPARAM lParam   // second message parameter  32位,一般爲地址 );
 

 

發佈了32 篇原創文章 · 獲贊 10 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章