BitCount Help

K

Kodiak

I have this code snippet below and what I am trying to due is return
the sum of the byte returned from the GetDIBits() method. What I am
trying to due is if you open up notepad and leave the text area empty
you should get the sum of the bits returned in the byte data. If you
type some text into the notepad area and run the program again the sum
of the bits should be different from the first sum. Everytime I run
the program I get the same result every time. I do not know if there
is something wrong with my logic, but if someone can help me with this
problem I would appreciate it.

int main()
{
HWND hWnd;
RECT rcWnd;
hWnd = FindWindow("Notepad", "Untitled - Notepad");
GetWindowRect(hWnd, &rcWnd);

int x = rcWnd.right - rcWnd.left;
int y = rcWnd.bottom - rcWnd.top;
int left = rcWnd.left;
int top = rcWnd.top;
int width = x - left;
int height = y - top;

HDC hDC;
HDC hBitmapDC;
HBITMAP hBitmap;
HGDIOBJ hobj;
byte* bitmap;
byte* data;
DWORD sum, result;
long length;
LPBITMAPINFOHEADER lpbih;
sum = NULL;
hDC = GetDC(hWnd);
bitmap = new byte[sizeof(BITMAPINFOHEADER)+x*y*4];
if(bitmap)
{
length = x*y*4;
memset(bitmap,0,sizeof(BITMAPINFOHEADER)+x*y*4);
hBitmapDC = CreateCompatibleDC(hDC);
hBitmap=CreateCompatibleBitmap(hDC,x,y);
hobj = SelectObject(hBitmapDC,hBitmap);
BitBlt(hBitmapDC,0,0,x,y,hDC,rcWnd.left,rcWnd.top,SRCCOPY);
hobj = SelectObject(hBitmapDC,hobj);
lpbih = LPBITMAPINFOHEADER(bitmap);
lpbih->biSize = sizeof(BITMAPINFOHEADER);
lpbih->biWidth = x;
lpbih->biHeight = y;
lpbih->biBitCount = 32; //say our desired format is 32bpp
BI_RGB
lpbih->biPlanes = 1;
lpbih->biCompression = BI_RGB;
data = bitmap+sizeof(BITMAPINFOHEADER);
if(GetDIBits(hBitmapDC,hBitmap,0,0,data,LPBITMAPINFO(lpbih),DIB_RGB_COLORS))
{

for(int i=0; i<length; i++)
{
sum += (DWORD)data;
}

result = sum;

}
}

ReleaseDC((HWND)hWnd, hDC);
DeleteDC(hDC);
DeleteDC(hBitmapDC);
DeleteObject(hBitmap);
return 0;
}
 
B

BobR

Kodiak wrote in message
I removed all the parts that this NG does not cover.
int main(){
long length;
for(int i=0; i<length; i++){ }
return 0;
}

Hmm, not much left. What was your C++ question on that?

Oh, you *should* initialise 'length'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top