dave2k
May 23rd, 2006, 02:37 PM
i am trying to gather the bits of an area of a hidden window using a method pointed out by golansahar a while back. my code is a modified version of what i am currently using:typedef BOOL (_stdcall *tPrintWindow)(HWND, HDC, UINT);
void Window::GetPixels(int x, int y, int w, int h, int* &pixels)
{
delete[] pixels;
RECT rc;
::GetWindowRect(hwnd,&rc);
HDC hDC = ::GetDC(0);
HDC memDC = ::CreateCompatibleDC(hDC);
HBITMAP memBM = ::CreateCompatibleBitmap(hDC, w, h);
HBITMAP OldBM = (HBITMAP)::SelectObject(memDC, memBM);
//::BitBlt(memDC, 0, 0, w, h, hDC, rc.left+x, rc.top+y, SRCCOPY);
// new code
tPrintWindow pPrintWindow = 0;
HINSTANCE handle = GetModuleHandle("user32.dll");
if ( handle == 0 ) handle = LoadLibrary("User32.dll");
if ( handle ) pPrintWindow = (tPrintWindow)GetProcAddress(handle, "PrintWindow");
if ( pPrintWindow ) pPrintWindow(hwnd, memDC, 0 );
// end new code
int size = w * h;
pixels = new int[size];
::GetBitmapBits(memBM, size*4, pixels);
::SelectObject(hDC, OldBM);
::DeleteObject(memBM);
::DeleteDC(memDC);
::ReleaseDC(0, hDC);
}
as you can see i commented out the BitBlt and have the new code below it. can anyone see where this is going wrong? (pixels is not getting populated)
p.s. i need to get only a portion of the window, hence the parameters to the function. getting the whole window significantly reduces performance.
void Window::GetPixels(int x, int y, int w, int h, int* &pixels)
{
delete[] pixels;
RECT rc;
::GetWindowRect(hwnd,&rc);
HDC hDC = ::GetDC(0);
HDC memDC = ::CreateCompatibleDC(hDC);
HBITMAP memBM = ::CreateCompatibleBitmap(hDC, w, h);
HBITMAP OldBM = (HBITMAP)::SelectObject(memDC, memBM);
//::BitBlt(memDC, 0, 0, w, h, hDC, rc.left+x, rc.top+y, SRCCOPY);
// new code
tPrintWindow pPrintWindow = 0;
HINSTANCE handle = GetModuleHandle("user32.dll");
if ( handle == 0 ) handle = LoadLibrary("User32.dll");
if ( handle ) pPrintWindow = (tPrintWindow)GetProcAddress(handle, "PrintWindow");
if ( pPrintWindow ) pPrintWindow(hwnd, memDC, 0 );
// end new code
int size = w * h;
pixels = new int[size];
::GetBitmapBits(memBM, size*4, pixels);
::SelectObject(hDC, OldBM);
::DeleteObject(memBM);
::DeleteDC(memDC);
::ReleaseDC(0, hDC);
}
as you can see i commented out the BitBlt and have the new code below it. can anyone see where this is going wrong? (pixels is not getting populated)
p.s. i need to get only a portion of the window, hence the parameters to the function. getting the whole window significantly reduces performance.