如何開啟從外面拖圖示到程式內執行?
從外面拖檔案到程式裡執行,其實不需用到API函數和Hook、Call
Back等,用以下短短幾行就行了:
Dim strpath As String
Private Sub Text1_OLEDragDrop(data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim txt As String
Dim retl As String
strpath = data.Files(1)
If Right(strpath, 3) = "txt" Then
readfile
Else
retl = MsgBox("This is not a txt file, Do you really want to open it?", vbYesNo Or
vbExclamation, "file extension")
If retl = vbYes Then readfile
End If
End Sub
Sub readfile()
Dim f As Integer
f = FreeFile
Open strpath For Input As #f
Text1.Text = ""
Do Until EOF(f) = True
Line Input #f, txt
Text1.Text = Text1.Text & txt & vbCrLf
Loop
Close #f
End Sub