CreateCompatibleBitmap is failed when running in x64 mode

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,

I have the source code that capture the windows screen as below.
These codes run normally when building by x32 mode , but when
building by x64 mode the exception occurred .
When debugging I found that function CreateCompatibleBitmap is failed . What is the problem?
(I build project by Visual Studio 2008 (debug, x64) on Windows 7 x64).


<div style="color:Black;background-color:White; <pre>
CDialog *hDlg = (CDialog*)AfxGetResourceHandle();
<span style="color:Blue; int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
<span style="color:Blue; int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

HWND hDesktopWnd = hDlg->m_hWnd;
HDC hDesktopDC = ::GetWindowDC(hDesktopWnd);

HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
CRect rc;
RECT rc1;
GetClientRect(&rc1);
GetWindowRect(&rc);

HBITMAP hCaptureBitmap;
hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,
rc1.right, rc1.bottom);

BITMAPINFO bmi;
LPBYTE pBits;
ZeroMemory(&bmi, <span style="color:Blue; sizeof(bmi));
bmi.bmiHeader.biSize = <span style="color:Blue; sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = rc.right;
bmi.bmiHeader.biHeight = rc.bottom;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
HBITMAP hbm = CreateDIBSection(hDesktopDC, &bmi, DIB_RGB_COLORS, (<span style="color:Blue; void **)&pBits, NULL, 0);

<span style="color:Green; // shortening....

SelectObject(hCaptureDC,hCaptureBitmap);
BitBlt(hCaptureDC,0,0,rc1.right, rc1.bottom-sToolbar-1,hDesktopDC,rc.left+iFrame+1,rc.top+sTitlebar+sToolbar,SRCCOPY);

CBitmap bmp;
bmp.Attach((HBITMAP)hCaptureBitmap);

BITMAP bitmap;
bmp.GetBitmap(&bitmap);

<span style="color:Green; // shortening....
[/code]

Thank you very much,

View the full article
 
Back
Top