Solved

Dropping a file onto an applications icon

Posted on 1998-04-29
7
202 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

12 Experts available now in Live!

Get 1:1 Help Now