By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,345 Members | 1,667 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,345 IT Pros & Developers. It's quick & easy.

Bitmap help

P: n/a
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;
}

Nov 13 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
this doesn't sound like a generic c++ question, rather than a win32 api
question.

Nov 13 '06 #2

P: n/a
Kodiak wrote:
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-lit....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

Nov 13 '06 #3

P: n/a
I posted to this group because I am developing the code using C++.

mlimber wrote:
Kodiak wrote:
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-lit....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
Nov 13 '06 #4

P: n/a
* Kodiak:
[top-posting]
Please don't.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 13 '06 #5

P: n/a
Kodiak wrote:
>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.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 13 '06 #6

P: n/a
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.

Phlip wrote:
Kodiak wrote:
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.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 13 '06 #7

P: n/a
Kodiak wrote:
mlimber wrote:
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-lit....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.

I posted to this group because I am developing the code using C++.
[Top-posting corrected. Cf.
http://parashift.com/c++-faq-lite/ho....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

Nov 13 '06 #8

P: n/a
Kodiak wrote:
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?
Nov 13 '06 #9

P: n/a
red floyd wrote:
Kodiak wrote:
>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?
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.
Nov 14 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.