如何拖动&在不占用系统资源的情况下删除大量文件?

2022-01-12 00:00:00 windows drag-and-drop c++ mfc

我正在开发的程序的一个功能是能够从其主窗口拖动对象并将它们作为文件拖放到 Windows 资源管理器中.

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.

为此,我们重写 COleDataSource::OnRenderGlobalData() 并且当格式为 CF_HDROP 时,我们将每个对象保存为文件.当对象数量很少时,这可以正常工作.

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.

但是,由于我们现在正致力于支持企业级数量的对象,因此当用户尝试将大量对象从我们的应用程序拖到 Windows 资源管理器中时,我们会看到很大的延迟,有时会导致挂起或最终崩溃.

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.

我猜这是因为 OnRenderGlobalData() 被调用了很多次,当然,每次它都必须遍历被拖动的对象并保存它们作为文件.

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.

我正在研究重写 OnRenderFileData() 的想法,但问题是它一次只处理一个文件.

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.

当用户尝试将大量对象拖到 Windows 资源管理器上时,有什么方法可以加快我们的应用程序的速度,最好是通过将保存循环移动到在实际放置时只能执行一次的地方?

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?

推荐答案

不要创建文件,而是拖动拖放时生成的虚拟数据.提供 CFSTR_FILEGROUPDESCRIPTOR 和 CFSTR_FILECONTENTS.这是一个例子.

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

相关文章