【正文】
Set the icon for this dialog. The framework does this automatically // when the application39。s main window is not a dialog SetIcon(m_hIcon, TRUE)。 // Set big icon SetIcon(m_hIcon, FALSE)。 // Set small icon // TODO: Add extra initialization here if(()) (FALSE)。 (3)。 //選擇1 if( !()) (TRUE)。//打開串口 else AfxMessageBox(cannot open serial port)。 (9600,n,8,1)。 //波特率9600,無(wú)校驗(yàn),8個(gè)數(shù)據(jù)位,1個(gè)停止位 (1)。 //1:表示以二進(jìn)制方式檢取數(shù)據(jù) (1)。 //參數(shù)1表示每當(dāng)串口接收緩沖區(qū)中有多于或等于1個(gè)字符時(shí)將引發(fā)一個(gè)接收數(shù)據(jù)的OnComm事件 (0)。 //設(shè)置當(dāng)前接收區(qū)數(shù)據(jù)長(zhǎng)度為0 ()。//先預(yù)讀緩沖區(qū)以清除殘留數(shù)據(jù) return TRUE。 // return TRUE unless you set the focus to a control}void CMy10250119Dlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID amp。 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout。 ()。 } else { CDialog::OnSysCommand(nID, lParam)。 }}void CMy10250119Dlg::OnDestroy(){ WinHelp(0L, HELP_QUIT)。 CDialog::OnDestroy()。}// If you add a minimize button to your dialog, you will need the code below// to draw the icon. For MFC applications using the document/view model,// this is automatically done for you by the framework.void CMy10250119Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this)。 // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) (), 0)。 // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON)。 int cyIcon = GetSystemMetrics(SM_CYICON)。 CRect rect。 GetClientRect(amp。rect)。 int x = (() cxIcon + 1) / 2。 int y = (() cyIcon + 1) / 2。 // Draw the icon (x, y, m_hIcon)。 } else { CDialog::OnPaint()。 }}// The system calls this to obtain the cursor to display while the user drags// the minimized window.HCURSOR CMy10250119Dlg::OnQueryDragIcon(){ return (HCURSOR) m_hIcon。}BEGIN_EVENTSINK_MAP(CMy10250119Dlg, CDialog) //{{AFX_EVENTSINK_MAP(CMy10250119Dlg) ON_EVENT(CMy10250119Dlg, IDC_MSCOMM1, 1 /* OnComm */, OnComm, VTS_NONE) //}}AFX_EVENTSINK_MAPEND_EVENTSINK_MAP()void CMy10250119Dlg::OnComm() { // TODO: Add your control notification handler code here VARIANT variant_inp。 COleSafeArray safearray_inp。 LONG len,k。 BYTE rxdata[2048]。 //設(shè)置BYTE數(shù)組 An 8bit integerthat is not signed. CString strtemp。 if(()==2) //事件值為2表示接收緩沖區(qū)內(nèi)有字符 { ////////以下你可以根據(jù)自己的通信協(xié)議加入處理代碼 variant_inp=()。 //讀緩沖區(qū) safearray_inp=variant_inp。 //VARIANT型變量轉(zhuǎn)換為ColeSafeArray型變量 len=()。 //得到有效數(shù)據(jù)長(zhǎng)度 for(k=0。klen。k++) (amp。k,rxdata+k)。//轉(zhuǎn)換為BYTE型數(shù)組 for(k=0。klen。k++) //將數(shù)組轉(zhuǎn)換為Cstring型變量 { BYTE bt=*(char*)(rxdata+k)。 //字符型 (%c,bt)。 //將字符送入臨時(shí)變量strtemp存放 m_strRXData+=strtemp。 //加入接收編輯框?qū)?yīng)字符串 } } UpdateData(FALSE)。 //更新編輯框內(nèi)容 }void CMy10250119Dlg::OnButtonManualsend() { // TODO: Add your control notification handler code here UpdateData(TRUE)。 //讀取編輯框內(nèi)容 (COleVariant(m_strTXData))。//發(fā)送數(shù)據(jù) }