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, than开发者_StackOverflow社区ks 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
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
CF_HDROP
CFSTR_FILEDESCRIPTOR/CFSTR_FILECONTENTS
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.
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.
I'm sorry, but there is no way to get the target path of a DnD operation. Because the drop target may not even have a path!
See here for a more detailed explanation.
Of course, you could try to hook into the DnD, then ask for the target window and from there try to find the target path if the window is known to you (e.g., the window belongs to the explorer process).
精彩评论