Link to home
Start Free TrialLog in
Avatar of OeilNoir
OeilNoir

asked on

Drag and Drop

How do i make so if i drop a file on a program i made, it automaticaly open it? The program open when i drop something on it, but of course, it doesn't open the file. in what way do i recive the "file parameter" so i can do something with it? i though it should be in the OLEDragDrop and such events of the form, but it doesn't seem to work. all i would like to do, would be to capture the path of the file name that have been droped on my program. Thanks...
Avatar of caraf_g
caraf_g

Check the variable Command$ - it might contain the full path of the file you dropped on your program; you might just have to write some straightforward code to extract it from there.


Avatar of OeilNoir

ASKER

Give more details please, where is the variable command$ is passed? in what events can i get it?
ASKER CERTIFIED SOLUTION
Avatar of chabaud
chabaud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
isn't there an easier way? i can't belive you need so much code to be able to use the drag and drop. what are the OLEDragDrop events and other of that kind are for?
Hello BlackEye!

Command$ is always available to your VB program, you don't need to pass it.

To check what's in it, just put in a message box somewhere at the start of your program.

MsgBox Command$

Then re-compile, and drop something on your program. If the message box then shows you something that contains, amongst other things, the full path of the file you've just dropped onto your program you'll know that Command$ will work for you.
caraf_g hehe you know some french =)
Well.. the command is almost what i want... it could work great, but it's using 8.3 format for file name... :-/ is there a way to have it to use the long name format? Also.. i guess i would have to "parse" to get the path if someone ever call my program with some other parameters...
Yes,

If it gives you the filename in 8.3 format, don't worry - as long as it gives you the full path. Let's say you extract this full path into a string variable named strFullPath.

If you then use strLongPath = Dir$(strFullPath, vbNormal), strLongPath will contain the long file name.
There is a difference between
- drag&drop a file from the windows explorer to an icon program (shortcut or not) on the desktop or in an explorer folder

and

- drag&drop some files from the windows explorer to an OPENED program (that is to a running window)

In the first case, just use the command$ function. To test it within VB see menu Project - Properties - Make and fill the "Command line argument"

In the second case, use my previous code (with API calls)
Sorry i should have said i wanted to drag and drop on an icon.. and not in the program.. well.. i think you 2 have a good answer...  i'll remake a question to give the points to caraf_g too..