如何制作更快的WM_PAINT事件 [英] How to make faster WM_PAINT event

查看:62
本文介绍了如何制作更快的WM_PAINT事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我创建了一个用于绘制图形的MFC应用程序。为此,我已经为特定区域调用了Invalidate rect函数以每50ms重绘一次(OnPaint事件中的书面代码)。经过一段时间后,由于经常调用InvalidateRect,如何克服这个问题,过程会变慢。





代码:

Hi,

I have created a MFC application for drawing graphs. For this i had called Invalidate rect function for a particular region to repaint every 50ms(Written code in OnPaint event). In this after some time process get slowed due to frequent calling of InvalidateRect how to overcome this issue.


Code:

// This is portion of drawing graph which i had returned in OnPaint event.
void CurveWindow1::OnPaint()
{
	if (m_Graph.m_bSetingFailed)
		return;

	global.UpdateDebugInfo(3);

	CPaintDC dc(this);

	CRect rect;
	GetClientRect(rect);

	m_Graph.BeginDraw(dc.m_hDC, rect);	
	m_Graph.RecalcRects(rect, 2);
	m_Graph.Axes(global.graph1LineColor, 2);
	m_Graph.DrawRealTimeLines(FALSE);
	//m_Graph.DrawBoundary(InitGraph1LineColor, 1);
	m_Graph.EndDraw(dc.m_hDC);	
}

//This will Call OnPaint message for the required area.
void CRealTime::Redraw(HWND hWnd)
{
	RECT rt;
	rt.left   = m_Rect.left - 1;
	rt.top    = m_Rect.top - 1;
	rt.right  = m_Rect.right - 1;
	rt.bottom = m_Rect.bottom - 1;
	::InvalidateRect(hWnd, &rt, FALSE);	
}










I had added time log for each function and find out that Polyline function is taking too much time. It takes nearly 80ms to plot 15000 points.
Is there some other function to make faster.

推荐答案

我认为您有以下选择:

I think you have the following options:
  1. 使绘图代码更快(如果可以,优化它)。
  2. 仅更新图形所需的部分(如果您有此选项) )。
  3. 减慢刷新时间。



我猜选项(3)是唯一真正可行的选项。你可以保持图形表示的正确性(跳过''中间''帧)。



例如,如果你的图表代表,则选项(2)可能是可行的 y = f(x) x ''每次重绘都不会动作太多'。然后你可以向左滚动(这个操作应该更快,然后重新计算和绘图)图形的一个重要部分,并重新计算(和绘制)它的一小部分。


I guess the option (3) is the only one really viable. You may keep the correctness of the graphic representation (skipping ''intermediate'' frames).

Option (2) could be viable if, for instance, your graph represents y=f(x) and x ''doesn''t move too much'' with each repaint. Then you may scroll left (this operation should be faster then recomputing and drawing) a big part of the graph and recompute (and draw) just a small part of it.


这篇关于如何制作更快的WM_PAINT事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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