Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag & Drop from Form to Windows; get drop destination

I have been developing an app in VB.NET which requires a control object (for example, a ListViewItem) to be dragged out of the form, and to a user-specified location (for example, on the desktop, or in a folder).

However, The file that is intended to be 'copied', as the 'ListViewItem' represents, does not yet exist. It needs to be downloaded and then placed in the user specified location. Am I able to get the path/location of the destination drop? I would then proceed to download the file, and then place it where the use specified.

I have looked at other questions regarding a similar issue, which details the dragging operation outside the form, its just there doesn't appear to be a way to determine where that short cut went or how to flag the destination location.

Essentially, I am thinking that it may require some sort of 'dynamic link' or 'virtual file' as I've seen mentioned elsewhere. Then, after the drop operation, somehow accessing this 'link' from my application, proceed to download the file and place it in the final drop destination.

Any help is appreciated, thanks in advance!


OUTCOME:

Roger Lipscombe provided a link that contained links to other articles, with what looks to be promising information. The following links may prove useful in implementing a drag drop operation without providing the exact data that is required in managed code.

  • Delay's Blog; Creating something from nothing
  • Delay's Blog; Creating something from nothing, asynchronously
like image 536
Jake Edwards Avatar asked Jan 23 '23 13:01

Jake Edwards


2 Answers

You can ask Explorer to delay an IDataObject::GetData call to CFSTR_FILEDESCRIPTOR to when the drop actually occurs by responding CFSTR_PREFERREDDROPEFFECT in your IDataObject::GetData implementation. See http://hg.mozilla.org/mozilla-central/file/b49a6a8a4973/widget/src/windows/nsDataObj.cpp for an example. Note if the target is a virtual folder, the drop target is not obligated to honor your preference.

Explorer check clipboard formats for file name in the folling order

  1. CF_HDROP

  2. CFSTR_FILEDESCRIPTOR/CFSTR_FILECONTENTS

  3. CFSTR_FILENAME

Do not use CF_HDROP because it requires that the source file(s) actually exist somewhere in the file system. Use CFSTR_FILEDESCRIPTOR/CFSTR_FILECONTENTS instead.

like image 150
Sheng Jiang 蒋晟 Avatar answered Feb 01 '23 17:02

Sheng Jiang 蒋晟


Do you really want to know where the "file" was dropped? Or do you just not want to provide the data up front?

If the latter, Raymond Chen has a whole series on implementing virtual drag and drop, in native code. David Anson translates it into managed code and adds asynchronous support.

like image 21
Roger Lipscombe Avatar answered Feb 01 '23 17:02

Roger Lipscombe