How to avoid flicker while handling WM_ERASEBKGND in Windows dialog

后端 未结 6 1262
梦谈多话
梦谈多话 2020-12-17 19:41

I have a dialog that resizes. It also has a custom background which I paint in response to a WM_ERASEBKGND call (currently a simple call to FillSolidRect).

When t

相关标签:
6条回答
  • 2020-12-17 20:18

    If you are targeting WinXP or higher, you can also use the WS_EX_COMPOSITED style to enable double-buffering by default for top-level windows with this style. Bear in mind this has its own set of limitations -- specifically, no more drawing out of OnPaint cycles using GetDC, etc.

    0 讨论(0)
  • 2020-12-17 20:18

    Double buffering is indeed the only way to make this work.

    Child controls will take care of themselves so long as you make sure CLIPCHILDREN.

    0 讨论(0)
  • 2020-12-17 20:29

    Try adding the following line to your OnInitDialog function:

        ModifyStyle(0, WS_CLIPCHILDREN, 0);
    
    0 讨论(0)
  • 2020-12-17 20:30

    you can set parameter of your call to InvalidateRect method as false. This will prevent you to send WM_ERASEBKGND when the window will redraw.

    0 讨论(0)
  • 2020-12-17 20:33

    Do nothing in the WM_ERASEBKGND handling and do the erase as part of your main WM_PAINT. You can either paint smarter so that you only redraw the invalid areas, or more easily, double-buffer the drawing.

    By not doing anything in the erase background, you have all your drawing code in one location which should make it easier for others to follow and maintain.

    0 讨论(0)
  • 2020-12-17 20:38

    Assuming that "FillSolidRect" is the erase of your background then return TRUE from the WM_ERASEBKGND.

    To do the double buffering that you are almost doing in your code fragment, you will need to use CreateCompatibleBitmap and select that into your memDC.

    0 讨论(0)
提交回复
热议问题