Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dropping a file onto an applications icon

Posted on 1998-04-29
7
Medium Priority
?
224 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 400 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

877 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