Results 1 to 14 of 14

Thread: *resolved*Drag files from windows explorer

  1. #1

    Thread Starter
    Lively Member pyrosis1313's Avatar
    Join Date
    Jun 2002
    Location
    Califonia
    Posts
    83

    Red face *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.

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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

  3. #3

    Thread Starter
    Lively Member pyrosis1313's Avatar
    Join Date
    Jun 2002
    Location
    Califonia
    Posts
    83

    Thanx

    Thanx JordanChris... just what I was looking 4.

  4. #4
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244

    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:
    1. Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Dim i As Integer
    3.     If Data.GetFormat(15) Then
    4.     'Format 15 is an array of names from WinExplorer
    5.     For i = 1 To Data.Files.Count
    6.     MsgBox Data.Files(i)
    7.     Next i
    8.     Data.Files.Clear
    9.     End If
    10. End Sub
    Nothing happens when I drop files from windows explorer on it. Could I be doing something wrong?

  5. #5
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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.

  6. #6
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244
    Could it be platform specific? Explorer specific? VB Specific?
    I am using VB6 Pro SP5, Windows 95 (A)

  7. #7
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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).

  8. #8
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244
    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.

  9. #9
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244
    Wow, you're right. It works when I do it on my 2000 machine. Let me try it on my 95 (B) machine

  10. #10
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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:
    1. Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.   MsgBox "Dropped it"
    3. End Sub

  11. #11
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244

    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.

  12. #12
    Junior Member
    Join Date
    Aug 2002
    Posts
    30
    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.

  13. #13
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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:
    1. Data.Files.Add "C:\Temp\Myfile1.TXT", 1
    2. Data.Files.Add "C:\Temp\Yourfile2.TXT", 2
    3. 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.

  14. #14
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    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
  •  



Click Here to Expand Forum to Full Width