Re: Drawing to a Bitmap
I have a question, do you only want the client area of the views, or do you
want to save the border and titlebar and all that?
This might be a little more than what you asked for!
Typical the way I do my view drawing is double buffered, so what I normally
do is I keep a bitmap in memory that I draw to, and then when OnDraw gets
called I simply blit the bitmap in memory to the screen.
The reason I do this is because it is much faster to simply blit a bitmap
than to loop through everything and draw every item each time a WM_PAINT is
received, because that can happen more often than my actual graphics is
going to change.
So everytime something happens that requires a change to the graphics, I
simply draw to the memory bitmap and Invalidate/UpdateWindow the view so
that the display will show the changes.
With all that said, my Drawing routine usually takes a CDC and a CRect and
draws on that DC. The cool thing here is that I can pass in any DC, screen
or memory for the draw routine to draw to.
So for me, if I want to save a bitmap of what's on the screen, all I have to
do is create a memory dc and put a bitmap in it, call my draw routine with
that DC and then simply save the bitmap to a file.
The short fall of this method is that it can be memory intensive depending
on the size of your bitmaps.
"Scoots" <firstname.lastname@example.org> wrote in message
I have what I hope to be a simple question, but one that Google is
failing me on. Everything seems to describe the opposite of the
process, but I know that the information is out there somewhere.
I have an mfc application that with multiple CViews that I have draw
code set up for and everything works wonderfully when drawing to the
screen. Now, what I want to do, is create a bitmap, tell each of the
CViews to draw to that, and then saving it out to disk as a screen
capture. I want to go this route for several reasons, the biggest
being that I want to save these CViews even if they are ocluded by
other windows, though if this proves to be too difficult, a screenshot
would suffice I suppose.
My CView has draw code that looks like the following:
void CGraphicsView::OnDraw(CDC* pDCWnd)
CGraphicsDoc* pModelDoc = GetModelDocument();
CDC *pDC = pDCWnd;
if (EqualRect(&rectClient, &rectClip))
m_bWasCovered = false;
m_bWasCovered = true;
pDC->FillSolidRect(rectClip, RGB(204, 204, 204));