Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more: (untagged)
i created a Music Player in WPF.

i created a reg file to register my app as default , and added Open with "My App name" into right click on music files. but i still can`t get this work .also i want when user click on the music file , its open my app and play the music file in my app , how i can do that ?

Edit - i mean when i click on the music file it load my app , but not adding the music into my app list , and not playing it .

i have a trouble receiving the file, i don't know how , i just created that you can select folder to play contents , and select music file , and play music file throw url , or drag files and drop them into my app or my app playlist , but i don`t know how to receive files when use click on the music file ...
Posted
Updated 13-Jul-12 6:48am
v5
Comments
lewax00 13-Jul-12 12:18pm    
"i still can`t get this work" isn't very descriptive. How is it not working? Is it launching and crashing? If so, what's the error message? Is it not opening? Please add some more details (use "Improve question").
Ali Al-Masry 13-Jul-12 12:31pm    
i mean when i click on the music file it load my app , but not adding the music into my app list , and not playing it .
lewax00 13-Jul-12 12:37pm    
That helps narrow it down. How is your program expecting to receive the file? A command line argument with a path to the file, a stream on standard input, something else? Or are you having trouble figuring out how to receive the file?
Ali Al-Masry 13-Jul-12 12:48pm    
yes , i have a trouble receiving the file, i don't know how , i just created that you can select folder to play contents , and select music file , and play music file throw url , or drag files and drop them into my app or my app playlist , but i don`t know how to receive files when use click on the music file ...
Sergey Alexandrovich Kryukov 13-Jul-12 20:21pm    
"I don't know how" and "can't get it to work" is not informative. What exactly you could not do and why? The problem is pretty simple (but takes some attention to detail...).
--SA

Played around a bit with this, and it looks like Windows opens files that way by passing the file's path to the program as an argument. You can get the arguments in your program by accessing the arguments array of Program.Main, where you can either deal with it there, or pass it to the constructor of your form, and let the form handle it.

So in your case, I would suggest probably passing arguments to the main form of your application, seeing if there are any arguments being passed in, and open them as you normally would open a file in your program.

[Edit]
Forgot you were using WPF, that handles command line arguments a little differently, but this[^] has an example of how to handle them in WPF apps.
 
Share this answer
 
v2
Comments
Ali Al-Masry 13-Jul-12 13:04pm    
So , can you show me an example ?
lewax00 13-Jul-12 13:15pm    
Added a link with an example to the answer.
Ali Al-Masry 13-Jul-12 13:19pm    
Thanks Dear , i`ll check it and i`ll reply you here then.
Sergey Alexandrovich Kryukov 13-Jul-12 20:25pm    
Correct, my 5. To add to it, I provided a link to my library to work with command line arguments, please see.
--SA
In addition to the correct answer by lexwax00:

You can use my library to process command line arguments. It is especially easy to use and is provided in a source code for this CodeProject article:
Enumeration-based Command Line Utility[^].

—SA
 
Share this answer
 
Comments
lewax00 13-Jul-12 21:28pm    
That looks a lot more useful than the example I found, +5
Sergey Alexandrovich Kryukov 13-Jul-12 23:03pm    
Thank you. Another aspect is register the application for "Open", "Open with" by file type, etc. This is easy to find out; you correctly explained the basic idea.
--SA
Ali Al-Masry 13-Jul-12 23:04pm    
i am still trying to understand your example , and how it can help me ...
Ali Al-Masry 14-Jul-12 13:24pm    
Hello People, this dose n`t help me out.
i am trying this

http://mel-green.com/2009/04/c-set-file-type-association/

but still won`t work for me .... what steps shall i do ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900