使用来自串行端口的数据更新对话框,而不会闪烁 [英] Update dialog with data from serial port, without flickering

查看:85
本文介绍了使用来自串行端口的数据更新对话框,而不会闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于SDI的MFC项目,在其中我通过在MainFrame类中放置代码来创建了一个对话框.表单对话框有一个只读的编辑框,我要在其中显示从串行端口连续接收到的数据.我在视图类中有以下代码:

I have SDI based MFC project, in which I created a dialog by placing code in MainFrame class. The form dialog has a readonly edit box where I want to display data continuously received from serial port. I have the following code in the view class:

void CSerialCommView::OnDraw(CDC* /*pDC*/)
{
	CDC MemDC;
	CSerialCommDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
	 return;
	CString mystr=SerialPortContinuousRead(); ===> works fine
	mystr += "\r\n";

	CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
	CEdit* DispBox=(CEdit*)pFrame->m_wndDlgBar.GetDlgItem(IDC_DISPLAY_BOX); 
	DispBox->SetWindowTextW(mystr);
}



当我在此函数中有断点时,它将在编辑框中更新数据,否则我将看不到数据.感谢任何帮助,谢谢



When I have break points in this function it updates the data in edit box, otherwise I can''t see the data. Any help appreciated, thanks

推荐答案

我不知道这是否有帮助,但是当我想用实时"数据更新对话框时,通常设置计时器以读取和显示最新值.

我不确定这是否是您要的内容,因此希望对您有所帮助. :)
I don''t know if this helps but when I want to update a dialog box with ''real time'' data I normally setup a timer to read and display the latest value.

I''m not sure if that''s is what you are asking, so I hope that helps. :)


嗨艾莉森,

我添加了计时器来更新编辑"框.我的计时器功能中包含以下代码.

Hi Alison,

I have added timer to update Edit box. The following code i have in the timer function.

void CSerialCommView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
  CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
  CEdit* DispBox=(CEdit*)pFrame->m_wndDlgBar.GetDlgItem(IDC_DISPLAY_BOX); 
  dispstr+=mydatastr+_T("\n");
  DispBox->SetWindowTextW(dispstr);
  DispBox->LineScroll(DispBox->GetLineCount());
  Invalidate(true);
 CView::OnTimer(nIDEvent);
}



问题是,由于



The problem is,the dialog flickers because of

Invalidate(true)

,对话框闪烁.

是否有其他任何方法都可以更新而不会出现闪烁问题. :omg:
谢谢.

.

Is there any other method which will just update without flickering problem. :omg:
Thanks.


设置文本后,与其调用Invalidate(),不如尝试以下操作:
Instead of calling Invalidate() after you set the text, try this:
CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
CEdit* DispBox=(CEdit*)pFrame->m_wndDlgBar.GetDlgItem(IDC_DISPLAY_BOX);
DispBox->SetWindowTextW(mystr);
DispBox->UpdateWindow();


这将仅导致编辑控件更新-而不是整个窗口.

希望有帮助.


That will cause only the edit control to update - not the entire window.

Hope that helps.


这篇关于使用来自串行端口的数据更新对话框,而不会闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆