使用来自串行端口的数据更新对话框,而不会闪烁

编程入门 行业动态 更新时间:2024-10-18 10:32:06
本文介绍了使用来自串行端口的数据更新对话框,而不会闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个基于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.

更多推荐

使用来自串行端口的数据更新对话框,而不会闪烁

本文发布于:2023-11-17 12:36:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1610024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   端口   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!