DragQueryFile

機能
ドロップされたファイル情報を取得
Declare Function DragQueryFile Lib "shell32.dll" _
Alias "DragQueryFileA" _
(ByVal hDrop As Long, ByVal iFile As String, _
ByVal lpszFile As String, ByVal cch As Long) As Long
Declare Function DragQueryFile Lib "shell32.dll" _
Alias "DragQueryFileA" _
(ByVal hDrop As Integer, ByVal iFile As String, _
ByVal lpszFile As String, ByVal cch As Integer) As Integer

UINT DragQueryFile(
HDROP hDrop,
UINT iFile,
LPTSTR lpszFile,
UINT cch
);
引数
hDrop

WM_DROPFILESで与えられる内部データ構造体のハンドル
iFile
ドロップされたファイルのインデックス
hDrop構造体のファイル数を得るとき-1(&HFFFFFFFF)
lpszFile
(戻り値)ファイル名を受け取るバッファ
cch
同、バイト数
戻り値
正常終了のとき  コピーしたバイト数
iFileに-1を設定したとき      ファイル数
サンプル
ダウンロード(DragQueryFile.lzh 3.50KB)

Private Sub Command1_Click()
Call OpenFile
End Sub

Private Sub Form_Load() Me.List1.Clear 'ファイルが受け取れるように設定 Call DragAcceptFiles(Me.Text1.hWnd, 1) hOldWndProc = SetWindowLong(Me.Text1.hWnd, GWL_WNDPROC, AddressOf TestProc) End Sub
Private Sub Form_Unload(Cancel As Integer) Call SetWindowLong(Me.Text1.hWnd, GWL_WNDPROC, hOldWndProc) End Sub
Private Sub List1_DblClick() Call OpenFile End Sub
Private Sub OpenFile() Dim nIndex As Long, FileName As String Dim Txt As String, Temp As String '現在選択されている項目番号を調べる nIndex = Me.List1.ListIndex 'ファイル名の取得 FileName = Me.List1.List(nIndex) '拡張子があるかどうか調べる a = InStr(FileName, Chr(46)) If a < 1 Then Exit Sub '開く Txt = "" Open FileName For Input As #1 Do While Not EOF(1) Line Input #1, Temp Txt = Txt + Temp + Chr(13) + Chr(10) Loop Close Me.Text1.Text = Txt End Sub