开发者

Move a bitmap around a window quickly in C++

开发者 https://www.devze.com 2022-12-09 22:38 出处:网络
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

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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消