afx_msg void OnCommMscomm1();//函数声明 DECLARE_EVENTSINK_MAP() |
// Generated message map functions //{{AFX_MSG(CSerialPortActivexDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg void OnClearButton(); afx_msg void OnSendButton(); afx_msg void OnCommMscomm1(); DECLARE_EVENTSINK_MAP() //}}AFX_MSG |
BEGIN_EVENTSINK_MAP(CSerialPortActivexDlg, CDialog) //{{AFX_EVENTSINK_MAP(CSerialPortActivexDlg) ON_EVENT(CSerialPortActivexDlg, IDC_MSCOMM1, 1 /* OnComm */, OnCommMscomm1, VTS_NONE) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() |
void CSerialPortActivexDlg::OnCommMscomm1() { // TODO: Add your control notification handler code here UpdateData(true); VARIANT variant_inp; COleSafeArray safearray_inp; long i = 0; int len; char rxdata[1000]; CString tmp; switch (m_mscom.GetCommEvent()) { case 2: //表示接收缓冲区内有字符 { variant_inp = m_mscom.GetInput(); safearray_inp = variant_inp; len = safearray_inp.GetOneDimSize(); for (i = 0; i < len; i++) { safearray_inp.GetElement(&i, &rxdata); } rxdata = '\0'; } m_recv += rxdata; UpdateData(false); break; default: break; } } |
afx_msg void OnCommMscomm(); DECLARE_EVENTSINK_MAP() |
CMSComm m_ComPort; |
BEGIN_EVENTSINK_MAP(CMainFrame, CFrameWnd) ON_EVENT(CMainFrame,ID_COMMCTRL,1,OnCommMscomm,VTS_NONE) //映射ACTIVEX控件的事件 END_EVENTSINK_MAP() |
ComPort.Create(NULL, WS_VISIBLE | WS_CHILD, CRect(0,0,0,0),this, ID_COMMCTRL); |
文章评论(0条评论)
登录后参与讨论