CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jul 2005
    Posts
    218

    Reduce flickering

    Hey guys,

    I am using a CListBoxEBX control from this project, DrawItem function is overriden.

    http://www.codeguru.com/cpp/controls...cle.php/c4745/

    When I fill this list box intensively with lots of items per second i see a lot of
    flickering.

    What are usual techniques in GDI area to reduce flickering as much as possible?

    thanks

  2. #2
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: Reduce flickering

    One common technique is Double Buffering. You should find a lot of material on the Internet regarding this topic.
    Har Har

  3. #3
    Join Date
    Dec 2003
    Location
    Middletown, DE
    Posts
    67

    Re: Reduce flickering

    For controls like the Listbox, you can suspend updates while making multiple changes. I haven't tested this myself, but CWnd::LockWindowUpdate() and CWnd:UnlockWindowUpdate() seem to be what you're looking for. I'd be curious if this worked for you.

    In .NET-land, you would use SuspendLayout() and ResumeLayout(), but there doesn't seem to be an equivalent in MFC.

  4. #4
    Join Date
    Jul 2005
    Posts
    218

    Re: Reduce flickering

    Quote Originally Posted by PadexArt
    One common technique is Double Buffering. You should find a lot of material on the Internet regarding this topic.
    Double Buffering of what, PadexArt?

  5. #5
    Join Date
    Apr 1999
    Posts
    3,585

    Re: Reduce flickering

    You might want to try CWnd::SetRedraw ().
    Gort...Klaatu, Barada Nikto!

  6. #6
    Join Date
    Jul 2005
    Posts
    218

    Re: Reduce flickering

    Quote Originally Posted by Mike Harnad
    You might want to try CWnd::SetRedraw ().
    yes, before updating the list (either removal or adding an item) I disable redrawing and enable it after

  7. #7
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Reduce flickering

    Quote Originally Posted by nazgul27
    Double Buffering of what, PadexArt?
    double buffering of your drawings. ..

    First do all the drawings to a temp buffer. . and then. . write the tempbuffer to the DC. Result : no more filckering.

  8. #8
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Reduce flickering

    Double buffering (or rather, offscreen drawing - double buffering is something else, strictly speaking ) would be overkill in this case, and totally unnecessary.

    Like Mike said: Call SetRedraw(false) before inserting / removing items, and SetRedraw(true), follwed by Invalidate(), after you're done with your bulk item operation.

  9. #9
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: Reduce flickering

    Some form of optimizied drawing should be employed to ensure flickering is not affecting other operations ( such as scrolling). In some cases it is desirable to see something is happening but with a minimal flicker and SetRedraw cannot help there.
    Har Har

  10. #10
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: Reduce flickering

    Have you tried using int InitStorage( int nItems, UINT nBytes ) with the number of items to speed up the loading process.
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  11. #11
    Join Date
    Jul 2005
    Posts
    218

    Re: Reduce flickering

    Quote Originally Posted by gstercken
    Double buffering (or rather, offscreen drawing - double buffering is something else, strictly speaking ) would be overkill in this case, and totally unnecessary.

    Like Mike said: Call SetRedraw(false) before inserting / removing items, and SetRedraw(true), follwed by Invalidate(), after you're done with your bulk item operation.
    actually there is no bulk operation. The items are inserted on run time one by one. But there are times when the number of those items is huge, about 100 items per second.

    This control is a self redrawing control. Before any Remove/Add operation I disable redraw and enable it after but it does not help.

    When I added OnEraseBackground handler and return FALSE from there the flickering is gone. but the only disadvantage is when the listbox is not full the background is not invalidated in case it's overlapped with something but it's not that nasty since the control gets filled pretty quickly

  12. #12
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: Reduce flickering

    Did you try my above suggestion ??
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  13. #13
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Reduce flickering

    Quote Originally Posted by Vanaj
    Did you try my above suggestion ??
    if the number of items is not know before their insertion, he cannot use InitStorage.

  14. #14
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Reduce flickering

    The items are inserted on run time one by one. But there are times when the number of those items is huge, about 100 items per second.
    When an item is inserted, disable Redraw, and start a timer (restart timer if already started). When timer expires, enable re-draw and invalidate. A timer of about 0.75 seconds is what I like.

    No "flicker" but fairly quick updates
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  15. #15
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: Reduce flickering

    Quote Originally Posted by Alin
    if the number of items is not know before their insertion, he cannot use InitStorage.
    One can make an educated guess...but he has not said this value is unknown and anything greater than 100 WILL help and 500 is better even if only 150 is loaded. Mine loads 4,000+ with NO flicker and InitStorage() is run before loading using values from database returns.
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured