
- 加为好友
- 发送私信
- 在线聊天
|
| 发表于:2008-05-21 22:29:263楼 得分:0 |
下面是我线程的代码 UINT CommProc(LPVOID pParam) { OVERLAPPED os; DWORD dwMask,dwTrans; COMSTAT ComStat; DWORD dwErrorFlags; CTTYDoc *pDoc=(CTTYDoc*)pParam; memset(&os,0,sizeof(OVERLAPPED)); os.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL); if(os.hEvent=NULL) { AfxMessageBox("can't creat event object"); return (UINT)-1; } while(pDoc->m_bConnected) { ClearCommError(pDoc->m_hCom,&dwErrorFlags,&ComStat); if(ComStat.cbInQue) { WaitForSingleObject(pDoc->m_hPostMsgEvent,INFINITE); ResetEvent(pDoc->m_hPostMsgEvent); PostMessage(pDoc->m_hTermWnd,WM_COMMNOTIFY,EV_RXCHAR,0); continue; } dwMask=0; if(!WaitCommEvent(pDoc->m_hCom,&dwMask,&os)) { if(GetLastError()==ERROR_IO_PENDING) GetOverlappedResult(pDoc->m_hCom,&os,&dwTrans,TRUE); else { CloseHandle(os.hEvent); return (UINT)-1; } } } CloseHandle(os.hEvent); return 0; } 消息是 LRESULT CTTYView::OnCommNotify(WPARAM wParam,LPARAM lParam) { char buf[MAXBLOCK/4]; CString str; int nLength,nTextLength; CTTYDoc* pDoc=GetDocument(); CEdit &edit=GetEditCtrl(); if(!pDoc->m_bConnected ¦ ¦(wParam&EV_RXCHAR)!=EV_RXCHAR) { SetEvent(pDoc->m_hPostMsgEvent); return 0L; } nLength=pDoc->ReadComm(buf,100); if(nLength) { nTextLength=edit.GetWindowTextLength(); edit.SetSel(nTextLength,nTextLength); for(int i=0;i <nLength;i++) { switch(buf[i]) { case '\r': if(!pDoc->m_bNewLine) break; case '\n': str+="\r\n"; break; case '\b': edit.SetSel(-1,0); edit.ReplaceSel(str); nTextLength=edit.GetWindowTextLength(); edit.SetSel(nTextLength-1,nTextLength); edit.ReplaceSel(""); str=""; break; case '\a': MessageBeep((UINT)-1); break; default: str==buf[i]; } } edit.SetSel(-1,0); edit.ReplaceSel(str); } SetEvent(pDoc->m_hPostMsgEvent); return 0L; } 帮我看看会是什么问题 大概如果有兴趣的 请留下E -Mail我发代码给你 谢谢各位了 | | |
修改
删除
举报
引用
回复
| |