GFReceiveFile/GFReceiveFile.frm
VERSION 5.00
Begin VB.Form Mfrm
Caption = "Drag files from Explorer over to this form."
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4695
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4695
StartUpPosition = 3 'Windows‑Standard
Begin VB.ListBox List1
Height = 1425
Left = 120
TabIndex = 0
Top = 120
Width = 4455
End
End
Attribute VB_Name = "Mfrm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'(c)2001, 2004 by Louis.
'
'NOTE: this is a demonstration of how to use WM_DROPFILES and some related
'API functions, there is no interface sub (copy code into misc. target subs).
'
'Downloaded from www.louis‑coder.com.
'This project demonstrates how to implement WM_DROPFILES processing.
'When you drag over a file from the Explorer to this form, then the file's name
'will be visible within the ListBox.
'
'GFReceiveFile
Private Declare Sub DragAcceptFiles Lib "shell32.dll" (ByVal hwnd As Long, ByVal fAccept As Long)
Private Declare Function DragQueryFile Lib "shell32.dll" Alias "DragQueryFileA" (ByVal hDrop As Long, ByVal UINT As Long, ByVal lpStr As String, ByVal ch As Long) As Long
Private Declare Sub DragFinish Lib "shell32.dll" (ByVal hDrop As Long)
'GFReceiveFile
Private Const WM_DROPFILES = &H233
Private Sub Form_Load()
'on error resume next
Call GFSubClass(Mfrm, "Form1", Mfrm, True)
Call DragAcceptFiles(Mfrm.hwnd, True)
End Sub
Public Sub GFSubClassWindowProc(ByVal SourceDescription As String, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByRef ReturnValue As Long, ByRef ReturnValueUsedFlag As Boolean)
'on error resume next
Dim Tempstr$
If Msg = WM_DROPFILES Then
Tempstr$ = String$(261, Chr$(0)) 'one additional char for the terminating null character
Call DragQueryFile(wParam, 0, Tempstr$, 260) 'pass True instead of 0 to get the file count (0 means receive name of first dropped file)
Call DragFinish(wParam)
Debug.Print Tempstr$
List1.AddItem Left$(Tempstr$, InStr(1, Tempstr$, Chr$(0), vbBinaryCompare) ‑ 1)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'on error resume next
Call DragAcceptFiles(Mfrm.hwnd, False) 'important, call when exiting program
Call GFSubClassmod.GFSubClass_Terminate 'important, call when exiting program
End Sub
[END OF FILE]