Hi,
I am in need of a way of doing the following.
1. I can get the handle to a window that I know of.
2. I can get the DC as well.
I want to Get the content of the window(DC) in to the memory as a bitmap so I can fiddle around with it.
I have seen this same problem all over internet and there are many suggestions. But I can't get my code to work.
Here's what I have in the end of a whole day:
And that code is not mine. It is a Ctr + c + v from the net.
However, I can't figure it out. Can Anyone plz tell me what the format of the values in lpBits array? Is it RGBA ? etc. And how can I derive a single pixel out of it? Thanx very much in advance.
I am in need of a way of doing the following.
1. I can get the handle to a window that I know of.
2. I can get the DC as well.
I want to Get the content of the window(DC) in to the memory as a bitmap so I can fiddle around with it.
I have seen this same problem all over internet and there are many suggestions. But I can't get my code to work.
Here's what I have in the end of a whole day:
Code:
RECT rc; ::GetWindowRect(hWnd, &rc); int w = rc.right-rc.left; int h = rc.bottom-rc.top; HDC hDC = ::GetDC(hWnd); HDC memDC = ::CreateCompatibleDC(hDC); HBITMAP memBM = ::CreateCompatibleBitmap(hDC, w, h); ::SelectObject(memDC, memBM ); ::BitBlt(memDC, 0, 0, w, h , hDC, rc.left, rc.top , SRCCOPY ); int size = 3 * w * h; int *lpBits = new int[size]; ::GetBitmapBits(memBM, size, lpBits );
However, I can't figure it out. Can Anyone plz tell me what the format of the values in lpBits array? Is it RGBA ? etc. And how can I derive a single pixel out of it? Thanx very much in advance.
Comment