Link to home
Start Free TrialLog in
Avatar of henry3
henry3

asked on

How can application get multifiles at the same time?

HI,men
  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.
Avatar of jhance
jhance

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.
Avatar of henry3

ASKER

Hi,jhance
   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.
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

Avatar of henry3

ASKER

HI,Mike
   
   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.
>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....
Give mblas the points and take jhance's advice
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of henry3

ASKER

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.
Avatar of henry3

ASKER

I got it!