In VB6, it is possible to use your app to put a list of files on the windows clipboard along with data telling if you want to cut or copy those files. Then the Windows file explorer can then take that list and copy or move those files. A lot of API calls are used to accomplish this.
In VB.Net, it is also possible to put this list of files, called a file drop list, on the clipboard as well as the DropEffect which tells Windows File explorer if the file list should be moved (a cut) or copied. You do not need all the API calls that were used in VB6 to accomplish it.
Set DropEffect in VB6:
In VB6 the file droplist is set with API calls to OpenClipboard, CopyMem, and SetClipboardData. The drop Effect is set with MoveMemory and RegisterClipboardFormat. Below is the function that is called in VB6 to set the drop effect. It is called with a vbDropEffectCopy to request a copy, and a vbDropEffectMove to request a cut.
Public Function SetFilesDropEffect(ByVal lEffect As Long) As Boolean
Dim lMemoryHandle As Long
Dim lMemoryPointer As Long
Dim lFormat As Long
Dim lReturn As Long
If OpenClipboard(0) Then
lMemoryHandle = GlobalAlloc(GHND, Len(lEffect))
If lMemoryHandle Then
lMemoryPointer = GlobalLock(lMemoryHandle)
Call MoveMemory(ByVal lMemoryPointer, lEffect, Len(lEffect))
lFormat = RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT)
lReturn = SetClipboardData(lFormat, lMemoryHandle)
If lReturn Then
SetFilesDropEffect = True
Set FileDropList and DropEffect in VB.Net:
In VB.Net, the Clipboard.SetFileDropList function can be used to place a list of files on the clipboard. It does not however have any way to set the DropEffect to tell File Explorer that you want to cut files instead of copy. So everything you put on the clip board this way is a copy.
If you use the SetDataObject to write a correctly created DataObject to the clipboard, you can pass the DropEffect as well as the DropFile List.
Setting the DropEffect in VB.Net requires creating a Data Object and writing it to the clipboard with Clipboard.SetDataObject. The Data Object needs to contain both the File DropList and DropEffect. They are put into the Object with the SetData method.
1) You need a String array of the filenames. It needs to be trimmed so there are no trailing spaces.
2) The DropEffectData is a 4 byte long byte array. The first byte is either 2 for move or 5 for copy. The remaining bytes are zeros.
3) Turn the DropEffectData into a 4 byte memory stream. This is the format of the Preferred Drop Effect data.
4) Create the Data Object.
5) Using SetData write the File DropList and DropEffect memory stream to the Data Object.
6) Clear the clipboard (this isn't required).
7) Write the data object to the clipboard with SetDataObject.
Dim sFiles() As String = Split(RichTextBox1.Text.TrimEnd, vbCrLf)
Dim DropEffectData(3) As Byte
Select Case TextBox1.Text.Substring(0, 1).ToString
Case 2 DropEffectData(0) = 2
Case 5 DropEffectData(0) = 5
Case Else DropEffectData(0) = 5
DropEffectData(1) = 0
DropEffectData(2) = 0
DropEffectData(3) = 0
Dim mstream As Stream = New MemoryStream(4)
mstream.Write(DropEffectData, 0, DropEffectData.Length)
Dim data_object As New DataObject()
data_object.SetData("FileDrop", True, sFiles)
data_object.SetData("Preferred DropEffect", mstream)
The Sample app will read the clipboard. If it finds a File DropList (from a File Explorer cut or paste), it will display the contents and DropEffect. The Set File DropList button will then Enable.
Clicking the Set File Droplist will execute the code above which Copies the data from the form and puts it back on the clipboard. You can then finish the cut or paste back in Explorer.