   Erase a Specific Area from a HDC
  HelloI am trying to find a Win32 function/way that can allow me to erase a HRGN from a HDC. What I am doing is double buffering; so I copy the window HDC to a buffer HDC, then I delete/erase a specific area of the buffer HDC, then draw what I need to.But I dont know how to erase a specific area of a HDC?. I cant use InvalidateRgn(NULL, ObjRegion, true) (because this function only erases the window HDC) or can I? Hope this makes sense :)   
Quote:Original post by grettyHelloI am trying to find a Win32 function/way that can allow me to erase a HRGN from a HDC. What I am doing is double buffering; so I copy the window HDC to a buffer HDC, then I delete/erase a specific area of the buffer HDC, then draw what I need to.But I dont know how to erase a specific area of a HDC?. I cant use InvalidateRgn(NULL, ObjRegion, true) (because this function only erases the window HDC) or can I? Hope this makes sense :)There is no concept of "erase".  You can only draw on top of a DC that you are given, or look at the current contents.  You cannot peek at what was there in history.If you are trying to prevent yourself from drawing on a region, you can use regions for clipping.  In that case you call SelectClipRgn then blit over the top of it.   ;FillRgnHowever your description sounds very dicey.  You should pretty much never be bltting from the window dc to your backbuffer.   ;  Gretty, what exactly are you trying to do? Generally I agree with what frob says above.There's generally not a reason to copy from the window device context to your offscreen bitmap. When you do double-buffering what you do is (1) set up an offscreen bitmap; (2) get an HDC into that; (3) in the WM_PAINT handler for the window you're double-buffering, paint into the offscreen bitmap; (4) in the WM_PAINT handler, blit the offscreen bitmap to the window HDC that you get from BeginPaint(). If you're trying to make a non-rectangular window you should look at SetWindowRgn() i.e. let windows do the clipping for you.   ;  Well I have attempted something but no success.One option I have tried is to clear the HRGN from the HDC by doing this:FillRgn( hdc, ObjRegion, (HBRUSH)GetStockObject(NULL_BRUSH) ); So I am painting it with null, but that doesn't work, it doesn't erase it from the HDC. I know that I am meant to use WM_ERASEBKGROUND (but do I paint it with NULL when this message is sent or in WM_PAINT) & I have done this but it still doesn't work. Any suggestions on whats going wrong would really help.@jwezorek , I am trying to make my own simple 2d drawing engine (animation?) :P. So what I do is at each drawing_clock_interval I have a drawing controller object that copies the window HDC in a buffer HDC, erases an objects HRGN (from the buffer HDC) (erase the old position of an object), then I draw the objects new position (FillRegion) onto the bufferHDC, then I copy the buffer HDC to the main window HDC.Is this the correct way to do this or do think there is a better way?   ;  You might try ignoring WM_ERASEBKGROUND altogether:case WM_ERASEBKGROUND: return 0;as that is generally used to repaint the background color of the window and, if you are drawing the background behind your animation (that's what "erasing" really is - drawing over what's there), you'll be drawing the background each frame in any case.Rather than buffer your drawing, draw to the window HDC itself. Is there a reason you want to buffer?You can determine the region you want to overdraw, set a clipping region* to that area, and redraw the background, animations, etc., in that region.*you'll want to overdraw the previous animation and the current animation region (combine the regions) as they may not be the same (animated object is moving, etc.)Remember, when you "erase" the previous animation, you're "erasing" the background behind it, also. If you don't test the background drawing against the clipping region and draw only what's in the region, you might try just redrawing to the entire window HDC each frame.   ;Quote:Original post by grettyFillRgn( hdc, ObjRegion, (HBRUSH)GetStockObject(NULL_BRUSH) ); So I am painting it with null, but that doesn't work, it doesn't erase it from the HDC.NULL_BRUSH is a brush that doesn't do anything and it sounds like it's working as advertised.  "painting it will null" is meaningless.  As frob mentioned there's no such thing as erasing.  You can try using BLACK_BRUSH just to convince yourself that it's actually doing something.I'm guessing that what you actually want is the brush returned by GetSysColorBrush(COLOR_WINDOW).Like I said before, you shouldn't be copying from the window dc.  Just keep your back buffer around and make the changes there rather than doing an extra blt for no reason.  Especially because bltting from the screen can be much slower than blting to it.   