I’m working on a program that requires WM_ERASEBKGND to be disabled (to avoid flickering).
The problem comes in when my main window loses focus, and another window (another program) gains the focus.
The window that has the focus (not my program) invalidates MY program’s window every time it passes over it! The result is, my window’s screen turns white everywhere that another window has passed by it, leaving it almost totally blank afterward. Obviously, I cannot have a program where the screen turns white every time it loses focus.
Is there any way to continue my window’s drawing operations, (continue calling wm_paint, for example) even after my window has lost focus (WM_KILLFOCUS)?
First of all, from the comments above, never send the
WM_PAINTmanually withSendMessageorPostMessage. UseInvalidateRectto instruct the window to be repainted.About the
WM_ERASEBKGND, the return value is used to indicate theWM_PAINThandler that the background has been erased, in case the paint procedure can be optimized. To actually prevent the background from being erased, simply do not callDefWndProc()for that message. Or even easier, set thehbrBackgroundtoNULLin the window class.As others mentioned the focus has nothing to do with repainting, and your window should paint normally even while in the background.