Solved

Dropping a file onto an applications icon

Posted on 1998-04-29
7
203 Views
Last Modified: 2011-08-18
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.
0
Comment
Question by:tdubroff
  • 3
  • 3
7 Comments
 

Expert Comment

by:MikeABB
ID: 1167389
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
}
0
 
LVL 2

Author Comment

by:tdubroff
ID: 1167390
You get command line args automatically with an AppWizard generated application.

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1167391
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:tdubroff
ID: 1167392
Include this code in your application's InitInstance

      CCommandLineInfo cmdInfo;
      ParseCommandLine(cmdInfo);

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

0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1167393
SDI and MDI apps already have thie code .. They then call ProcessShellCommand which interprets the command line and sends commands like ID_FILE_NEW etc.  Ida dialog app, you (probably) don't want this last step .. you can check m_nShellCommand for the type of command line given (FileNew is no file dropped, FileOpen is a file was dropped etc).

This can also be used when your app is associated with a file type .. so double clicking on the file will launch your app with the filename as a command line arg, and the m_nShellCommand will be FileOpen and m_strFileName will be the name.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1167394
Thanks for the help Ronslow.  I got it working.
0
 
LVL 2

Author Comment

by:tdubroff
ID: 1167395
Glad to help

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now