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 -
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
-
1 Form: frmMain
2 buttons: cmdClear and cmdExit
1 listbox: lstFiles
1 label: lblNumFiles
1 label: lblInfo ["Number of dropped files"] -
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
-
4 5167
Would it be acceptable to drop the file onto another control, say a textbox, and have your code transfer it to the listbox?
Anyway, here's a sample I had lying around which may be some help. The files are dated 2001, I don't recall where it came from - picked it up on the web somewhere, I guess. It's just a project with a single form with the default name Form1. Here's the listing. If you want it, just create Form1, go to the code window, select all, then paste this in... - Option Explicit
-
DefLng A-Z
-
-
Private Sub Text1_OLEDragOver(Data As _
-
DataObject, Effect As Long, Button As Integer, _
-
Shift As Integer, X As Single, Y As Single, State _
-
As Integer)
-
If Data.GetFormat(vbCFFiles) Then
-
'If the data is in the proper format, _
-
inform the source of the action to be taken
-
Effect = vbDropEffectCopy And Effect
-
Exit Sub
-
End If
-
'If the data is not desired format, no drop
-
Effect = vbDropEffectNone
-
End Sub
-
-
Private Sub Text1_OLEDragDrop(Data As _
-
DataObject, Effect As Long, Button As Integer, _
-
Shift As Integer, X As Single, Y As Single)
-
If Data.GetFormat(vbCFFiles) Then
-
Dim vFN As Variant
-
-
For Each vFN In Data.Files
-
'DropFile Text1, vFN
-
Text1 = Text1 & vbCrLf & vFN
-
Next vFN
-
End If
-
End Sub
-
-
Sub DropFile(ByVal txt As TextBox, ByVal strFN$)
-
Dim iFile As Integer
-
iFile = FreeFile
-
-
Open strFN For Input Access Read Lock Write As #iFile
-
Dim Str$, strLine$
-
While Not EOF(iFile) And Len(Str) <= 32000
-
Line Input #iFile, strLine$
-
If Str <> "" Then Str = Str & vbCrLf
-
Str = Str & strLine
-
Wend
-
Close #iFile
-
-
txt.SelStart = Len(txt)
-
txt.SelLength = 0
-
txt.SelText = Str
-
-
End Sub
-
hi
tnx a lot, this one works indeed.
I just wanted to thank Killer42 for solving this same problem for me. I needed to have users drag files from Window explorer onto a form and attach them as documents based on their types. Your solution enabled me to do this.
Sincerely,
Don
I just wanted to thank Killer42 for solving this same problem for me. I needed to have users drag files from Window explorer onto a form and attach them as documents based on their types. Your solution enabled me to do this.
No problem, Don. Glad we could help. :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: hemant_mishal |
last post by:
Hi All,
I am writting a java script library which will provide inter frame drag
and drop operation. The more precise will be OLE drag and drop, which
means only data will be transfered from frame...
|
by: Lauren Quantrell |
last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.)
onto a field in Access2K and capture the full file path.
I found an posting below that says this is possible but I cannot...
|
by: SamSpade |
last post by:
There seems to be two ways to put things on the clipboard ( I don't mean
different formats): SetClipboardData and OleSetClipboard
If I want to get data off the clipboard do I care how it was put...
|
by: Ajay Krishnan Thampi |
last post by:
I have a slight problem implementing 'drag and drop' from a datagrid
to a tree-view. I have pasted my code below. Someone please advice me
on what to do...pretty blur right now.
==code==
...
|
by: jojobar |
last post by:
Hello,
I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I
tried to run it under firefox browser but it did not run.
If I want to use this feature in a commercial product...
|
by: VB Programmer |
last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2
listboxes? Thanks!
|
by: ViRi |
last post by:
I am currently experimenting a bit with
AxMicrosoft.MediaPlayer.Interop.AxWindowsMediaPlayer and so far, most
has gone well.
Currently, i would like to add drag-and-drop functionality to the...
|
by: Darren |
last post by:
I'm trying to create a file using drag and drop.
I want to be able to select a listview item drag it to the shell and create a file.
Each icon in the listview represents a blob in a database.
When...
|
by: RHSFSS |
last post by:
Hi, I have a Drag and Drop registration problem (See http://www.thescripts.com/forum/thread434707.html for similar problem post), can anyone out thereadvise on the best solution?
I have a .NET 2.0 ...
|
by: Romulo NF |
last post by:
Greetings,
I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |