Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am drawing in a 1024x1024 MFC Form using directx control. 1024X1024 resolution not occupied in my monitor screen, so i enabled scroll bar control for the Display form. I am using thread to draw the form (1024x1024) continuously. At the time i am scrolling to view the hidden part of the display, some flicker is happen. How to avoid that flicker while moving scroll bar in the display.
Posted

>I am using thread to draw the form (1024x1024) continuously.
>At the time i am scrolling to view the hidden part of the display, some flicker is happen.

I would not draw the form during scrolling. You can use
SQL
SetRedraw(FALSE)
on the begin and
C++
SetRedraw(TRUE)
on the end of scrolling. Take a look at this example from MSDN:

C++
// Updating a control or window with large amounts of data may cause
// flicker. In such cases it may be better to turn off drawing

//...

   //m_list is a member of type CListCtrl
   m_List.SetRedraw(FALSE);  // turn drawing off regardless of list mode

//...
// Update control
//...

   m_List.SetRedraw(TRUE);  // turn drawing back on and update the window

   // invalidate the entire control, force painting
   m_List.Invalidate();
   m_List.UpdateWindow();
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Mar-13 13:49pm    
I'm not sure it will work, without double buffering. Imagine that GDI draws a filled rectangle, and something thin on top of it, say, a line. It will flicked on each invalidation, no matter what you do.
Please see Solution 2 and Solution 3.
—SA
Instead of painting directly to your control you could create an equally sized memory DC and bitmap and paint into that. Then, when ready, just bitblt the currently visible part to the DC of the control. That has several advantages:

- drawing to a memory bitmap is faster than drawing to the screen
- you don't have to execute your drawing code for every scroll step; instead you draw once the entire control and just bitblt the part that is visible. Your might oven use the window scrolling functions for scrolling and just bitblt the small stripe that became visible in the last scrolls step.

This technique is called double-buffering and is used widely to suppress screen flicker.
 
Share this answer
 
Comments
Leo Chapiro 26-Mar-13 11:01am    
+5
nv3 26-Mar-13 11:09am    
Thanks!
Sergey Alexandrovich Kryukov 26-Mar-13 13:47pm    
Right, a 5.
In my answer, I also provided some references, including a CodeProject article, please see.
—SA
 
Share this answer
 
Comments
nv3 26-Mar-13 14:32pm    
As so often you have a couple of very good links in your sleeve, Sergey. I particularly liked the first one. +5
Sergey Alexandrovich Kryukov 26-Mar-13 14:59pm    
Thank you.
And I like your expression "in you sleeve". Pretty often, this is exactly the case. Due to all that CodeProject experience, I keep decent set of links handy, in my records... :-)
—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