CreateCompatibleBitmap() failure
Hello all,
We have a member function in our app. to programatically take a
screenshot (shown at the end of this post).
After taking approx. 70 screenshots, the call to
CreateCompatibleBitmap() fails and returns 0. If I call GetLastError(),
I get a return of 8 which MSDN says means that there is not enough
storage available to process this command.
Can anybody shed light on what is going wrong?
Thanks,
Dave
bool ScreenCapture::CaptureScreenImage() {
m_hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
m_hdcCompatible = CreateCompatibleDC(m_hdcScreen);
// Create a compatible bitmap for hdcScreen.
m_hbmScreen = ::CreateCompatibleBitmap(m_hdcScreen,
GetDeviceCaps(m_hdcScreen, HORZRES),
GetDeviceCaps(m_hdcScreen, VERTRES));
CBitmap* pbm = CBitmap::FromHandle(m_hbmScreen);
BITMAP bmInfo;
pbm->GetBitmap(&bmInfo);
// Select the bitmap into the compatible DC.
HBITMAP hbmOld = (HBITMAP)SelectObject(m_hdcCompatible, m_hbmScreen);
//Copy screen image to compatible memory dc
BitBlt(m_hdcCompatible,0,0,bmInfo.bmWidth,bmInfo.bmHeight,m_hdcScreen,0,0,SRCCOPY);
return true;
}