Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > BitCount Help

Reply
Thread Tools

BitCount Help

 
 
Kodiak
Guest
Posts: n/a
 
      11-28-2006
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,LPBITMAPIN FO(lpbih),DIB_RGB_COLORS))
{

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

result = sum;

}
}

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

 
Reply With Quote
 
 
 
 
BobR
Guest
Posts: n/a
 
      11-29-2006

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'.

--
Bob R
POVrookie


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bitcount MrGeek C Programming 1 06-17-2009 02:18 PM
How to design the new bitcount function? jacklisp@gmail.com C Programming 10 11-08-2008 11:42 PM
newbie: bitcount for unsigned interegers Adam Chapman C Programming 2 10-27-2008 01:41 PM
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
HELP! HELP! HELP! Opening Web Application Project Error =?Utf-8?B?dHJlbGxvdzQyMg==?= ASP .Net 0 02-20-2004 05:16 PM



Advertisments