Search code examples
c++mfcflickercdialog

Avoid Flickering on a dialog that moves its controls on resize


I have a popup dialog( CDialog ) that handles WM_CTLCOLOR message to color itself. It is having some controls (like bitmap buttons) that draws themselves using OwnerDraw. It is also having a control that displays an image with size that takes up to 70% of the dialog.

When user re-sizes the dialog, some of the controls in the dialog should be re-positioned (not re-sized). It also involves re-sizing of the image inside the dialog. As the re-sizing of image makes the whole process slow, individual re-positioning of the controls are causing a visual effect of flickering.

I need to get rid of these. One idea is to put the controls as the children of an intermediate dialog that is the child of the original popup dialog. So, when there is a re-size, I can re-position the dialog only instead of moving each controls individually. (Re-position happens only in one direction (x or y), so moving the intermediate dialog should be enough.

As it involves some coding effort, before going this way, I need answers to the following questions:

  • Will this work?
  • If yes, whats the complexity involved in this method?
  • Is there a better way?

Please help!


Solution

  • It will probably work, but you should try solutions that don't alter your control hierarchy before, because it has other subtle consequences (focus, tab order, message notifications, etc).

    Try one or all of the following:

    • Use BeginDeferWindowPos/DeferWindowPos/EndDeferWindowPos functions to move the children.
    • Set the WS_CLIPCHILDREN style flag in the dialog.
    • Set the WS_EX_LAYERED extended style flag in the dialog.