Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Move a bitmap around a window quickly in C++ [modified]

Move a bitmap around a window quickly in C++ [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++comgraphicsalgorithms
10 Posts 6 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neville Franks
    wrote on last edited by
    #1

    I'm looking for some C++ code to let me quickly move a bitmap around a window, restoring the background as it moves. At present I capture the Window contents to a bitmap during the app initialization and in the OnPaint() I draw the this bitmap and then I draw my overlayed bitmap. I am double buffering the paint. The overlayed bitmap position moves with the mouse which invalidates the Window. This works fine except it is too slow when the background window is large (think Windows Desktop) and the PC is slow. My guess is that redrawing the large background bitmap on every mouse move is the bottleneck. There has to be a much better and faster way to do this, but my searching hasn't found the answer I need.

    Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

    modified on Sunday, October 25, 2009 5:25 PM

    _ C C Y S 5 Replies Last reply
    0
    • N Neville Franks

      I'm looking for some C++ code to let me quickly move a bitmap around a window, restoring the background as it moves. At present I capture the Window contents to a bitmap during the app initialization and in the OnPaint() I draw the this bitmap and then I draw my overlayed bitmap. I am double buffering the paint. The overlayed bitmap position moves with the mouse which invalidates the Window. This works fine except it is too slow when the background window is large (think Windows Desktop) and the PC is slow. My guess is that redrawing the large background bitmap on every mouse move is the bottleneck. There has to be a much better and faster way to do this, but my searching hasn't found the answer I need.

      Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

      modified on Sunday, October 25, 2009 5:25 PM

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Try writing a handler for WM_ERASEBKGND[^] and return non-zero.

      «_Superman_» I love work. It gives me something to do between weekends.
      Microsoft MVP (Visual C++)

      N 1 Reply Last reply
      0
      • _ _Superman_

        Try writing a handler for WM_ERASEBKGND[^] and return non-zero.

        «_Superman_» I love work. It gives me something to do between weekends.
        Microsoft MVP (Visual C++)

        N Offline
        N Offline
        Neville Franks
        wrote on last edited by
        #3

        «_Superman_» wrote:

        Try writing a handler for WM_ERASEBKGND[^] and return non-zero.

        Thanks, but I'm already doing that.

        Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

        1 Reply Last reply
        0
        • N Neville Franks

          I'm looking for some C++ code to let me quickly move a bitmap around a window, restoring the background as it moves. At present I capture the Window contents to a bitmap during the app initialization and in the OnPaint() I draw the this bitmap and then I draw my overlayed bitmap. I am double buffering the paint. The overlayed bitmap position moves with the mouse which invalidates the Window. This works fine except it is too slow when the background window is large (think Windows Desktop) and the PC is slow. My guess is that redrawing the large background bitmap on every mouse move is the bottleneck. There has to be a much better and faster way to do this, but my searching hasn't found the answer I need.

          Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

          modified on Sunday, October 25, 2009 5:25 PM

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

          Try to redraw only parts on your window that really change instead of redrawing the whole thing.

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

          1 Reply Last reply
          0
          • N Neville Franks

            I'm looking for some C++ code to let me quickly move a bitmap around a window, restoring the background as it moves. At present I capture the Window contents to a bitmap during the app initialization and in the OnPaint() I draw the this bitmap and then I draw my overlayed bitmap. I am double buffering the paint. The overlayed bitmap position moves with the mouse which invalidates the Window. This works fine except it is too slow when the background window is large (think Windows Desktop) and the PC is slow. My guess is that redrawing the large background bitmap on every mouse move is the bottleneck. There has to be a much better and faster way to do this, but my searching hasn't found the answer I need.

            Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

            modified on Sunday, October 25, 2009 5:25 PM

            C Offline
            C Offline
            Chris Losinger
            wrote on last edited by
            #5

            if the background is static, you really only need to draw the overlay at its new position and then draw the parts of the background that were uncovered when the overlay moved. there's no need to redraw the whole background. 1. the overlay's previous rect = R1. 2. the overlay's new rect = R2. 3. R3 = the bounding rect of R1 and R2. 4. alloc a bitmap of size R3 5. fill it with the appropriate chunk of background 6. draw the overlay into the temp bitmap 7. draw the temp bitmap to the screen as long as the overlay is moving only a few pixels at a time, R3 should be just slightly bigger than the overlay size. if R1 and R2 don't instersect, you can split it into two operations: restore the background to one rect, then draw the overlay into the other - don't bother with the temp bitmap.

            image processing toolkits | batch image processing

            N 1 Reply Last reply
            0
            • C Chris Losinger

              if the background is static, you really only need to draw the overlay at its new position and then draw the parts of the background that were uncovered when the overlay moved. there's no need to redraw the whole background. 1. the overlay's previous rect = R1. 2. the overlay's new rect = R2. 3. R3 = the bounding rect of R1 and R2. 4. alloc a bitmap of size R3 5. fill it with the appropriate chunk of background 6. draw the overlay into the temp bitmap 7. draw the temp bitmap to the screen as long as the overlay is moving only a few pixels at a time, R3 should be just slightly bigger than the overlay size. if R1 and R2 don't instersect, you can split it into two operations: restore the background to one rect, then draw the overlay into the other - don't bother with the temp bitmap.

              image processing toolkits | batch image processing

              N Offline
              N Offline
              Neville Franks
              wrote on last edited by
              #6

              Thanks Chris, sounds like a good plan.

              Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

              1 Reply Last reply
              0
              • N Neville Franks

                I'm looking for some C++ code to let me quickly move a bitmap around a window, restoring the background as it moves. At present I capture the Window contents to a bitmap during the app initialization and in the OnPaint() I draw the this bitmap and then I draw my overlayed bitmap. I am double buffering the paint. The overlayed bitmap position moves with the mouse which invalidates the Window. This works fine except it is too slow when the background window is large (think Windows Desktop) and the PC is slow. My guess is that redrawing the large background bitmap on every mouse move is the bottleneck. There has to be a much better and faster way to do this, but my searching hasn't found the answer I need.

                Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

                modified on Sunday, October 25, 2009 5:25 PM

                Y Offline
                Y Offline
                yzprout
                wrote on last edited by
                #7

                Load the image to memory and try to move it.

                N 1 Reply Last reply
                0
                • Y yzprout

                  Load the image to memory and try to move it.

                  N Offline
                  N Offline
                  Neville Franks
                  wrote on last edited by
                  #8

                  I am already using a memory buffer as I said at the start: "I am double buffering the paint."

                  Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

                  1 Reply Last reply
                  0
                  • N Neville Franks

                    I'm looking for some C++ code to let me quickly move a bitmap around a window, restoring the background as it moves. At present I capture the Window contents to a bitmap during the app initialization and in the OnPaint() I draw the this bitmap and then I draw my overlayed bitmap. I am double buffering the paint. The overlayed bitmap position moves with the mouse which invalidates the Window. This works fine except it is too slow when the background window is large (think Windows Desktop) and the PC is slow. My guess is that redrawing the large background bitmap on every mouse move is the bottleneck. There has to be a much better and faster way to do this, but my searching hasn't found the answer I need.

                    Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

                    modified on Sunday, October 25, 2009 5:25 PM

                    S Offline
                    S Offline
                    Stuart Dootson
                    wrote on last edited by
                    #9

                    Would you get better performance by using your current methods but using (say) DirextX or OpenGL to do the blitting? They might have better performing drivers that make better use of hardware?

                    Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                    N 1 Reply Last reply
                    0
                    • S Stuart Dootson

                      Would you get better performance by using your current methods but using (say) DirextX or OpenGL to do the blitting? They might have better performing drivers that make better use of hardware?

                      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                      N Offline
                      N Offline
                      Neville Franks
                      wrote on last edited by
                      #10

                      Thanks Stuart. I'd considered that but didn't want to add the overhead and complication of using these libraries. As of late yesterday I now have an implementation that works well enough on my slow old Vista Notebook and very well on my Desktop PC. Basically doing what Chris suggested.

                      Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups