问题描述
如果需要使用双缓冲,则需要禁止显示WM_ERASEBKGND
消息.
If I need to use double buffering, I need to suppress WM_ERASEBKGND
message.
我可以处理WM_ERASEBKGND
并立即返回.但是我可以将WNDCLASS
/WNDCLASSEX
的hbrBackground
设置为NULL
而不处理WM_ERASEBKGND
消息吗?这是正确的方法吗?
I can handle WM_ERASEBKGND
and return immediately. But can I set the WNDCLASS
/WNDCLASSEX
's hbrBackground
to NULL
and not handle the WM_ERASEBKGND
message? Is this a correct way?
推荐答案
是的,将hbrBackground
设置为NULL
是避免实现无操作WM_ERASEBKGND
处理程序的适当方法.
Yes, setting hbrBackground
to NULL
is an appropriate way to avoid implementing a no-op WM_ERASEBKGND
handler.
将WM_ERASEBKGND
传递给DefWindowProc
时,它将检查窗口类中的背景画笔.如果有一个,它将用它填充脏区.如果背景画笔为空,则不执行任何操作并返回.基本上与拥有自己的WM_ERASEBKGND
不执行处理程序相同.
When you pass WM_ERASEBKGND
on to DefWindowProc
, it checks the background brush in the window's class. If there is one, it fills the dirty region with it. If the background brush is null, it does nothing and returns. That's essentially the same as having your own do-nothing WM_ERASEBKGND
handler.
WM_ERASEBKGND
处理程序的返回值会影响WM_PAINT
调用BeginPaint
时获得的PAINTSTRUCT
的fErase
字段. WM_PAINT
处理程序应该检查fErase
以了解它是否需要擦除背景本身,或者是否已经被WM_ERASEBKGND
完成. (尽管我从未真正看到任何人对其进行过检查.)如果让DefWindowProc
处理WM_ERASEBKGND
,如果它具有颜色编号或画笔,它将返回TRUE
,如果hbrBackground
是NULL
,它将返回FALSE
.
The return value from the WM_ERASEBKGND
handler affects the fErase
field of the PAINTSTRUCT
you get when WM_PAINT
calls BeginPaint
. The WM_PAINT
handler is supposed to check fErase
to find out whether it needs to erase the background itself or if it was already done by WM_ERASEBKGND
. (Though I've never actually seen anyone check it.) If you let DefWindowProc
handle WM_ERASEBKGND
it will return TRUE
if it has a color number or brush and FALSE
if the hbrBackground
is NULL
.
这篇关于抑制WM_ERASEBKGND的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!