Bitmap help

K

Kodiak

I am passing in a reference to a window handle, followed by the height
and width as well into my method. I am then creating a Device Context
using the window handle and converting the window in a bitmap saved in
memory. What I am trying to accomplish is generating a checksum value
and returning that value from the bitmap stored in memory, but I cannot
solve this problem. The method is designed to given a window handle,
height, and width, take an image of the window, and return the checksum
value. I am trying to check to see if the window changes by using the
checksum values. Any help with this method and problem is greatly
appreciated! Please see the code below for what I have done so far!


STDMETHODIMP CCaptureBitmap::BitmapResult(DWORD hWnd, int height, int
width, long *pIndex)
{
HDC hdc, hdcMem;
HBITMAP bitmap;
int y = 0;
y = (4 * height) / 5;
hdc = GetDC((HWND)hWnd);
hdcMem = CreateCompatibleDC(hdc);
bitmap = CreateCompatibleBitmap(hdcMem, width, height);
SelectObject(hdcMem, bitmap);
BitBlt(hdcMem, 0, 0, width, y, hdc, 0, 0, SRCCOPY);

//Need to add code here to generate checksum value.

ReleaseDC((HWND)hWnd, hdc);
return S_OK;
}
 
M

mlimber

Kodiak said:
I am passing in a reference to a window handle, followed by the height
and width as well into my method. I am then creating a Device Context
using the window handle and converting the window in a bitmap saved in
memory. What I am trying to accomplish is generating a checksum value
and returning that value from the bitmap stored in memory, but I cannot
solve this problem. The method is designed to given a window handle,
height, and width, take an image of the window, and return the checksum
value. I am trying to check to see if the window changes by using the
checksum values. Any help with this method and problem is greatly
appreciated! Please see the code below for what I have done so far!


STDMETHODIMP CCaptureBitmap::BitmapResult(DWORD hWnd, int height, int
width, long *pIndex)
{
HDC hdc, hdcMem;
HBITMAP bitmap;
int y = 0;
y = (4 * height) / 5;
hdc = GetDC((HWND)hWnd);
hdcMem = CreateCompatibleDC(hdc);
bitmap = CreateCompatibleBitmap(hdcMem, width, height);
SelectObject(hdcMem, bitmap);
BitBlt(hdcMem, 0, 0, width, y, hdc, 0, 0, SRCCOPY);

//Need to add code here to generate checksum value.

ReleaseDC((HWND)hWnd, hdc);
return S_OK;
}

Your question does not appear to be related to the C++ language proper,
which is the topic of this group (see
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9). You
may want to ask in comp.programming (for general algorithmic questions)
or a Microsoft group (for help with their API and frameworks). Of
course, if during your development, you come upon a question about the
language itself, this is the right place to ask.

Cheers! --M
 
P

Phlip

Kodiak said:
I posted to this group because I am developing the code using C++.

Win32 API code can be called from any language, and this newsgroup is only
qualified to discuss the raw C++ language itself. You will get much better
results posting to the narrowest possible newsgroup.

However, you didn't specify exactly what your problem actually is. (It could
still be a C++ question, even with all these HWND things going on!) You
might be having trouble between reading the bitmap and extracting its bits
as data. That would be Win32-side, not C++ side!
What I am trying to accomplish is generating a checksum value
and returning that value from the bitmap stored in memory, but I cannot
solve this problem.

The problem of what, the checksum?
BitBlt(hdcMem, 0, 0, width, y, hdc, 0, 0, SRCCOPY);

Now you need to get to the memory backing up the hdcMem, and point into it
with (probably) an unsigned char pointer.

If this code were on-topic, I could explain to you what it does. It is
enough to get you googling - copying the bits out of a bitmap is a FAQ on
Win32 graphics programming forums.

HBITMAP hOld = ( HBITMAP ) SelectObject( hMemDC, hBitmap );
assert( hOld );

worked = BitBlt( hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, SRCCOPY );
assert( worked );

HGLOBAL_t storage = GlobalAlloc( GMEM_FIXED, pbih->biSizeImage );
LPBYTE lpBits = static_cast< LPBYTE >( (HGLOBAL)storage );

assert( lpBits );

// Retrieve the color table (RGBQUAD array) and the bits
// (array of palette indices) from the DIB.
BOOL worked = GetDIBits( hDC, hBMP, 0, pbih->biHeight, lpBits, pbi,
DIB_RGB_COLORS );

Note that if I tried to explain those and got anything wrong, _this_
newsgroup would not be qualified to correct me.

After you have the bits in lpBits, you need to Google for a code snippet
that shows how to generate a checksum, and you need to adapt that code to
the LPBYTE.
 
K

Kodiak

Thanks phillip for pointing me in the right direction. I due apologize
for posting to the wrong newsgroup.

Phillip my probem was trying to get the bytes out of the bitmap.
 
M

mlimber

Kodiak said:
I posted to this group because I am developing the code using C++.

[Top-posting corrected. Cf.
http://parashift.com/c++-faq-lite/how-to-post.html#faq-5.4]

As the FAQ I cited in my previous response explains, this newsgroup is
for discussing the *language* as defined by the C++ Standard, not
platform-specific libraries or arbitrary applications of the language.
Asking "How do I convert Yen to Dollars?", for instance, is also
off-topic (even if you were intending to perform the conversion in a
C++ program) because the question deals with an algorithm that is not
part of the standard language or library.

Cheers! --M
 
R

red floyd

Kodiak said:
I posted to this group because I am developing the code using C++.

Assuming that Minesweeper is written in C++, and that Word is written in
C++, would you then feel it appropriate to post questions about
Minesweeper or Word here?
 
W

Wayne Marsh

red said:
Assuming that Minesweeper is written in C++, and that Word is written in
C++, would you then feel it appropriate to post questions about
Minesweeper or Word here?

That's a flawed analogy. You need to formulate one that involves a
something akin to USING C++ and not being relevant to this group.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top