Advertisement
4_2005-2006 OLE/ COM/ DCOM/ Active-X #152779

Simple ole drag and drop

This demonstrates a simple drag and drop of a file from windows explorer into a text box then grab the filename and path (this is part of the code im using to make a map install program for quake2)

AI

Tóm tắt bởi AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Mã nguồn
original-source
Private Sub text1_OLEDragDrop(Data As DataObject, Effect As Long _
, Button As Integer, Shift As Integer, X As Single, Y As Single)
' Prepare a variable (numfiles) and pass the number of files
' dropped onto text1 to this variable
Dim numFiles As Integer
 numFiles = Data.Files.Count
' an example how to trap 1 file (can be modified to trap as many
' or as little amount by changing the > 1 to > {new value}) then
' display a message box telling user the maximum allowed file drops)
' then exit the sub
If numFiles > 1 Then 
	MsgBox "Only allows 1 file at a time in beta version! Sorry!"_
	,vbOKOnly, "Ooops beta version"
	Exit Sub
end if
' check the attributes of the file being dropped and see if it is a
' directory, if it is then warn user that only files are valid to drop
' and exit the sub
If (GetAttr(Data.Files(1))) = vbDirectory Then
 MsgBox "Sorry this beta version only allows files not directories to be installed"
 Exit Sub
End If
' check the file is the correct file type (using its extension)
' if not then warn user and exit the sub
If LCase(Right(Data.Files(1), 3)) <> LCase("bsp") Then
 MsgBox "This file is not a quake 2 map (*.bsp)"
 Exit Sub
End If
' tell user the drag and drop was succesful
MsgBox Data.Files(1) + " installed"
' code here to install file
' or do what ever you need
' data.files(1) is a string holding the path and filename of the dropped file
' using a for..next loop you can control multiple files dropped at once
' replacing the 1 with the for..next variable and using numfiles to find out
' the maximum for..next value
End Sub
Bình luận gốc (3)
Được khôi phục từ Wayback Machine