drag & drop onto application icon

Windows specific forum
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

drag & drop onto application icon

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Urgh I'm an idiot.. thanks Netmaestro.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Thanks netmaestro - as usual, you're the man :)
User avatar
Michael Vogel
Addict
Addict
Posts: 2821
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
User avatar
Michael Vogel
Addict
Addict
Posts: 2821
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

netmaestro wrote:Should be fine to use, imho.
Right!
And when you see this message, you will know why... :roll:
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Thanks Michael & netmaestro for the constructive comment & tips. Much appreciated.
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

Thanks for sharing! That works like a champ :!:
Intrigued - Registered PureBasic, lifetime updates user
Post Reply