Re: using CClientDC::BitBlt() to capture only the client window
It is the same bitmap as anyother bitmap.
What you have to do is have a bitmap as a member of your view class, draw to
that, and in response to WM_PAINT, you would bitblt to the screen.
But like I asked you in another post, what type of application are you
writing? Give us a little detail about what you are trying to accomplish.
There are multiple solutions to your problem, and without knowing what type
of UI you are providing it will be hard to give a good answer.
If you are writing a paint like program you would use a memory bitmap, if
you are writing a freehand type program you would need a different approach.
But the for memory bitmap:
class CMyView : public CView
{
.....
private:
CBitmap m_Bmp;
CDC m_MemDC;
};
void CMyView::OnInitUpdate()
{
//create the bitmap according to the size the user specifies or
something
m_Bmp.CreateCompatibleBitmap(....)
m_MemDC.CreateCompatibleDC(...);
}
//When you need to draw something on the screen, don't draw on the screen
dc.
//draw on the bitmap by selecting it into the memory dc and drawing on the
memory dc.
void CMyView::DrawSomethingOnImage()
{
int SaveDC = m_MemDC.SaveDC();
m_MemDC.SelectObject(&m_Bmp);
m_MemDC.Rectangle(....);
m_MemDC.RestoreDC(SavedDC);
}
//when you need to paint, simply draw on the screen what is in the memory
bitmap.
void CMyView::OnPaint()
{
CPaintDC dc(this);
int SavedDC = m_MemDC.SaveDC();
m_MemDC.SelectObject(&m_Bmp);
dc.BitBlt(0,0,Width,Height,&m_MemDC,0,0,SRCCOPY);
m_MemDC.RestoreDC(SavedDC);
}
AliR.
"nexolite" <nexolite@discussions.microsoft.com> wrote in message
news:F9A56255-DEA8-4584-AA1C-17B19DF8C363@microsoft.com...
Please tell me where is that bitmap and how can I use that?
"Joseph M. Newcomer" wrote:
This seems the wrong approach. Why do you use BitBlt in this fashion?
Your program
should work on the bitmap representation in memory, and only use BitBlt
to draw it to the
screen. Once it is on the screen, the pixels are ignored by your
program, and would never
be "recaptured" in the fashion you are attempting.
joe
On Wed, 18 Feb 2009 08:58:07 -0800, nexolite
<nexolite@discussions.microsoft.com> wrote:
Hi,
I am trying to create a application similar to MS paint , so I am
using
BitBlt() to capture the drawing area that is the window of my
application, I
did the following:
*To Capture the scrren*
CClientDC dcMemory;
CRect rect;
GetClientRect(&rect);
dcMemory.BitBlt(rect.TopLeft().x,rect.TopLeft().y,rect.Width(),rect.Height(),NULL,rect.TopLeft().x,rect.TopLeft().y,SRCCOPY);
*To display the screen back*
CClientDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.BitBlt(rect.TopLeft().x,rect.TopLeft().y,rect.Width(),rect.Height(),&dcMemory,rect.TopLeft().x,rect.TopLeft().y,SRCCOPY);
Now what happens is that the complete screen, the screen including the
portion that is outside my application window gets drawn into the
application
window ,so what must be done so that it captures the screen area of my
application window only?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm