Link to home
Start Free TrialLog in
Avatar of tdubroff
tdubroff

asked on

Dropping a file onto an applications icon

I would like it so that I can drop a file onto my application's icon and then the application would start up with information gleaned from the file.  I'm using MS VC++ 5.0 and have experimented with the WM_DROPFILES message, but that only appears to work once the application has already started.  Any help would be appreciated.
Avatar of MikeABB
MikeABB

You have to accept command line arguments in your application to be able to accept a file that is dropped on your icon.  Your main routine should look something like this:

void main(int argc, char* argv[])
{
   //argc is the argument count
   if (argc > 1)
      //read in your file whose name is in argv[1]
      //or do whatever file manipulation you are doing
      ReadFile( argv[1] );
   //put the rest of your main subroutine in here
}
Avatar of tdubroff

ASKER

You get command line args automatically with an AppWizard generated application.

Ronslow, can you be a little more specific?  I have a global application called The App that runs my modal dialog box.  Where do I insert the use of command-line arguments?  I have put an OnDropFiles(HDROP hDrop) message handler in both The App and my dialog box, but that only accepts dropped files after the application has started up.
Include this code in your application's InitInstance

      CCommandLineInfo cmdInfo;
      ParseCommandLine(cmdInfo);

Then look at cmdInfo to determine what to do with the file

ASKER CERTIFIED SOLUTION
Avatar of RONSLOW
RONSLOW

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
Thanks for the help Ronslow.  I got it working.
Glad to help