CDockablePane - Sliding - Redrawing
-
Sunday, April 29, 2012 3:26 PM
Dear all,
I have an MFC MDI application using the new MFC Feature Pack. I have a CDockablePane that has the autohide option enabled. My CView driven class takes a lot of time to be drawn. The problem I am facing is that when the pane is sliding (to autohide or auto appear), each step in the sliding makes the CView redraw itself! This is making the sliding takes a lot of time and the application appears very heavy. Is there a way to avoid these unnecessary redrawings and draw the CView driven object only once?
Thank you :)
All Replies
-
Sunday, April 29, 2012 4:10 PM
An idea:
In your CView drawing code, check if CDockablePane is visible. If it is visible, it means it's still sliding. Draw your painting code only when it's not visible.
The code that slide your CDockablePane in and out is in CMFCAutoHideBar::OnMouseMove(). You might want to check that out.
Another approach could be adding WM_SHOWWINDOW message handler to your CDockablePane, which could freeze and unfreeze your CView class's drawing when the visiblity state of CDockablePane is about to change--that way, your CView painting code doesn't need to check for CDockablePane visibility state everytime when it paints.
- Marked As Answer by Helen ZhaoModerator Monday, May 07, 2012 9:01 AM
-
Sunday, April 29, 2012 10:29 PM
You may want to draw your CView content in a bitmap instead of on the screen, and then draw the bitmap on the screen in CView::OnDraw. Drawing a bitmap on the screen is very fast, so you should not have any flickering ordrawing delay.
In CView::OnDraw, most of the time you don't need to update the bitmap, so just draw it on the screen. If your data have changed, then you would have to update/recreate your bitmap, and this would take time. But this would not happen when a pane is sliding, would it?
If you want some sample code to do this have a look here: http://stackoverflow.com/questions/2309767/c-windows-bitmap-draw-text
-
Monday, April 30, 2012 11:59 AM
Thank you so much for your replies :)
I already draw on an image, but I still do not understand why the autohide makes the CView flicker. The strange thing is that the flicker happens only when the pane is show and sliding to hide, while it does not happen when the pane is hidden and sliding to be shown.
Is there any reason that makes the sliding behaves differently when it is being shown than being hidden?
Thank you so much.
-
Monday, April 30, 2012 1:25 PM
What happens when you "pin" your pane and then resize it ? Does your view still flicker? If yes, then most likely you have to do some fixes in your painting code. Look up flicker-free painting on google.
-Seetharam
-
Monday, April 30, 2012 2:41 PM
If I resize my pinned pane, the view flickers just once which is normal to redraw itself in the new size. What annoys me is the continuous flicker that happens when a pane is sliding (in order to disappear). As I said before, this flicker does not happen when the pane is sliding in order to appear.
Please help.
Thank you. -
Wednesday, May 02, 2012 12:27 AM
The pane is disappearing in an animation, and this animation needs your view to be redrawn many times.
When the pane appears, the animation only needs your view to be redrawn once. So there is no flickering at this time. Have a close look at what happens on the screen in the 2 animations.
To avoid this flicker you have no choice but to optimize your code. If you are just drawing a bitmap, then this should be easy. Flicker is often caused when the view background is erased in OnEraseBackground, and then draw your bitmap in OnDraw. Clearing the background and drawing something on it generally causes the flicker.
- Marked As Answer by Helen ZhaoModerator Monday, May 07, 2012 9:02 AM
-
Wednesday, May 02, 2012 9:10 AM
Thank you Pierre for your reply.
I just still do not get why the need to redraw the CView multiple times. Why not just draw it once (with the bigger size) and then just slide the pane on top of it. If I have a dialog on top of my CView for example, and I move the dialog around, it does not cause the CView to be redrawn whenever I move the dialog.
Please advise.
Thank you! -
Wednesday, May 02, 2012 12:46 PM
Dialogboxes have CS_SAVEBITS flag so they save the screen backgroundbefore they are displayed, and restore it when they are closed.Dialogboxes are not displayed for a long time, so its worth usingmemory during a short time to avoid redraw events.But panes are not dialogboxes, they are supposed to be displayed for along time. So it's not worth using memory to store the screenbackground when they are displayed.Once again, the problem you have is not the pane animation. Yourproblem is that your CView drawing code has flickers. If you want tosolve this problem, you should optimize your drawing code.- Marked As Answer by Helen ZhaoModerator Monday, May 07, 2012 9:01 AM

