Reputation: 817
I have outputted an image (bitmap) which is created by Bitblt
.
Now I want to get rid of it. How can I do? (Do not use the patch, like FillSolidRect
, etc.)
Upvotes: 1
Views: 603
Reputation: 244732
There is no way to "undo" or "erase" a BitBlt or any other drawing output (except in very special cases where you do XOR-based drawing, which you can undo by doing another XOR drawing operation on top of the original).
The only thing you can do is to draw on something else on top of it, which is what you are calling a "patch". Typically, you would draw a solid rectangle of the window's background color. This is precisely what the OnEraseBkgrnd
message handler does by default, which runs just before OnPaint
. Specifically, it uses your window class's background brush, which is typically a brush that draws using the COLOR_3DFACE
(for a dialog) or COLOR_WINDOW
(for a window) system color.
Of course, you could always just not do the BitBlt in the first place. All painting code should always go inside of the OnPaint
message handler function, so there is no way that you could end up with "stale" graphics. Whenever the window needs repainting, it is going to call this function, and your code inside of that function will repaint the window. If you don't want it to be painted with a bitmap, don't call BitBlt.
If you've done a BitBlt on top of your window using a temporary CDC
object (which you generally should not be doing), you can force this to be erased by triggering a repaint of the window. The easiest way is to use the window's InvalidateRect()
member function; passing NULL
as the pointer to the rectangle to be invalidated will invalidate the window's entire client area, or you can just invalidate the area that you blitted.
Upvotes: 2