本文介绍了在Windows对话框中处理WM_ERASEBKGND时如何避免闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调整大小的对话框。它还有一个自定义背景,我为了响应WM_ERASEBKGND调用(目前是一个简单的调用FillSolidRect)绘制。



当对话框调整大小时,会有巨大的闪烁。为了尝试减少闪烁,我枚举所有子窗口,并将它们添加到剪辑区域。这似乎有所帮助 - 现在,所有的孩子控件中的闪烁显示在他们重新绘制时都是显而易见的。



如何在调整对话框时无闪烁?我怀疑双缓冲必须发挥作用,但我不知道如何使用带有子控件的对话框(不使所有子控件拥有者绘制或类似的东西)来实现。



我应该注意到,我使用C ++(而不是.NET)和MFC,尽管基于Win32的纯粹解决方案受到欢迎:)



注意:有一件事我尝试了,但不行(不知道为什么)是:

  CDC memDC; 
memDC.CreateCompatibleDC(pDC);
memDC.FillSolidRect(rect,backgroundColor);

pDC-> BitBlt(0,0,rect.Width(),rect.Height(),& memDC,0,0,SRCCOPY);


解决方案

假设FillSolidRect是您的背景的擦除然后从WM_ERASEBKGND返回TRUE。



要在代码片段中执行双缓冲,您需要使用CreateCompatibleBitmap并将其选择到您的memDC中。


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 the dialog is resized, there is tremendous flickering going on. To try and reduce the flickering I enumerate all child windows and add them to the clipping region. That seems to help a little -- now the flickering is mostly evident in all of the child controls as they repaint.

How can I make the dialog flicker-free while resizing? I suspect double-buffering must play a part, but I'm not sure how to do that with a dialog with child controls (without making all child controls owner-draw or something like that).

I should note that I'm using C++ (not .NET), and MFC, although pure Win32-based solutions are welcomed :)

NOTE: One thing I tried but which didn't work (not sure why) was:

CDC memDC;
memDC.CreateCompatibleDC(pDC);
memDC.FillSolidRect(rect, backgroundColor);

pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &memDC, 0, 0, SRCCOPY);
解决方案

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.

这篇关于在Windows对话框中处理WM_ERASEBKGND时如何避免闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:33
查看更多