[RESOLVED] [2008] Associate windows with my application
Hi!
How would i do to get the regkey from my program and then register it into the windows key register so that users can select Open With... [MyApplication]?
And this brings me to another question, how can i get the data from a file if someone opens my program with a file (Open With...)?
Or else maybe how can i get the path to the file which opened my program so that i can retrieve the data from the file?
I hope im clear enough, if you have any questions, ask me.
Thanks in advance,
//Zeelia
Re: [2008] Associate windows with my application
I'm not sure about the "Open With" option but to get the data from a file when a user opens the file with your program through explorer (either through Open With or by double clicking on a file that has a file extension that is associated with your program) you can use the first argument that is passed to your program in the My.Application.CommandLineArgs array to find out the full path of the file. So in your form load you could check to see if any such path was passed in and if so then process the file however you want to now that you have its full path
Re: [2008] Associate windows with my application
Okay great, im gonna try that out tomorrow (, kinda late atm).
Thanks!
*EDIT*
Okay so i can't sleep so i tried it out:
'Try to see if myapp was opened from a file
Dim i As Integer, s As String
For i = 0 To My.Application.CommandLineArgs.Count - 1
s = My.Application.CommandLineArgs.Item(i)
MsgBox(s)
Next
and that works but my problem is that if i open more lets say 5 files, it just msgbox:es one of the files and i want to get all of the files, any idea?
Re: [2008] Associate windows with my application
What you mean if you select multiple files in Explorer and then do Open With (or double click)?
Re: [2008] Associate windows with my application
if i do open with, since i haven't associated my program with the files as default since they are MP3 files, i'd like to use WMP as default.
But is double clicking the only way to open multiple files?
Re: [2008] Associate windows with my application
No you can open multiple files by selecting them in explorer (by holding Ctrl or Shift) and then right clicking on one of the items and going to Open With.
What happens when you do that?
Re: [2008] Associate windows with my application
Well when i do that, only one of the files is opened (the file which is on the top, viewing from a (detailed) list in explorer)
My program is a music player which uses its own playlist files and when i select 2 playlist files and click 'enter' two instances of my program opens.
So what could be wrong?
//Zeelia
Re: [2008] Associate windows with my application
Well you remember I said the CommandLineArgs property was an array? Well, if you open more than one file at once that should open in your app (or use Open With) then for every extra file path you get an extra entry in your array :)
So for example if I wanted to add the path of each file that was passed to my program into TextBox1 I could do this in my Form_Load event:
vb Code:
For Each filepath As String In My.Application.CommandLineArgs
TextBox1.AppendText(filepath)
Next
That help?
Re: [2008] Associate windows with my application
Not really, i tried that aswell, i got the same result.
:S Im starting thinking that the problem doesn't have anything with this to do...
I've tried the For Each and the For functions but none of them did the complete work.
But what if i'd take a roundabout way :P
What if i create an array which will store all the args and then from the array do something like for each entry in array { msgbox(entry.ToString) }.
That's like the same thing just that i assign the CommandLineArgs array into a variable-array... could that work or would that just give the same result?
//Thanks
Re: [2008] Associate windows with my application
I cant see why that would be any different.
I dont know what to say, it works perfectly fine for me when I select multiple files and use that code that I posted above...
Create a test project and just use that code I posted to see if you can at least get it to add the file paths to a textbox. Let me know how that goes.
Re: [2008] Associate windows with my application
Yes i will try that out, maybe its just my computer which is messed up (even though i re-installed windows recently)
I'll edit this post later with the results
*EDIT*
Yes, my new project had no problems opening multiple files...
I'll check out my code, maybe i've written something that stops the loop.
**EDIT*
Ok now i found out the problem, the issue was all the time that i had some code before the loop which i think in some way canceled the loop and just ran the code inside the loop, strangely.
But now everything works.
Thanks!
//Zeelia
Re: [2008] Associate windows with my application
Glad to hear it :) mark the thread as Resolved if everything is sorted now (use the Thread Tools menu at the top of your first post in this thread)