Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dropping a file on programs icon or shortcut & opening 1

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
GB
Hallo.
Does anyone know how to have your program open when a user drops an associated file over it?
Cheers,
Douglas JL

A salesman is a machine for turning coke into obnoxious arrogance.

Common sense is what tells you the world is flat.

 
It is automatic in windows. Values are passed in to a program through the WinMain Function.

Typically, Borland creates the code as:
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)

LPSTR is the string input parameter for command line.
Redefine it as:
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR CmdLine, int)

Then CmdLine will contain the name of the file you dragged over the program's icon.

Chris
 
Thanks alot, man!
DJL

A salesman is a machine for turning coke into obnoxious arrogance.

Common sense is what tells you the world is flat.

 
Hello

I?m trying to do the same thing. I made what Supernat03 said, but now the program tries to open "the file" even when i just open the program (double click). How can i say to the program to exectute that only when a file is dragged over the program's icon?

My program sees if the file is in a supported format and if not it shows a message. When i open a file (not supported) by dragging it over the program's icon it shows the message but the main program's windows goes to back (to back the window where the file i dragged were....for example), why?
 
Please somenone answer me.

I think that when I open the program (double click) the CmdLine is empty, so I just need to verify if it is empty, and if so the program shouldn't try to open "the file". But how can i know if the CmdLine is empty? CmdLine.IsEmpty() doesn?t works.
 
Try something like:

if(CmdLine!=""){
//open file(s)
}
else{
//don't bother
}

Or am I misunderstanding?
DJL

A salesman is a machine for turning coke into obnoxious arrogance.

Common sense is what tells you the world is flat.

 
I may be being REALLY dumb, but how on earth do you get the CmdLine information to the form to use it?
I've tried declaring a global LPSTR & assigning CmdLine to that, but the form still can't see it.
Hmm...
Anyone?
DJL

A salesman is a machine for turning coke into obnoxious arrogance.

Common sense is what tells you the world is flat.

 
Try

AnsiString Comm=CmdLine;
if(Comm.Length>0){
//do stuff
}
else{
//don't bother
}

This just worked for me - BTW, how are you getting the CmdLine data to the form?
DJL

A salesman is a machine for turning coke into obnoxious arrogance.

Common sense is what tells you the world is flat.

 
I´m just using CmdLine as a parameter to a function.


void DoSomething(String); //function's declaration

AnsiString Comm=CmdLine;
if(Comm.Length>0){
DoSomething(Comm);
}
 
I'm sorry, I wasn't very clear. The command line string returned is not just the parameters. It is the entire command line. You must then parse it with your own code. You should just parse it by spaces. Then check to see how many different strings were returned. The first string will always be the name and path of the program you are running (hence why it is never null). The parameters will be strings after that.

You should have been able to breakpoint on the winmain function and read the command line being passed in and see this. I'd recommend that just to convince yourself anyway.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top