CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2001
    Posts
    391

    Question My Steps for No Flickering Controls while Resizing Dialog

    Maybe i am doing it wrong but i noticed that when i resize controls on my dialog box while the dialog is being resized (using one of its corners via the mouse button) that the controls begin flickering terribly.

    To fix it, i am planning on applying the following steps (please someone tell me if i am overthinking this):

    1. Putting the following code inside the dialog's WM_WINDOWPOSCHANGED message:

    HDWP defer = BeginDeferWindowPos(#);
    DeferWindowPos(defer,...); <-- Used for each control on the dialog that will resize
    .
    .
    EndDeferWindowPos(defer);

    Each DeferWindowPos(..) represents a control and contains the new resizing values for that control relative to the dialog's new resizing values. By using the Begin/Defer/End this will reposition/resize all of my controls in a single refresh cycle. I figure this is a better alternative than using SetWindowPos(..) for each of the numerous controls that exist on this resizable dialog that must change when the dialog changes in size.

    2. Turning ON the "ClipChildren" option for the dialog (so the dialog doesnt clear the background under each control while resizing -- it will only erase the bkg in regions that controls dont sit on).

    3. Subclassing each control and disabling the WM_ERASEBKG (or more specifically, "return TRUE", so it doesnt erase the background of that control).

    4. Redraw the entire control (and background) inside the WM_PAINT message (of that subclassed control) using a created compatible memory DC (a double-buffer). Once i do that i will BitBlt the results onto the Dialog's hdc (the visual screen).

    Does that all make sense? Or is this overkill and alternatively, i can achieve no flicker results in some other way?


    Thank you immensely!
    Last edited by quantass; August 5th, 2005 at 08:17 AM.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: My Steps for No Flickering Controls while Resizing Dialog

    I think this is overkill (depending on what exactly is on your dialog.)
    First try to enable "WS_CLIPCHILDREN" on your dialog. That should already help quite a lot and perhaps be perfect.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Dec 2001
    Posts
    391

    Re: My Steps for No Flickering Controls while Resizing Dialog

    Hey Marc,

    I am using groupboxes (3), ListViews (2 of them), StatusBar, buttons, edit boxes, and dropdowns. I noticed that even with ClipChildren enabled i see flickering around the ListViews scrollbars, and my status bar flickers terribly. I do notice though that when using the status bar and resizing it i have to always call the SendMessage(hwndStatusBar,WM_SIZE,0,0); each time and may be the cause of flickering but without it the status bar never redraws itself (i had to create the status bar in code because the resource editor wouldnt work -- if that helps to know).
    Last edited by quantass; August 5th, 2005 at 08:39 AM.

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: My Steps for No Flickering Controls while Resizing Dialog

    Yes, you are correct, i have the same problem with my statusbars, but I don't have time to find a solution for it. If someone else knows an easy to implement solution for this, please let us know.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    Dec 2001
    Posts
    391

    Re: My Steps for No Flickering Controls while Resizing Dialog

    Hi Marc, quick update....GEEZ u know your stuff. I am playing around with all my controls including the flickering scrollbar with listview and noticed that infact there was anoter control that i didnt see sitting on the scroll bar of it) while it wasrezing..When i moved that other control away it stopped flickering Yes, so from what you have told me then the only thing that seems to flicker is the Status Bar. Once again Marc you da best.

    I figure i will just subclass that control and do my technique for that instead.

    Thanks again Marc!

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: My Steps for No Flickering Controls while Resizing Dialog

    Quote Originally Posted by quantass
    I figure i will just subclass that control and do my technique for that instead.
    You could also try some of the articles at http://www.codeguru.com/Cpp/controls/statusbar/ . Perhaps some of these implementation already solves the flickering problem.

    Quote Originally Posted by quantass
    Thanks again Marc!
    You're welcome
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

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