|
-
Sep 9th, 2002, 03:29 AM
#1
Thread Starter
Lively Member
*resolved*Drag files from windows explorer
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.
Last edited by pyrosis1313; Sep 9th, 2002 at 05:42 PM.
-
Sep 9th, 2002, 03:55 AM
#2
Frenzied Member
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
-
Sep 9th, 2002, 05:43 PM
#3
Thread Starter
Lively Member
Thanx
Thanx JordanChris... just what I was looking 4.
-
Oct 2nd, 2002, 10:03 AM
#4
Addicted Member
Perhaps you could give a fuller axample, JordanChris
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:
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
Nothing happens when I drop files from windows explorer on it. Could I be doing something wrong?
-
Oct 2nd, 2002, 10:16 AM
#5
Frenzied Member
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.
-
Oct 2nd, 2002, 10:19 AM
#6
Addicted Member
Could it be platform specific? Explorer specific? VB Specific?
I am using VB6 Pro SP5, Windows 95 (A)
-
Oct 2nd, 2002, 10:26 AM
#7
Frenzied Member
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).
-
Oct 2nd, 2002, 10:28 AM
#8
Addicted Member
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.
-
Oct 2nd, 2002, 10:32 AM
#9
Addicted Member
Wow, you're right. It works when I do it on my 2000 machine. Let me try it on my 95 (B) machine
-
Oct 2nd, 2002, 10:35 AM
#10
Frenzied Member
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
-
Oct 2nd, 2002, 10:56 AM
#11
Addicted Member
It does seem to be explorer specific.
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.
-
Oct 10th, 2002, 01:52 AM
#12
Junior Member
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.
-
Oct 10th, 2002, 03:08 AM
#13
Frenzied Member
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:
VB Code:
Data.Files.Add "C:\Temp\Myfile1.TXT", 1
Data.Files.Add "C:\Temp\Yourfile2.TXT", 2
Data.SetData , 15
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.
Last edited by JordanChris; Oct 10th, 2002 at 03:12 AM.
-
Oct 24th, 2002, 09:11 AM
#14
Fanatic Member
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|