views:

403

answers:

2

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.

+1  A: 

Probably your fastest way would be to store your movable image in one bitmap and then maintain a second temporary bitmap of the same size in memory as well. To draw your movable bitmap over your main image, you would first use the BitBlt API function to copy the region you're about to draw the movable bitmap onto into your temporary bitmap, then BitBlt your movable bitmap onto your main image. As you move the movable bitmap then, you would 1) BitBlt the temp bitmap onto its original location, then 2) BitBlt the new location into the temp bitmap, and then 3) BitBlt the movable image onto the new location in the main bitmap.

MusiGenesis
Yes I was thinking along these lines, but I had one try at something like this and the result wasn't as fast as I was hoping. So I was wondering if there is a better way.I am using GDI+ and I'm thinking it might be better to drop back to GDI as from my reading GDI+ isn't supported by video hardware acceleration.
nevf
BitBlt should be nearly instantaneous, so I'm not sure why that wouldn't be working for you.
MusiGenesis
+1  A: 

You should check out Image Lists which implement dragging effects.

The Win32 API includes functions for dragging an image on the screen. The dragging functions move an image smoothly, in color, and without any flashing of the cursor. Both masked and unmasked images can be dragged.

Of course the user don't actually have to drag the image. You do that by changing the image position.

Nick D
The image being moved is resizeable (ie. the user can change its size) so I don't think an ImageList is a good solution.
nevf
You can try layered windows, http://msdn.microsoft.com/en-us/library/ms997507.aspx (I have not try it so I'm not sure if you can resize them)
Nick D
I had tried a layered window but that didn't do what I needed.
nevf
Be aware that image list images max out at 256x256 pixels.
Oliver Bock