|
-
Dec 1st, 2008, 03:45 PM
#1
Thread Starter
Fanatic Member
[2008] Open with multiple arguments
Hi!!
If you select many MP3 files and press enter, and the default program to open the MP3 files is windows media player. It opens windows media player with all the files in the playlist "Now Playing".
How can I do so that my program acts the same, but just adds the filenames to a Listbox?
I have this code but it doesnt work, well works but just for a single file:
vb.net Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If My.Application.CommandLineArgs.Count > 0 Then
For a As Integer = 0 To My.Application.CommandLineArgs.Count - 1
Dim FI As New IO.FileInfo(My.Application.CommandLineArgs(a))
If FI.Extension.ToUpper = ".MP3" Then
Listbox1.Items.Add(IO.Path.GetFileNameWithoutExtension(My.Application.CommandLineArgs(a)))
End If
Next
End If
End Sub
-
Dec 1st, 2008, 04:21 PM
#2
Re: [2008] Open with multiple arguments
Not sure why that doesn't work. Did you debug to see what the arguments actually are?
-
Dec 1st, 2008, 06:57 PM
#3
Junior Member
Re: [2008] Open with multiple arguments
I tested your code on my compiler (VB 2005 expressed) and it seamed to work as expected. Double check what command line arguments are being passed by the calling application. In order for the code to work properly the arguments should be space seperated.
-
Dec 1st, 2008, 07:14 PM
#4
Re: [2008] Open with multiple arguments
in 2008 i did this
Code:
If My.Application.CommandLineArgs.Count > 0 Then
For cla As Integer = 0 To My.Application.CommandLineArgs.Count - 1
Debug.WriteLine(My.Application.CommandLineArgs.Item(cla))
Next
End If
worked as expected.
i did find that i had an error trying to access the command line arguments with:
Enable ClickOnce Security - Checked
This is a Full Trust Application - Selected.
-
Dec 2nd, 2008, 09:17 AM
#5
Thread Starter
Fanatic Member
Re: [2008] Open with multiple arguments
Well it works but opens me a lot of instances of my program, with a file in the listbox in each program, instead of one and only instance with all the files in the listbox. I've try to make it a single instance application and still only adds a file to the listbox.
-
Dec 2nd, 2008, 10:29 AM
#6
Re: [2008] Open with multiple arguments
You have probably set the file attributes wrongly. I cannot help you how to set them properly, but it seems to me that windows now sees the file as being opened only once at a time. So what it does is open a new instance of your application for each selected file.
The same happens for example with Notepad: try creating a few .txt files with notepad on your desktop, select them all and press Enter. All the files are opened in a separate instance of Notepad.
What you want is that windows opens only one instance of your app with the selected files as separate commandline args.
So this is certainly an error in the way windows handles the opening of multiple files, not in the way your application handles the commandline args.
-
Dec 2nd, 2008, 10:54 AM
#7
Re: [2008] Open with multiple arguments
 Originally Posted by Lasering
If you select many MP3 files and press enter, and the default program to open the MP3 files is windows media player. It opens windows media player with all the files in the playlist "Now Playing".
I understand the problem now! What you're trying to do won't work with traditional command line arguments as each time a file is opened Explorer goes to the specified application and passes the path of the file into it.
So in your current application you'll get a ton of instances.
So if you want your current code to work you have to highlight all of your MP3s and drag them onto your executable / shortcut or add each path of each MP3 manually to either the command line or run box for your application.
If you want your application to work like Windows Media Player then you'll need to setup a single instance application. In VB2005 / VS2008 there is a checkbox somewhere in your project's properties that says "make single instance" or something to that effect. Then everytime a new instance of your application attempts to open, instead, you'll have an event thrown with the appropriate command line arguments so you can keep adding things to your listbox.
 Originally Posted by NickThissen
So this is certainly an error in the way windows handles the opening of multiple files, not in the way your application handles the commandline args.
It has nothing to do with the way Windows handles opening multiple files. Windows doesn't do that. This has to do with what the OP's application is doing when Windows sends commands to it.
-
Dec 4th, 2008, 04:06 PM
#8
Thread Starter
Fanatic Member
Re: [2008] Open with multiple arguments
 Originally Posted by kasracer
Then everytime a new instance of your application attempts to open, instead, you'll have an event thrown with the appropriate command line arguments so you can keep adding things to your listbox.
I've already checked the make single instance option.
Which event do I have to check now?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|