Page 1 of 1
drag & drop onto application icon
Posted: Fri Jun 23, 2006 4:10 am
by mskuma
I'd like to extract a list of files dropped onto my application icon (before a window has opened). Has anyone done this?
I've searched here and seems like all related topics are about drag/dropping onto already open windows or gadgets.
Thanks for any help.
Posted: Fri Jun 23, 2006 4:49 am
by netmaestro
Hi mskuma. Afaik it will happen automatically if your program is already set up to take commandline parameters. Windows will run the icon's target application and pass it the filename that got dropped on it. I just tested it with a couple of my programs and it works like a charm.
Posted: Fri Jun 23, 2006 4:55 am
by mskuma
Urgh I'm an idiot.. thanks Netmaestro.
Posted: Fri Jun 23, 2006 5:16 am
by mskuma
netmaestro, I guess you mean something like this?
Code: Select all
Repeat
File$ = ProgramParameter() ; get the next parameter (if any)
MessageRequester("test","file dropped: " + File$)
Until ProgramParameter() = ""
I might be wrong, but I think it only works when one file dropped. For my current purpose, one file is ok but I noticed then I dropped 2 (or more) files on the icon, only one file was picked up. If anyone has a suggested improvement, would be great. Thanks.
Posted: Fri Jun 23, 2006 5:59 am
by netmaestro
It's working fine here. Try this code version:
Code: Select all
numfiles=CountProgramParameters()
For i = 1 To numfiles
File$ = ProgramParameter()
MessageRequester("test","file dropped: " + File$)
Next
I ran this and selected a bunch of files, dragged them to the desktop icon which was a shortcut to the compiled program, and it processed them each in turn without fail. Copy/Paste works equally well.
Posted: Fri Jun 23, 2006 6:41 am
by mskuma
Thanks netmaestro - as usual, you're the man

Posted: Fri Jun 23, 2006 6:44 am
by Michael Vogel
Please be careful! Command line parameters are limited (to 1020 or 2040 chars or so), so putting quit a lot of files onto an icon will make problems!
So if your program should not only interact with single files, you can also allow your program to open a window (when started without parameter) to be able to accept "real" drag and drop...
Michael.
Posted: Fri Jun 23, 2006 7:04 am
by netmaestro
2000/XP should have a limit of 2040, which allows to select over fifty files with pathnames 40 characters long. If it exceeds this amount, you just get a message from Windows saying it can't access the file specified, it doesn't crash anything. Should be fine to use, imho.
Posted: Mon Jun 26, 2006 10:29 am
by Michael Vogel
netmaestro wrote:Should be fine to use, imho.
Right!
And when you see this message, you will know why... :roll:
Posted: Mon Jun 26, 2006 10:42 am
by mskuma
Thanks Michael & netmaestro for the constructive comment & tips. Much appreciated.
Posted: Mon Aug 14, 2006 2:33 am
by Intrigued
Thanks for sharing! That works like a champ
