|
How to stop flickering in MFC app |
Posted by Roger on Jan-19-2006 19:48 |
|
Hi
I am using your software in an MFC app. I am using a gauge in a "realtime" app. I get flickering when I redraw the gauge, no matter how slow the redraw timer (> 5 seconds even). Here is the code which is called by the timer routine:
BaseChart *c = roundmeter(ttt++);
m_ChartViewer.setChart(c);
delete c;
Both roundmeter() and setChart() are your code obviously.
Any ideas?
Thank you
Roger |
Re: How to stop flickering in MFC app |
Posted by Peter Kwan on Jan-20-2006 02:01 |
|
Hi Roger,
I think the most common way to avoid flickering is to use double buffering.
The ChartViewer that is included in the ChartDirector MFC sample code are designed as sample code to illustrate how to display a chart on screen using the MFC GUI framework. For simplicity (so people can follow the code easily), the sample code does not use double-buffering.
I think you may modify the code to use double-buffering. The easy method should be to create two ChartViewer objects, but only allows one to be visible (may be using ShowWindow in the CWnd superclass). One only updates the invisible ChartViewer, and then make it visible, and then hide the other ChartViewer.
(The more complex method would be to subclass the OnPaint method and paint it on screen yourself.)
Hope this can help.
Regards
Peter Kwan |
Re: How to stop flickering in MFC app |
Posted by Roger on Jan-20-2006 16:26 |
|
Hi Peter
I tried this but it didn't seem to make any difference. Is that what you meant by double-buffering?
BaseChart *c = roundmeter(ttt++);
m_ChartViewer[!m_bCurrGauge].setChart(c);
delete c;
m_ChartViewer[m_bCurrGauge].ShowWindow(FALSE);
m_ChartViewer[!m_bCurrGauge].ShowWindow(TRUE);
m_bCurrGauge = !m_bCurrGauge;
Regards
Roger |
Re: How to stop flickering in MFC app |
Posted by Peter Kwan on Jan-20-2006 20:10 |
|
Hi Roger,
Actually, from my impression even the original ChartViewer sample code may not flicker. Today, I tried myself by modifying a sample charting code so as to generate a "real time" chart. It works normally without any flickering, even if I updated it 10 times per second.
I have uploaded my complete sample code to http://www.advsofteng.com/scrollzoomdemo.zip
The sample code is a complete VC++ project. It also contains the compiled file "scrollzoomdemo.exe" that you may try to run. The compiled code updates the chart 5 times per second.
When you test the code, please ensure you use "Release" mode and also you "execute" the code. Do not use "Start Debug" to run the code, as all code will run much slower in the Visual Studio debugger. (Anyway, I my case, even if I use "Debug" mode and use "Start Debug", it still does not flicker.)
If you try the above code, and it does not flicker, but in your own code, it flickers, I suspect may be the flickering is not related to the ChartViewer control, but related to other things on the Window form. The container may also affect whether the controls flickers or not, as the container specifies how and when the control redraws itself. I suspect the thread the draws the control also affects whether the control flickers or not, although I have not tried myself. (In the sample code, the control is drawn on the main GUI thread.)
Finally, what I mean double buffer is similar to what you are doing, except that I would try to show the second chart before hiding the first chart. But from my testing, it seems double buffering may not be needed. If the problem is in fact not related to double buffering, the double buffer may not solve the problem.
//show chart first - then hide chart
m_ChartViewer[!m_bCurrGauge].ShowWindow(TRUE);
m_ChartViewer[m_bCurrGauge].ShowWindow(FALSE);
Regards
Peter Kwan |
Re: How to stop flickering in MFC app |
Posted by Roger on Jan-21-2006 01:06 |
|
Hi Peter
You are correct. The problem is with my application. I ran your sample and it works perfectly. As you say, double buffering is not necessary. Thank you very much for your help.
Regards
Roger
ChartDirector is excellent software by the way. |
Re: How to stop flickering in MFC app |
Posted by Patrick Riphagen on Aug-13-2007 16:19 |
|
Sorry to bring up this old topic again.
I am using chartDirector in MFC in an MDI child fromView.
I have the flickering, and I suspect also the problem is not with ChartDirector and double buffering.
You did not mention how you solved the issue. In the example applications I do not have the flickering at all.
Can you tell me how I might resolve this issue? (Not using double buffering?) |
Re: How to stop flickering in MFC app |
Posted by Peter Kwan on Aug-14-2007 04:07 |
|
Hi Patrick,
If you update the chart in the same way is the example application, and there is no flickering, that means the ChartDirector ChartViewer control will not flicker at all.
However, even if the ChartDirector ChartViewer control does not flicker at all, the entire application may still flicker. For example, the application may decide to redraw the entire Window or frame or client area, etc., when one of its control changes.
If you search google for MDI flicker, you may found that MDI is very easy to flicker. Even an empty MDI window can flicker. There are many solutions suggested by various people. May be you can try these suggestions to see if anyone can work.
Regards
Peter Kwan |
Re: How to stop flickering in MFC app |
Posted by Peter Kwan on Aug-14-2007 04:57 |
|
Hi Patrick,
I have just tried myself. I added WS_EX_COMPOSITED to the window style of the child MDI form, and it appears to avoid the flickering.
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.dwExStyle |= WS_EX_COMPOSITED;
if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
So I think in addition to the controls, the entire MDI Child Form needs to be configured for double-buffering.
Hope this can help.
Regards
Peter Kwan |
Re: How to stop flickering in MFC app |
Posted by pengwei on Aug-03-2013 01:22 |
|
to avoid flicker, I found anothre way...
Use Unicode Character Set --> flicker
Use Multi-Byte Character Set --> no flicker
strange >< |
Re: How to stop flickering in MFC app |
Posted by Cherry on Aug-13-2013 14:33 |
|
pengwei wrote:
to avoid flicker, I found anothre way...
Use Unicode Character Set --> flicker
Use Multi-Byte Character Set --> no flicker
strange ><
Yes, I have also found this issue.
Even if using the Unicode Character Set, comment out the following part in the stdafx.h
file, the flicker will also stop:
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\\"type='win32'
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86'
publicKeyToken='6595b64144ccf1df' language='*'\\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\\"type='win32'
name='Microsoft.Windows.Common-Controls' version='6.0.0.0'
processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\\"type='win32'
name='Microsoft.Windows.Common-Controls' version='6.0.0.0'
processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\\"")
#else
#pragma comment(linker,"/manifestdependency:\\"type='win32'
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*'
publicKeyToken='6595b64144ccf1df' language='*'\\"")
#endif
#endif
But this will cause the Window Common controls fail Xp style support! |
Re: How to stop flickering in MFC app |
Posted by Peter Kwan on Aug-13-2013 23:28 |
|
Hi Cherry,
Thanks for providing this really important piece of information.
As the statements are related to Windows Common Controls, I remembered seeing Windows
Common Controls in the standard Windows File Explorer to flicker on Windows XP as well. If
the Windows XP is configured to "Show window contents while dragging" (in "Control Panel
=> Display Properties => Appearance => Effects => checked the "Show window contents
while dragging" box => Click OK and Apply), then when I resize the File Explorer with the
directory "Tree View" on the left, I can see the Tree View and the status bar flicker.
I am suspecting the Windows Common Controls somehow causes the entire window to be
repaint from bottom up (that is, the window is painted with background color first, wiping
away everything, then the contents are repainted on top of the background color). Because
the window is painted with the background color first before the contents are painted, this
cause flickering.
Regards
Peter Kwan |
Re: How to stop flickering in MFC app |
Posted by Cherry on Aug-14-2013 09:20 |
|
Hi Peter,
Firstly, thank you for your timely reply!
I have double checked the special feature of Windows Common Controls on Windows XP.
When I resize or move the File Explorer with the directory "Tree view" on the left, I can see
the view and status bar flickering.
But I still wonder why the flicker takes place just when I move the track cursor(dynamic
layer), not resize or move the Chartview window.
Best Regards
Cherry
|
Re: How to stop flickering in MFC app |
Posted by Chang on Jan-14-2014 13:19 |
|
I have same problem.
How could i fix this? |
Re: How to stop flickering in MFC app |
Posted by Peter Kwan on Jan-16-2014 04:27 |
|
Hi Chang,
As you may have noticed, in our sample code, the charts do not flicker. Some of our
customers have reported that the flickering occurs when Windows Common Controls are
used, and some mentioned about XP Themes support. It is also commonly reported in
various forums in the Internet that Windows Common Controls can cause the MFC CStatic
objects to flicker. (CChartViewer inherits from CStatic, and CStatic is the class that actually
displays the chart to the screen)
Without knowing the exact reason that may have caused the flickering, I have modified the
CChartViewer.cpp and CChartViewer.h to by-pass the CStatic OnPaint implementation
entirely. It seems to work in my test case. I have attached the modified CChartViewer for
your reference. Please kindly try them in your code and please inform me if it does solve the
problem.
Regards
Peter Kwan
|
Re: How to stop flickering in MFC app |
Posted by Cherry on Jan-16-2014 13:59 |
|
Peter Kwan wrote:
Hi Chang,
As you may have noticed, in our sample code, the charts do not flicker. Some of our
customers have reported that the flickering occurs when Windows Common Controls are
used, and some mentioned about XP Themes support. It is also commonly reported in
various forums in the Internet that Windows Common Controls can cause the MFC CStatic
objects to flicker. (CChartViewer inherits from CStatic, and CStatic is the class that actually
displays the chart to the screen)
Without knowing the exact reason that may have caused the flickering, I have modified the
CChartViewer.cpp and CChartViewer.h to by-pass the CStatic OnPaint implementation
entirely. It seems to work in my test case. I have attached the modified CChartViewer for
your reference. Please kindly try them in your code and please inform me if it does solve the
problem.
Regards
Peter Kwan
Hi Peter,
Thank you for your reply and endeavor. I have tried your modified files into my project, and now the flickering has no longer existed. Once I moved the cursor upon the charview, it would flicker associated with the moving. But now it is OK.
Regards
Cherry |
Re: How to stop flickering in MFC app |
Posted by Chang on Jan-23-2014 16:56 |
|
Hi, Peter.
Thank you very much.
It's very helpful to me.
Regards
Chang |
|