Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag and Drop in VB5 Enterprise.

Status
Not open for further replies.

MarkWillsUK

Technical User
May 30, 2000
1
US
Hello. This is my first post to this forum!<br><br>I have an application that plays WAV files (amongst other things). I would like to be able to drag a file from windows explorer, or, maybe a window that was opened from 'my computer' etc to my application and have my application determine the path and filename of the the file that was dropped onto my application.<br><br>Does anyone know how to accomplish this?<br><br>I have looked in the on-line help for VB5, but the inference is that only objects from within the SAME FORM may be dragged and dropped on-top of each other. Yet, we all know that many programs allow files to be dropped onto them, a technique that goes way back to Windows 3.1!<br><br>So, could someone provide some example code that, when a file is dropped onto a form, a message box opens displaying the path/filename of the item that was dropped.<br><br>Many thanks in anticipation of any help!<br><br>Yours,<br><br>Mark Robert Wills<br>(Father of three, trying to learn programming!)<br>
 
Hi Mark<br><br>You don't pick easy questions to start with do you? &lt;smile&gt;<br><br>This is something that you feel *should* be easy in VB - but isn't.<br><br>I don't have VB5 at home - but I do have a VB6 example that you might find useful. This is from the VB6 online documentation. Quite a neat little example, start the app, start explorer, drag a text file (or two or three) onto the text box - and drop.<br><br>1 Start a new project in Visual Basic.<br><br>2 Add a text box control to the form. Set its OLEDropMode property to Manual. Set its MultiLine property to True and clear the Text property.<br><br>3 Copy and paste the following code into the form<br><FONT FACE=monospace><b><br>Private Sub Text1_OLEDragOver( _<br>&nbsp;&nbsp;&nbsp;&nbsp;Data As VBRUN.DataObject, _<br>&nbsp;&nbsp;&nbsp;&nbsp;Effect As Long, _<br>&nbsp;&nbsp;&nbsp;&nbsp;Button As Integer, _<br>&nbsp;&nbsp;&nbsp;&nbsp;Shift As Integer, _<br>&nbsp;&nbsp;&nbsp;&nbsp;X As Single, _<br>&nbsp;&nbsp;&nbsp;&nbsp;Y As Single, _<br>&nbsp;&nbsp;&nbsp;&nbsp;State As Integer _<br>)<br><br>If Data.GetFormat(vbCFFiles) Then<br>'If the data is in the proper format, inform the source of the action to be taken<br>&nbsp;&nbsp;&nbsp;&nbsp;Effect = vbDropEffectCopy And Effect<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>End If<br><br>'If the data is not desired format, no drop<br>Effect = vbDropEffectNone<br><br>End Sub<br><br>Sub DropFile( _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal txt As TextBox, _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal strFN$ _<br>)<br><br>Dim iFile As Integer<br>iFile = FreeFile<br><br>Open strFN For Input Access Read Lock Read Write As #iFile<br>Dim Str$, strLine$<br>While Not EOF(iFile) And Len(Str) &lt;= 32000<br>&nbsp;&nbsp;&nbsp;&nbsp;Line Input #iFile, strLine$<br>&nbsp;&nbsp;&nbsp;&nbsp;If Str &lt;&gt; &quot;&quot; Then Str = Str & vbCrLf<br>&nbsp;&nbsp;&nbsp;&nbsp;Str = Str & strLine<br>Wend<br>Close #iFile<br><br>txt.SelStart = Len(txt)<br>txt.SelLength = 0<br>txt.SelText = Str<br><br>End Sub<br><br>Private Sub Text1_OLEDragDrop( _<br>&nbsp;&nbsp;&nbsp;&nbsp;Data As VBRUN.DataObject, _<br>&nbsp;&nbsp;&nbsp;&nbsp;Effect As Long, _<br>&nbsp;&nbsp;&nbsp;&nbsp;Button As Integer, _<br>&nbsp;&nbsp;&nbsp;&nbsp;Shift As Integer, _<br>&nbsp;&nbsp;&nbsp;&nbsp;X As Single, _<br>&nbsp;&nbsp;&nbsp;&nbsp;Y As Single _<br>)<br><br>If Data.GetFormat(vbCFFiles) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim vFN<br>&nbsp;&nbsp;&nbsp;&nbsp;For Each vFN In Data.Files<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DropFile Text1, vFN<br>&nbsp;&nbsp;&nbsp;&nbsp;Next vFN<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End Sub<br></font></b><br><br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Please -- Don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top