Date: 02-16-2022
Return to Index
created by gbSnippets
'The Windows API DragAcceptFiles can be applied to a dialog,
'allowing capture of the %WM_DropFiles message.
'Primary Code:
'There are 3 steps to allowing/getting a dropped filename
'1. Telling the application to accept dropped file information
DragAcceptFiles hDlg, %True
'2. Capturing the %WM_DropFiles message
Case %WM_DROPFILES
temp$ = GetDroppedFileName(CB.wParam)
DragFinish CB.wParam
'3. Extracting the filename
Function GetDroppedFileName(hDrop As DWord) As String
'David Gwillim July 2005
Local fString As Asciiz*%MAX_PATH, Count As Long
fString=Space$(%MAX_PATH)
Count = DragQueryFile(hDrop,0,fString,Len(fString)-1) ' put FileName(0) into fString and get character count
Function = Left$(fString,Count) ' put Count chars into result string
End Function
'At this point, drop the file name anywhere over the dialog.
'Note: the DragAcceptFiles can be applied to a specific control,
'rather than to the entire application
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Drop Test",300,300,200,200, %WS_OverlappedWindow To hDlg
DragAcceptFiles hDlg, %True
Control Add Label, hDlg, 200,"Drag/drop file anywhere within app!", 20,40,170,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local temp$
Select Case CB.Msg
Case %WM_DROPFILES
temp$ = GetDroppedFileName(CB.wParam)
DragFinish CB.wParam
MsgBox "Dropped filename: " + $crlf + $crlf + temp$
End Select
End Function
Function GetDroppedFileName(hDrop As DWord) As String
'David Gwillim July 2005
Local fString As Asciiz*%MAX_PATH, Count As Long
fString=Space$(%MAX_PATH)
Count = DragQueryFile(hDrop,0,fString,Len(fString)-1) ' put FileName(0) into fString and get character count
Function = Left$(fString,Count) ' put Count chars into result string
End Function
'gbs_00041
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm