hi
i've been snooping around on the internet trying to get something usefull for my drag and drop problem.
i want to get the filename of a dropped file in a listbox.
now, i have found a source but it does not always work.
why ? or rather why not?
the code for module1
1 Form: frmMain
2 buttons: cmdClear and cmdExit
1 listbox: lstFiles
1 label: lblNumFiles
1 label: lblInfo ["Number of dropped files"]
i've been snooping around on the internet trying to get something usefull for my drag and drop problem.
i want to get the filename of a dropped file in a listbox.
now, i have found a source but it does not always work.
why ? or rather why not?
the code for module1
Code:
Type POINTAPI x As Long y As Long End Type Type MSG hWnd As Long message As Long wParam As Long lParam As Long time As Long pt As POINTAPI End Type Declare Sub DragAcceptFiles Lib "shell32.dll" (ByVal hWnd As Long, ByVal fAccept As Long) Declare Sub DragFinish Lib "shell32.dll" (ByVal hDrop As Long) 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 Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As MSG, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long Public Const PM_NOREMOVE = &H0 Public Const PM_NOYIELD = &H2 Public Const PM_REMOVE = &H1 Public Const WM_DROPFILES = &H233
2 buttons: cmdClear and cmdExit
1 listbox: lstFiles
1 label: lblNumFiles
1 label: lblInfo ["Number of dropped files"]
Code:
Dim FileDropMessage As MSG ' Msg Type Dim FileDropped As Boolean ' True if Files where dropped Dim hDrop As Long ' Pointer to the dropped file structure Dim FileName As String * 128 ' the dropped filename Dim numOfDroppedFiles As Long ' the amount of dropped files Dim curFile As Long ' the current file number Dim ret As Long Private Sub cmdclear_Click() lstFiles.Clear lblNumFiles.Caption = "0" End Sub Private Sub cmdexit_Click() Unload Me End End Sub Private Sub Form_Load() frmmain.Show DragAcceptFiles frmmain.hWnd, True Do If PeekMessage(FileDropMessage, 0, WM_DROPFILES, WM_DROPFILES, PM_REMOVE Or PM_NOYIELD) = True Then hDrop = FileDropMessage.wParam numOfDroppedFiles = DragQueryFile(hDrop, True, FileName, 127) For curFile = 1 To numOfDroppedFiles ret = DragQueryFile(hDrop, curFile - 1, FileName, 127) lblNumFiles.Caption = LTrim(Str(numOfDroppedFiles)) lstFiles.AddItem FileName Next curFile DragFinish hDrop End If DoEvents Loop End Sub
Comment