1首先要在視窗類別的cpp檔案手動添加訊息響應機制,
- //{{AFX_MSG_MAP(CShellDlg)
- ON_MESSAGE(WM_SENDOFFLINE, OnSendOffline) //自訂訊息
- ON_MESSAGE(WM_SWIPECARD, OnSwipeCard) //自訂訊息
- ON_MESSAGE(WM_MODEM, OnModem)
- ON_MESSAGE(WM_PINPAD, OnPinPad)
- ON_MESSAGE(WM_TRANSACTION, OnTransaction)
- ON_MESSAGE(WM_THREAD_ERROR, OnThreadError)
- ON_MESSAGE(WM_SENDRECALL, OnSendRecall)
- ON_MESSAGE(WM_CHECKTXN, OnOnCheckTxn) //自訂訊息
- ON_WM_TIMER()
- ON_WM_KEYDOWN()
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
2 其次在視窗類別h檔案添加如下代碼;
- // Generated message map functions
- //{{AFX_MSG(CShellDlg)
- virtual BOOL OnInitDialog();
- afx_msg void OnTimer(UINT nIDEvent);
- afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
- afx_msg void OnDestroy();
- afx_msg LONG OnSwipeCard(WPARAM wParam,LPARAM lParam);
- afx_msg LONG OnModem(WPARAM wParam, LPARAM lParam);
- afx_msg LONG OnPinPad(WPARAM wParam, LPARAM lParam);
- afx_msg LONG OnTransaction(WPARAM wParam, LPARAM lParam);
- afx_msg LONG OnThreadError(WPARAM wParam, LPARAM lParam);
- afx_msg LONG OnSendOffline(WPARAM wParam, LPARAM lParam);
- afx_msg LONG OnSendRecall(WPARAM wParam, LPARAM lParam);
- afx_msg LONG OnOnCheckTxn(WPARAM wParam, LPARAM lParam);
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
3 實現響應函數,
- LONG XXXDlg::OnOnCheckTxn(WPARAM wParam, LPARAM lParam)
- {
- dwCurTranType =0;
- .....
- //這部分添加自己響應代碼
- return 0;
- }
4 最後在自己需要的地方調用自己定義的訊息(訊息響應)
MyMsg(pDlg->m_hWnd, WM_CHECKTXN, (WPARAM)TXN_DOWNTYPE, 0);
view plaincopy to clipboardprint?
- //訊息轉寄
- BOOL MyMsg(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- BOOL bRet = FALSE;
- bRet = PostMessage(hWnd, uMsg, wParam, lParam);
- return bRet;
- }
這樣就全部OK了