Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 570
RobH Avatar asked Jul 29 '11 03:07

RobH


People also ask

How do you click and drag on a PC?

"Clicking and dragging" is a way to move certain objects on the screen. To move an object, place the mouse cursor over it, press and hold down the left mouse button, then move the mouse while still holding down the left mouse button.

How do you drag on a laptop?

Put the mouse pointer over the file or folder. Press and hold mouse button 1. Drag the icon to where you want to drop it. Release the mouse button.

How do I drag with touchpad?

How do I Drag and Drop? By default, if you left-click and HOLD the left mouse or touchpad button while moving your mouse pointer to a different folder location on the same drive, when you release the left mouse button the file will be moved to the new location where you released the mouse button.


1 Answers

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

like image 199
Raymond Chen Avatar answered Oct 05 '22 23:10

Raymond Chen