How to drag & drop lots of files without taxing system resources?

爱⌒轻易说出口 提交于 2020-01-13 09:56:05

问题


One of the features that the program that I'm working on is the ability to drag objects from its main window and drop them onto Windows Explorer as files.

To do this, we override COleDataSource::OnRenderGlobalData() and, when the format is CF_HDROP, we save each object as a file. This works fine when the number of objects is small.

However, as we're now working on supporting enterprise level amounts of objects, we're seeing big delays, sometimes leading to hangs or eventual crashes, when the user tries to drag a lot of objects from our application into Windows Explorer.

My guess is that this is happening because OnRenderGlobalData() is being called quite a number of times, and of course, each time it has to loop through the objects that are being dragged and save them as files.

I was looking into the idea of overriding OnRenderFileData(), but the problem with that is that it only deals with one file at a time.

Is there any way that I can speed up our application when the user tries to drag a lot of objects onto Windows Explorer, preferably by moving the save loop to a place where it can be executed only once when the actual drop takes place?


回答1:


Instead of creating files, drag virtual data that is generated at drop time. Offer CFSTR_FILEGROUPDESCRIPTOR and CFSTR_FILECONTENTS. Here's an example.




回答2:


I have the same problem. My 'solution' is not very clever. I offer drag'n'drop as a convenience for a small number of objects. If the use has selected more than the number of objects that can be well handled, drag'n'drop is disabled and instead the user must select the destination from a folder browser dialog. When the destination is selected, the objects are written as files there, with a progress indicator.



来源:https://stackoverflow.com/questions/6868245/how-to-drag-drop-lots-of-files-without-taxing-system-resources

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