Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC
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.
Posted 24-Dec-12 0:21am
Edited 26-Dec-12 2:33am
v3
Comments
CPallini at 24-Dec-12 6:41am
   
why do you need to repaint after 50 ms?
sundarpalaniappan at 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 at 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 at 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 at 24-Dec-12 8:02am
   
I will call the above Redraw function for every 50ms
Richard MacCutchan at 24-Dec-12 8:46am
   
If you are concerned about speed, then you should stop using MFC and code in the base Win32 functions. MFC tends to add a lot of extra processing just managing objects which is probably not necessary for fast drawing.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v4
Comments
Sergey Alexandrovich Kryukov at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 470
1 mhegazy94 460
2 Ravi Bhavnani 190
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,135
1 OriginalGriff 6,801
2 CPallini 5,350
3 George Jonsson 3,619
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100