Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Bitmap help

Reply
Thread Tools

Bitmap help

 
 
Kodiak
Guest
Posts: n/a
 
      11-13-2006
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;
}

 
Reply With Quote
 
 
 
 
petschy
Guest
Posts: n/a
 
      11-13-2006
this doesn't sound like a generic c++ question, rather than a win32 api
question.

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      11-13-2006
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

 
Reply With Quote
 
Kodiak
Guest
Posts: n/a
 
      11-13-2006
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


 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      11-13-2006
* 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?
 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      11-13-2006
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!!!


 
Reply With Quote
 
Kodiak
Guest
Posts: n/a
 
      11-13-2006
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!!!


 
Reply With Quote
 
mlimber
Guest
Posts: n/a
 
      11-13-2006
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

 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      11-13-2006
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?
 
Reply With Quote
 
Wayne Marsh
Guest
Posts: n/a
 
      11-14-2006
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.
 
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
Convert e.Graphics to an image or bitmap Charles A. Lackman ASP .Net 4 02-10-2011 08:08 AM
Help! How can I draw a bitmap only with BITMAP information! xqggz C++ 1 06-19-2007 03:07 PM
HELP! Create bitmap from binary XML string in MFC dom_perron@hotmail.com C++ 4 03-08-2007 10:06 PM
Active-HDL, bitmap, simulation, Tcl/Tk Stein Kj°lstad VHDL 1 02-11-2004 12:58 PM
Masked bitmap from bitmap Gandalf Python 0 01-29-2004 09:41 PM



Advertisments