Bitmap help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kodiak

    #1

    Bitmap help

    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(D WORD hWnd, int height, int
    width, long *pIndex)
    {
    HDC hdc, hdcMem;
    HBITMAP bitmap;
    int y = 0;
    y = (4 * height) / 5;
    hdc = GetDC((HWND)hWn d);
    hdcMem = CreateCompatibl eDC(hdc);
    bitmap = CreateCompatibl eBitmap(hdcMem, width, height);
    SelectObject(hd cMem, 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;
    }

  • petschy

    #2
    Re: Bitmap help

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

    Comment

    • mlimber

      #3
      Re: Bitmap help

      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(D WORD hWnd, int height, int
      width, long *pIndex)
      {
      HDC hdc, hdcMem;
      HBITMAP bitmap;
      int y = 0;
      y = (4 * height) / 5;
      hdc = GetDC((HWND)hWn d);
      hdcMem = CreateCompatibl eDC(hdc);
      bitmap = CreateCompatibl eBitmap(hdcMem, width, height);
      SelectObject(hd cMem, 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.programmin g (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

      Comment

      • Kodiak

        #4
        Re: Bitmap help

        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(D WORD hWnd, int height, int
        width, long *pIndex)
        {
        HDC hdc, hdcMem;
        HBITMAP bitmap;
        int y = 0;
        y = (4 * height) / 5;
        hdc = GetDC((HWND)hWn d);
        hdcMem = CreateCompatibl eDC(hdc);
        bitmap = CreateCompatibl eBitmap(hdcMem, width, height);
        SelectObject(hd cMem, 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.programmin g (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

        Comment

        • Alf P. Steinbach

          #5
          Re: Bitmap help

          * 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?

          Comment

          • Phlip

            #6
            Re: Bitmap help

            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)storag e );

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


            Comment

            • Kodiak

              #7
              Re: Bitmap help

              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)storag e );
              >
              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!!!

              Comment

              • mlimber

                #8
                Re: Bitmap help

                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.programmin g (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.


                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

                Comment

                • red floyd

                  #9
                  Re: Bitmap help

                  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?

                  Comment

                  • Wayne Marsh

                    #10
                    Re: Bitmap help

                    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.

                    Comment

                    Working...