C++中添加自訂訊息的響應 (BEGIN_MESSAGE_MAP ON_MESSAGE)

來源:互聯網
上載者:User

BEGIN_MESSAGE_MAP   把訊息和函數指標聯絡起來

1首先要在視窗類別的cpp檔案手動添加訊息響應機制,



ON_MESSAGE(ID,Handler) 
LRESULT   Handler(WPARAM,LPARAM);//響應的函數


BEGIN_MESSAGE_MAP(CShellDlg, CDialog)<br />//{{AFX_MSG_MAP(CShellDlg)<br />ON_MESSAGE(WM_SENDOFFLINE, OnSendOffline) //自訂訊息<br />ON_MESSAGE(WM_SWIPECARD, OnSwipeCard) //自訂訊息<br />ON_MESSAGE(WM_MODEM, OnModem)<br />ON_MESSAGE(WM_PINPAD, OnPinPad)<br />ON_MESSAGE(WM_TRANSACTION, OnTransaction)<br />ON_MESSAGE(WM_THREAD_ERROR, OnThreadError)<br />ON_MESSAGE(WM_SENDRECALL, OnSendRecall)<br />ON_MESSAGE(WM_CHECKTXN, OnOnCheckTxn) //自訂訊息<br />ON_WM_TIMER()<br />ON_WM_KEYDOWN()<br />ON_WM_DESTROY()<br />//}}AFX_MSG_MAP<br />END_MESSAGE_MAP()


  2 其次在視窗類別h檔案添加如下代碼;


// Generated message map functions<br />//{{AFX_MSG(CShellDlg)<br />virtual BOOL OnInitDialog();<br />afx_msg void OnTimer(UINT nIDEvent);<br />afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);<br />afx_msg void OnDestroy();<br />afx_msg LONG OnSwipeCard(WPARAM wParam,LPARAM lParam);<br />afx_msg LONG OnModem(WPARAM wParam, LPARAM lParam);<br />afx_msg LONG OnPinPad(WPARAM wParam, LPARAM lParam);<br />afx_msg LONG OnTransaction(WPARAM wParam, LPARAM lParam);<br />afx_msg LONG OnThreadError(WPARAM wParam, LPARAM lParam);<br />afx_msg LONG OnSendOffline(WPARAM wParam, LPARAM lParam);<br />afx_msg LONG OnSendRecall(WPARAM wParam, LPARAM lParam);<br />afx_msg LONG OnOnCheckTxn(WPARAM wParam, LPARAM lParam);<br />//}}AFX_MSG<br />DECLARE_MESSAGE_MAP()


3 實現響應函數,


LONG XXXDlg::OnOnCheckTxn(WPARAM wParam, LPARAM lParam)<br />{<br />dwCurTranType =0;<br /> .....<br /> //這部分添加自己響應代碼<br />return 0;<br />}<br />


4 最後在自己需要的地方調用自己定義的訊息(訊息響應)

MyMsg(pDlg->m_hWnd, WM_CHECKTXN, (WPARAM)TXN_DOWNTYPE, 0);


//訊息轉寄<br />BOOL MyMsg(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)<br />{<br />BOOL bRet = FALSE;<br />bRet = PostMessage(hWnd, uMsg, wParam, lParam);<br />return bRet;<br />}



這樣就全部OK了,等有時間把測試代碼在整理出來

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.