Does anyone have a workaround to find out if their DragItem.Drag worked in Windows?
I have an edge case where the file I’ve created in the Temp folder remains and its copied to the target location rather than moved because CTRL was held down during the drop.
Normally using DoDragDrop would allow me to get around this by either removing the ability to hold CTRL down during the drop or by checking what happened during the drop by checking the pdwEffect value modified during the call. However, seemingly none of those options are exposed by the framework so I’m a bit stumped.
Do I need to roll my own DragDrop handler or am I missing something obvious?
I ran a test with the example program in Xojo’s Desktop/DragAndDrop/ListBoxDragAndDrop programs with Xojo 2018 r1.1, and pressing either shift with the mouse (cut and paste) or Ctrl with mouse (copy and paste) seems to always copy and paste.
When I have two folders open the Shift-DragAndDrop correctly cuts and pastes a file, while the ctrl-DragAndDrop correctly copies and pastes a file.
Was the purpose of the Ctrl-DragAndDrop to move a few selected files? I could be misunderstanding the purpose of the Ctrl-DragAndDrop in the program
Thanks for looking into it Eugene.
I’m basically dragging a file into the app, doing something to it which creates another file (in temp), then dragging out of the app into a new location which should place that new file from temp into the target location.
When I drag the file off my app and drop it onto explorer there’s no way for me to tell if that drop happened correctly, they could drop it onto an invalid target or press ESC during the drop which would cancel the drop. If the drop fails in this way the file will remain in Temp which I then want to tidy up. Also, when the drop is complete I update the UI to let the user know that everything worked, to do this at the moment I check that the temp file has been removed.
The CTRL-DragDrop is just messing things up for me because the DragDrop works is no modified keys are pressed during a the Drop however during a CTRL+DragDrop the file remains so I can’t use it to check if the DrapDrop worked.
This is the crux of the matter and why I asked for a little help to see if I was overlooking something obvious as I’m unable to find out if the DragDrop actually worked even though DoDragDrop should be letting the framework know, the info isn’t passed on to us unless I’m missing something.
I have and example that works when dragging a file from a folder to the listbox and will either copy (Ctrl-mouse drag) or move (Shift mouse drag) files. The secret is using DragActionCopy and DragActionMove.
Included in the download is the xojo_binary_project file and two example text files. Download the files to a directory, unzip the files and keep the directory open, as this example will be dragging and dropping these files from the folder into the listbox. Open a second folder at the specialfolder temp location (C:\Users\\AppData\Local\Temp). The temporary location is where the files will be copied or pasted from the original windows folder to the temp folder.
With the program running and the two folders open, mouse select MyTxt.txt in Windows folder and hold down the Ctrl key, drag the file to the list box and the file will be copied from the original folder to the temp folder.
Next, mouse select the MyTxt2.txt folder select the Shift key and drag it to the listbox. The file will be moved from the original folder and placed in the temp folder. The original file will be deleted.
Sorry, I ran out of time to work on the listbox selection to a file folder and hopefully the DragActionCopy and DragActionMove secret will help.
Thanks for looking into this again Eugene, I don’t have any issues dropping the file onto my app, the problem is when I’m dragging from my app to explorer as its the destination app (explorer in my case) that handles the drop.
I will admit defeat on DoDragDrop I tried to go through the example at SHDoDragDrop and wasn’t able to make it work.
SHDoDragDrop looks like its the correct avenue to have a listbox item correctly drop a file into a file folder on Windows.