Results 1 to 4 of 4

Thread: Drag And Drop From Explorer

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    West Palm Beach, Florida
    Posts
    188

    Drag And Drop From Explorer

    I have done some nice drag and drop code which works from in my vb application. However, how do I get my end users to drag and drop from another application onto mine (i.e. a picture file from explorer into a image box in my application) if I cannot set the start drag when the mouse goes down. If I try to put code in the drag and drop event.... the computer simply changes the mouse to a no entry sign when trying to drag another file from somewhere else on my computer.

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Some ideas to help you:

    If the application is not started, and you drag and drop files to your programs icon in Windows Explorer (whether that icon is on your desktop, or in the list of files within a folder) then the application is started and the parameters (the files you were dragging and dropped) are passed in using the Command() function.

    A different scenario is required if you 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. To identify a list of files from Windows Explorer use the following:
    VB Code:
    1. Dim i As Integer
    2.     If Data.GetFormat(15) Then
    3. 'Format 15 is an array of names from WinExplorer
    4.         MsgBox “The first file is “ & Data.Files(1)
    5.         For i = 2 To Data.Files.Count
    6.           MsgBox “Next file: “ & Data.Files(i)
    7.         Next i
    8.         Data.Files.Clear
    9.     End If
    The Format numbers used in the OLE DragDrop data structure, are:
    Text = 1 (vbCFText)
    Bitmap = 2 (vbCFBitmap)
    Metafile = 3 (used when dragging attachments from Outlook)
    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.
    VB Code:
    1. Data.Files.Add "C:\Temp\Myfile1.TXT", 1
    2. Data.Files.Add "C:\Temp\Yourfile2.TXT", 2
    3. Data.SetData , 15

  3. #3
    Hyperactive Member csar's Avatar
    Join Date
    Mar 2002
    Location
    Siam
    Posts
    288
    In reverse, could I know where another object/window that will get droped. (User's trying to drag from my App to drop to another)

    I think API may be used ?? but what/how?

    Thank in advance!
    Don't leave it till tomorrow, Do It Now!
    5361726176757468204368616E63686F747361746869656E

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    The dragged from application knows nothing about where an item will be dragged to.

    The idea of drag / drop is that the dragged from app has no idea where the item will be dropped. The dropped on app has no idea where the item has been dragged from. The only communication between the two is the item itself.

    Using the OLEDragDrop facilities you can do a little better than this, by packaging up a "droppable item" with the names of files or other options.

    Windows Explorer performs a certain action when something is dropped onto it. It does a FileCopy of the name of the item. It doesn't matter where it has been dragged from, WinExp expects to have a filename dropped on it that it can copy. So if you have a user that is going to drag from your app and drop onto WinExp you have to package up the filenames with their full paths correctly in the OLE item.

    If you have an application that is expecting at item to be dropped onto it, then that app will do certain things with the information it is given.

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