Following your advice, I’ve created a simple grid ...
ExtPPVW < CExtGridWnd > * m_wndGrid = new CExtPPVW < CExtGridWnd >;
... and filled it with some dummy data. When I try to capture
m_wndGrid ...
CExtBitmap * pEBM = CaptureWindow(m_wndGrid->GetSafeHwnd());
... with ...
CExtBitmap * CaptureWindow(HWND hWnd)
{
if( ! ::IsWindow(hWnd) )
{
assert(false);
return NULL;
}
HDC hDCMem = ::CreateCompatibleDC(NULL);
RECT rect;
::GetWindowRect(hWnd, & rect);
HBITMAP hBmp = NULL;
{
HDC hDC = ::GetDC(hWnd);
hBmp = ::CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);
::ReleaseDC(hWnd, hDC);
}
HGDIOBJ hOld = SelectObject(hDCMem, hBmp);
::SendMessage(hWnd, WM_PRINTCLIENT, (WPARAM) hDCMem, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);
::SelectObject(hDCMem, hOld);
::DeleteObject(hDCMem);
CExtBitmap * pEBM = new CExtBitmap();
pEBM->FromBitmap(hBmp);
return pEBM;
}
... I got an assertion (
hWnd == NULL). The reason is obvious:
m_wndGrid is not of type
CWnd*
.
My question as a non-MFC-specialist: how can I get a photo of my
m_wndGrid, though? Do I have to put it in a container of class
CWnd*
first? And do I have to call
ShowWindow()
before capturing?
Thanks a lot in advance!!
Martin