MFC编辑框接收数据动态更新与刷新方法代码示例-如何让编辑框内容实时更新
关键代码:
//发送数据通知
//from txwtech@163.com
LRESULT CCommSampleDlg::OnSendMsg(WPARAM dwEvent,LPARAM dwLen)
{
if(!dwLen) return ;
BYTE* temp = new BYTE[dwLen+];
memset(temp, 0x00, dwLen+);
memcpy(temp, (const void*)dwEvent, dwLen);
CString log;
log.Format("\r\n发送数据=%s", (LPCTSTR)temp); if (m_editLog)
{
CEdit* editLog=(CEdit*)FromHandle(m_editLog);
if (editLog->GetWindowTextLength()>)
{
editLog->SetSel(,-);
editLog->Clear();
editLog->SetSel(,);
editLog->ReplaceSel(log);
}
else
{
editLog->SetSel(editLog->GetWindowTextLength(),editLog->GetWindowTextLength());
editLog->ReplaceSel(log );
}
}
return ;
} // 接收消息通知
LRESULT CCommSampleDlg::OnRecvMsg(WPARAM dwEvent,LPARAM dwLen)
{
if(!dwLen) return ;
BYTE* temp = new BYTE[dwLen+];
memset(temp, 0x00, dwLen+);
memcpy(temp, (const void*)dwEvent, dwLen);
CString log;
log.Format("\r\n接收数据=%s", (LPCTSTR)temp); if (m_editRecv.GetLength() > ) m_editRecv = "";
m_editRecv += log;
UpdateData(FALSE);
return ;
}