各位大神求指导!用MFC做一个界面,下位机每隔一秒通过串口传数据到上位机,现在能接收到数据,要想根据这些数据实时的画矩形,是如何调用onpaint函数啊

阮阮学长 2018-03-20 11:46:49
各位大神求指导!用MFC做一个界面,下位机每隔一秒通过串口传数据到上位机,现在能接收到串口传来的数据,要想根据这些数据实时的画矩形,是如何调用onpaint函数啊,或者如何用这些数据去画图啊,现在我是在类中将串口数据传到onpaint里,然后设置了个定时器,每隔一秒invalidate和updatewindow,但是不能再窗口显示图形啊 ,求各位大神指点指点,我是基于对话框的MFC程序
...全文
436 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
阮阮学长 2018-03-20
  • 打赏
  • 举报
回复
引用 1 楼 wangningyu 的回复:
假设接收的数据是一个矩形坐标点,分两种情况: 1、实时更新,UI上面只有一个矩形显示不擦除上次的,那这种情况,只需要定一个成员/全局变量,串口接收上来的数据更改这个变量,再调用CDC绘,而不是用定时器!! 2、实时更析,UI上面显示多个矩形,不擦除上次的,那就用vector或queue来存储,串口接收的矩形坐标每次都push_back,定时器调CDC绘这个链表或队列的数据即可
我也是这么做的 我是在类中定义一个变量 然后在onpaint中画矩形的时候也是用的同一个变量 但是数据变化时 还是没办法显示图形啊 能不能私聊解释下 谢谢 QQ1361055847
汪宁宇 2018-03-20
  • 打赏
  • 举报
回复
上面打反了,第1种是只显示一个,第2种是多个
汪宁宇 2018-03-20
  • 打赏
  • 举报
回复
假设接收的数据是一个矩形坐标点,分两种情况: 1、实时更新,UI上面只有一个矩形显示不擦除上次的,那这种情况,只需要定一个成员/全局变量,串口接收上来的数据更改这个变量,再调用CDC绘,而不是用定时器!! 2、实时更析,UI上面显示多个矩形,不擦除上次的,那就用vector或queue来存储,串口接收的矩形坐标每次都push_back,定时器调CDC绘这个链表或队列的数据即可
赵4老师 2018-03-20
  • 打赏
  • 举报
回复
CWnd::OnEraseBkgnd afx_msg BOOL OnEraseBkgnd( CDC* pDC ); Return Value Nonzero if it erases the background; otherwise 0. Parameters pDC Specifies the device-context object. Remarks The framework calls this member function when the CWnd object background needs erasing (for example, when resized). It is called to prepare an invalidated region for painting. The default implementation erases the background using the window class background brush specified by the hbrBackground member of the window class structure. If the hbrBackground member is NULL, your overridden version of OnEraseBkgnd should erase the background color. Your version should also align the origin of the intended brush with the CWnd coordinates by first callingUnrealizeObject for the brush, and then selecting the brush. An overridden OnEraseBkgnd should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If it returns 0, the window will remain marked as needing to be erased. (Typically, this means that the fErase member of the PAINTSTRUCT structure will be TRUE.) Windows assumes the background is computed with the MM_TEXT mapping mode. If the device context is using any other mapping mode, the area erased may not be within the visible part of the client area. Note This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function. CWnd Overview | Class Members | Hierarchy Chart See Also WM_ICONERASEBKGND, CGdiObject::UnrealizeObject,WM_ERASEBKGND

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧