MFC编辑框接收数据动态更新与刷新方法代码示例-如何让编辑框内容实时更新

MFC编辑框接收数据动态更新与刷新方法代码示例-如何让编辑框内容实时更新

关键代码:

 1 //发送数据通知
 2 //from txwtech@163.com
 3 LRESULT CCommSampleDlg::OnSendMsg(WPARAM dwEvent,LPARAM dwLen)
 4 {
 5     if(!dwLen)    return 0;
 6     BYTE* temp = new BYTE[dwLen+1];
 7     memset(temp, 0x00, dwLen+1);
 8     memcpy(temp, (const void*)dwEvent, dwLen);
 9     CString log;
10     log.Format("\r\n发送数据=%s", (LPCTSTR)temp);
11     
12     if (m_editLog)
13     {    
14         CEdit* editLog=(CEdit*)FromHandle(m_editLog);
15         if (editLog->GetWindowTextLength()>50000)        
16         {
17             editLog->SetSel(0,-1);
18             editLog->Clear();
19             editLog->SetSel(0,0);
20             editLog->ReplaceSel(log);
21         }
22         else
23         {
24             editLog->SetSel(editLog->GetWindowTextLength(),editLog->GetWindowTextLength());
25             editLog->ReplaceSel(log );
26         }
27     }    
28     return 0;
29 }
30 
31 // 接收消息通知
32 LRESULT CCommSampleDlg::OnRecvMsg(WPARAM dwEvent,LPARAM dwLen)
33 {
34     if(!dwLen)    return 0;
35     BYTE* temp = new BYTE[dwLen+1];
36     memset(temp, 0x00, dwLen+1);
37     memcpy(temp, (const void*)dwEvent, dwLen);
38     CString log;
39     log.Format("\r\n接收数据=%s", (LPCTSTR)temp);
40 
41     if (m_editRecv.GetLength() > 50000)    m_editRecv = "";
42     m_editRecv += log;    
43     UpdateData(FALSE);
44     return 0;
45 }

 

posted @ 2019-06-21 20:41  txwtech  阅读(2770)  评论(0编辑  收藏  举报