Bitmap help

Discussion in 'C++' started by Kodiak, Nov 13, 2006.

  1. Kodiak

    Kodiak Guest

    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;
    }
    Kodiak, Nov 13, 2006
    #1
    1. Advertising

  2. Kodiak

    petschy Guest

    this doesn't sound like a generic c++ question, rather than a win32 api
    question.
    petschy, Nov 13, 2006
    #2
    1. Advertising

  3. Kodiak

    mlimber Guest

    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-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
    mlimber, Nov 13, 2006
    #3
  4. Kodiak

    Kodiak Guest

    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-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
    Kodiak, Nov 13, 2006
    #4
  5. * 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?
    Alf P. Steinbach, Nov 13, 2006
    #5
  6. Kodiak

    Phlip Guest

    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!!!
    Phlip, Nov 13, 2006
    #6
  7. Kodiak

    Kodiak Guest

    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!!!
    Kodiak, Nov 13, 2006
    #7
  8. Kodiak

    mlimber Guest

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

    >
    > 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
    mlimber, Nov 13, 2006
    #8
  9. Kodiak

    red floyd Guest

    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?
    red floyd, Nov 13, 2006
    #9
  10. Kodiak

    Wayne Marsh Guest

    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.
    Wayne Marsh, Nov 14, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman

    Convert e.Graphics to an image or bitmap

    Charles A. Lackman, Jun 10, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    15,505
    logon68
    Feb 10, 2011
  2. Stein Kjølstad

    Active-HDL, bitmap, simulation, Tcl/Tk

    Stein Kjølstad, Feb 11, 2004, in forum: VHDL
    Replies:
    1
    Views:
    612
    valentin tihomirov
    Feb 11, 2004
  3. Gandalf

    Masked bitmap from bitmap

    Gandalf, Jan 29, 2004, in forum: Python
    Replies:
    0
    Views:
    565
    Gandalf
    Jan 29, 2004
  4. Replies:
    4
    Views:
    515
    red floyd
    Mar 8, 2007
  5. xqggz
    Replies:
    1
    Views:
    403
    Victor Bazarov
    Jun 19, 2007
Loading...

Share This Page