Re: Grabbing desktop image under a window
Beside the fact that its done the hard way. It will not work for what he
wants. The code you posted will also save his window in the Bitmap, he
doesn't want his to be saved in the bitmap.
The code you posted is equivalent to this!
void CMgView::OnDraw(CDC* pDC)
{
CMgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDC *pDesktopDC =GetDesktopWindow()->GetDC();
pDC->BitBlt(0,0,800,600,pDesktopDC,20,20,SRCCOPY);
GetDesktopWindow()->ReleaseDC(pDesktopDC);
}
And why do some people mix API calls and MFC?
AliR.
"Harvey" <harveyab@juno.com> wrote in message
news:1173198860.906889.47680@n33g2000cwc.googlegroups.com...
MrAsm,
Here is some code I found and tested from another post by "reic yang"
and modified by "mj"
(Search Groups for " How I can capture Screen in order to create
Image?")
I added the last line to stop a mem leak.
You may have already got this part working.
Now for the getting under this window.
If you get other relavant info please post it.
Thanks,
Harvey
Drop this in a SDI App to test.
void CMgView::OnDraw(CDC* pDC)
{
CMgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
HWND hWnd=::GetDesktopWindow();
HDC hDCScreen=::GetDC(hWnd);
HDC hDCMem=::CreateCompatibleDC(hDCScreen);
HBITMAP hBitMap=::CreateCompatibleBitmap(hDCScreen,800,600);
::SelectObject(hDCMem,hBitMap);
BitBlt(hDCMem,0,0,800,600,hDCScreen,0,0,SRCCOPY);
CDC *pMem=new CDC();
pMem->Attach(hDCMem);
pDC->BitBlt(0,0,800,600,pMem,20,20,SRCCOPY);
::ReleaseDC(hWnd,hDCScreen);
::DeleteDC(hDCMem);
delete pMem;
}