Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
// 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);	
}



SQL
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.
Posted
Updated 26-Dec-12 2:33am
v3
Comments
CPallini 24-Dec-12 6:41am    
why do you need to repaint after 50 ms?
sundarpalaniappan 24-Dec-12 7:04am    
I need to refresh the window every 50ms to show the updated graph, not after 50ms. So paint event will be called every 50ms when i call InvalidateRect function
CPallini 24-Dec-12 7:53am    
That's not a graph, that's a movie!
InvalidateRect, itself doesn't slow down the system (UpdateWindow does). Could you please show us the relavant code?
sundarpalaniappan 24-Dec-12 8:02am    
This is my coding for OnPaint and function for firing OnPaint event


// 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);
}
sundarpalaniappan 24-Dec-12 8:02am    
I will call the above Redraw function for every 50ms

1 solution

I think you have the following options:
  1. Make the drawing code faster (if you can, optimize it).
  2. Update only the needed part of the graph (if you have this option).
  3. Slow down the refresh time.

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.
 
Share this answer
 
v4
Comments
Sergey Alexandrovich Kryukov 24-Dec-12 13:33pm    
My 4. It's all correct, and #3 is most likely also correct but needs correct formulation.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900