Hey guys,
am looking to create an object that obtains a file name and the path of the file, when it (the icon) is dragged onto the control.
Ex. Photoshop, Paintshop, Acrobat. and so on.
Printable View
Hey guys,
am looking to create an object that obtains a file name and the path of the file, when it (the icon) is dragged onto the control.
Ex. Photoshop, Paintshop, Acrobat. and so on.
Do you mean like when you drag a file from Windows Explorer?
If so, the following might help:
Drag and drop files onto an already running application. In this situation, the OLEDropMode must be set to
1 – Manual
for every object on the form that wants to receive a dropped file.
There are many OLExxxx subroutines that can be coded – the only one that is definitely required is the OLEDragDrop routine, which gets run when an item is dropped onto that object on the form.
The data that has been packaged by the dragged from application, is available to the dropped on application, although it must be decoded first. E.g. To identify a list of files from Windows Explorer use the following:
Dim i As Integer
If Data.GetFormat(15) Then
'Format 15 is an array of names from WinExplorer
For i = 1 To Data.Files.Count
MsgBox Data.Files(i)
Next i
Data.Files.Clear
End If
The Format numbers used in the OLE DragDrop data structure, are:
Text = 1 (vbCFText)
Bitmap = 2 (vbCFBitmap)
Metafile = 3
Emetafile = 14
DIB = 8
Palette = 9
Files = 15 (vbCFFiles)
RTF = -16639
If you want to drop files from your application back to Windows Explorer, the following will load the correct data structure with the file names (full names plus path are needed). Remember: Dropping these filenames onto Windows Explorer will initiate a copy operation.
Data.Files.Add "C:\Temp\Myfile1.TXT", 1
Data.Files.Add "C:\Temp\Yourfile2.TXT", 2
Data.SetData , 15
Thanx JordanChris... just what I was looking 4.
I created a form, then slapped a listbox on it, named List1. I set the listbox's OLEDropMode to 1 - Manual. Then I inserted this code:Nothing happens when I drop files from windows explorer on it. Could I be doing something wrong?VB Code:
Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) Dim i As Integer If Data.GetFormat(15) Then 'Format 15 is an array of names from WinExplorer For i = 1 To Data.Files.Count MsgBox Data.Files(i) Next i Data.Files.Clear End If End Sub
I just cut and pasted your code, then ran the application, then dragged a file from Windows Explorer and droped it onto the ListBox f the running application. It reported the file names that I had dragged correctly.
Could it be platform specific? Explorer specific? VB Specific?
I am using VB6 Pro SP5, Windows 95 (A)
VB version looks OK. Not totally sure about Windows 95 (although I know it works on 98, NT, 2000 and XP).
When you say "Nothing Happens"..... what exactly happens? Set a break point in your program, and make sure the Drop event is happening. At the same time you can step through the routine and make sure that there is something in the Data.GetFormat. Check all formats from Data.GetFormat(1) to (15).
When I say nothing happens, I mean the event didn't fire at all. I set a berakpoint on OLEDragDrop and it never got called.
Wow, you're right. It works when I do it on my 2000 machine. Let me try it on my 95 (B) machine
In whch case its nothing to do with Windows Explorer or GetFormat etc. Its all to do with your ListBox and application....
I have properties for the ListBox like:
DragMode = 0 - Manual
Enabled = True
OLEDragMode = 0 - Manual
OLEDropMode = 1 - Manual
Style = 0 - Standard
Is there anything else in your application that could be getting in the way? You could always create a new app with just this bit of code in it:
VB Code:
Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) MsgBox "Dropped it" End Sub
Remeber there were two (actually three) flavors of windows 95. One uses windows explorer (not internet explorer) version 4.0 (pictured here) This was released to the public as version A. Version B used Explorer version 4.7 and above. (pictured here) Typical characteristics of the latter were integrating windows explorer and IE into the same interface. Most people recognize this because it became the standard for all the windows platforms to come.
This works on the latter, but not the former. So few people still have Win95 (A) anyway, that I'm not even going to care. ;)
Hi Guys,
I have just read through your comments. The codes look very simple however,I am new to vb and i am a bit lost when it comes to draging an item from the list box to Win Explorer.
How do u implement it drag FROM Listbox TO Win Explorer.
Remember, dropping a file onto Windows Explorer will initiate a copy of the file.
In the OLEStartDrag routine (or elsewhere), you need to add the files you want to copy into the Data structure. Also you need to set the data format type:
Depending on what is in your ListBox will depend on how you make up the filenames (shown here as literal text). You will need to make sure that the full path of the file is given.VB Code:
Data.Files.Add "C:\Temp\Myfile1.TXT", 1 Data.Files.Add "C:\Temp\Yourfile2.TXT", 2 Data.SetData , 15
Is it possible to disable the Webbrowser drag and drop so that when you drag a link from the webbrowser to - say - word nothing is dropped? E.g. How could I access the variable where the drag&data is stored and null it?