Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dropping a file onto an applications icon

Posted on 1998-04-29
7
Medium Priority
?
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

Industry Leaders: 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!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

688 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