Move a bitmap around a window quickly in C++

眉间皱痕 提交于 2021-01-28 10:00:06

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1622117/move-a-bitmap-around-a-window-quickly-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!