How can application get multifiles at the same time?

Posted on 1999-12-17
Medium Priority
Last Modified: 2010-04-01
  Could I ask you some qestions about VC++ programing?
  In fact, I wanna get the work out that when draging
some files to my application, it can get these filenames
into string buffers. I know Winamp(MP3 player) can do
this. For examples, when you choose a lot of mp3 files
and press "ENTER", winamp will play them one by one
( Of course *.MP3 file should open with winamp )
Apparently, winamp get all of them. But some application
can get only one object file.
  How can I do it?
  Looking forward your suggestion.
Question by:henry3
  • 4
  • 2
  • 2
  • +1
LVL 32

Expert Comment

ID: 2289863
See the SDK docs for DragQueryFile().

When an application receives a WM_DROPFILE message, all the files that are dropped are available via the DragQueryFile() API.  Many applications are "lazy" and don't check to see if more than one file has been dropped.

It's up to the application (i.e. the programmer) to determine how to handle or ignore multiple dropped files.

Author Comment

ID: 2292949
   Thanks for your advice.
   But you may not understand my purpose exactly.
   WM_DROPFILES can only get the files that you dragto the application window. In fact, I hope thatwhen you drag some files to your unruned application,
it will be active automatically, and get them.
   May be I don't express my Qestion exactly. But
How can I get the above purpose?
   After all, your answer is helpful.
LVL 11

Expert Comment

ID: 2293916
When you have a shortcut on the desktop and the user drags files onto you, Windows starts your application with the file names each as separate arguments to the command line.  If the user selects 1.DAT, 2.DAT, BIG.DAT, and SMALL.DAT, then drags those files to your shortcut on the command line, you'll get each of the files on the command line as a separate argument.

Verify it for yourself with this minimal app:

-- begin file arglist.cpp --

#include <windows.h>
#include <string.h>

#pragma comment(lib, "user32.lib")

void main(int argc, char* argv[])
   char sz[10240];
   sz[0] = 0;

   int n;
   for (n = 0; n < argc; n++)
      strcat(sz, argv[n]);
      strcat(sz, "\r\n");

   MessageBox(NULL, sz, "Dang activated!", MB_OK);

-- end file arglist.cpp --

1) Build it
2) Create a shortcut to the EXE on your desktop
3) Start explorer
4) select some files
5) Drag 'em to the icon for the shortcut you created
6) Observe the message box.

..B ekiM

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Author Comment

ID: 2294025
   Thanks for your advice.
   Your anwser really can get that result.
But I don't make a ANSI C program. I wanna
a win32 VC++ program. So I don't think it is
the method I want. And anything else?
   Looking forward your suggestion.
LVL 32

Expert Comment

ID: 2294492
>But I don't make a ANSI C program. I
>wanna a win32 VC++ program

What are you talking about?  VC++ _IS_ an ANSI C compiler!  If you mean that you are writing a Windows GUI app and not a command line app with a main() function, the technique is still valid.

Why don't you open the SDK docs to GetCommandLine()?  Better yet, why don't you get a basic Windows programming book.  A good starting point might be Petzold's "Programming Windows" text.  

It seems to me that you don't even know enough about this subject to ask a good question, much less write some sort of MP3 application....

Expert Comment

ID: 2295187
Give mblas the points and take jhance's advice
LVL 11

Accepted Solution

mikeblas earned 80 total points
ID: 2295432
The above app _is_ a Win32 app.  I guess you mean that you want something that works as a Windows application.  That's fine, we can do that, too.

1) Start VC++.
2) Ask for an MFC AppWizard (exe) application
3) Call it Foo.
4) Ask for a Dialog-based application
5) Accept all the rest of the defaults.
6) Add these lines to the CFooDlg::OnInitDialog() function. You should add them right under the comment that says "TODO: Add extra initiailzation here"

   CListBox* pBox = (CListBox*) GetDlgItem(IDC_LIST1);

   int n;
   for (n = 0; n < __argc; n++)

7) Edit the IDD_FOO_DIALOG resource in your app.
8) Delete the "TODO" text in the middle of the dialog.
9) Drop a nice big list box control in the middle of the box.
10) Build the app.

Then, you can follow the same instructions I gave before to place this guy on your desktop. It'll work just the same, except you'll see that you can still just pick the filenames off the command line.

..B ekiM

Author Comment

ID: 2296826
To Mikeblas:
   Thanks for your advice.
   I got what I want.
   I have some C and C++(DOS) program EXP,
but I turn to Windows Programming recently.
So I'll face to many qestions with VC++.
   In fact, I mean that I don't make a
command line app with a main() function
as jhance said. So, the "_argc" and "_argv[]
is just what I need.
To jhance:
   I think that practice is the best way to
study program, instead of handbook-swallowing.
   So,please take all of your sarcasm back.
If you think the qestion is too simple, you
should ignore it.
   Although you are the expert of the week,
I think I'll be better than you someday.  
   And maybe you have super skill, but as a guide
Mike is much more qualified than you.

Author Comment

ID: 2296829
I got it!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…
Suggested Courses

588 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