Yet another programming question, this time in VB6

Discussion in 'OT Technology' started by deusexaethera, Aug 1, 2005.

  1. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    How do I enable objects in my forms to detect files dragged and dropped from Explorer into my programs during runtime? I got a piece of old VB4 code, but it doesn't work and there's supposedly an easier way to do it in VB6 anyway. Not that I can find anything online, though. I've been looking for days.
     
  2. BinaryMadman

    BinaryMadman New Member

    Joined:
    Jul 27, 2005
    Messages:
    54
    Likes Received:
    0
    Location:
    Texas
    I know how a little. What kind of control do you want to have that support for?
     
  3. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    I have an irregularly-shaped, 100% draggable form that is masked by pictureboxes in areas that I don't want the user to be able to drag the form in, such that only the manufactured title bar of the form is draggable.

    One of those masks covers the main area of the form, where users will presumably try to drop icons from the desktop into the form. Ultimately those icons will need to be duplicated inside the main body of the form, but for now I'll settle for detecting the dragdrops and extracting the filenames of the objects dropped on the form.

    The short answer is: I need a picturebox to detect dragdrops from outside the application and extract whatever info it can about the objects being dropped, but it doesn't have to process the data yet.
     
  4. BinaryMadman

    BinaryMadman New Member

    Joined:
    Jul 27, 2005
    Messages:
    54
    Likes Received:
    0
    Location:
    Texas
    When I first thought about doing this I thought it would be freakishly hard, but it wasn't. VB6 does a lot of the hard work for you.

    Click on whatever picturebox you plan on using the Drag & Drop with in Design View and go to its property window on the right. One of the properties should be something called OLEDropMode...set it to '1 - Manual'. That tells VB you want to manually control what happens yourself.

    On the code view, type this in:
    Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Data.Files.Count = 0 Then Exit Sub
    Dim i As Integer

    For i = 1 To Data.Files.Count
    MsgBox Data.Files.Item(i)
    Next i
    End Sub
    This will go through each file(s) that you grabbed from Explorer and display its filename. Once you have the filename, well, you could pretty much figure anything out you want about it. You can use the Windows API to find out what icon is associated with that file type, the file size, or just read the file data in. It's pretty cool when you do it the first time and get the message boxes to show the file paths.:big grin:
     
  5. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    You are my hero. :bowdown: You saved me a ton of time trying to figure that out.
     
  6. BinaryMadman

    BinaryMadman New Member

    Joined:
    Jul 27, 2005
    Messages:
    54
    Likes Received:
    0
    Location:
    Texas
    No problem, it took me forever to figure out how to do that. I was wearing out the google servers trying to find that answer, LOL! In the end I sort of figured it out myself when I heard something about OLE allowing programs to be aware of windows objects. I didn't want to let someone else go through that hell so I tried to make the process easy to follow. You're welcome. :)
     

Share This Page