Loading external files directly into my app?

BlitzMax Forums/MaxGUI Module/Loading external files directly into my app?

Rex(Posted 2010) [#1]
Hey guys, I've made myself a simple app to make my life a little easier at work. was wondering if there was a way to make my files load in my app when I double click on them? I am only using one file extension.

I have associated my files with my app, and while double-clicking on them externally does execute my app, they dont actually load into it.

Any help appreciated. Thanks


xlsior(Posted 2010) [#2]
When the application launches, the file name will be passed as a command line parameter.

Your program would need to take a look at the parameters at launch, and if it detects a valid filename there it can pass it to your file load routines.

For a start, look at AppArgs$[]


Rex(Posted 2010) [#3]
Thanks for taking the time to reply. I looked into this suggested appargs$, and found it quite vague an un-helpful.

I searched for a few hours within the forums here and on the net for hours with little success of how to do this.

I'm not a very experienced coder and would be most grateful for a small working example of this. Peace


xlsior(Posted 2010) [#4]
very basic example:

AppArgs(0) contains the path + filename of your actual executable
AppArgs(1) contains the first parameter
AppArgs(2) contains the second parameter
AppArgs(3) contains the third parameter
etc.

AppArgs.length contains the number of total variables:
For Local t = 0 to AppaRgs.Length-1
   Print AppArgs(t)
next


Since you're trying to open a file by double-clicking:
If AppArgs.Length > 1 ' At least one parameter is present
    FileToOpen$ = AppArgs(1)   
end if
' You now have the path + name of a file to pass to your file loading routine


Do make sure that you have some error checking in your load routine as well, to ensure that the path and filename passed are actually valid and it's not just a manual parameter passed from the commandline or something (e.g. "/?")

Also: You can test the parameters when creating your program in the official IDE by going to Program -> Commandline, and entering your full file path + filename as a parameter there. (Make sure to put double quotes around it if there are any spaces in the name)
Then when you run your program, it can see the parameter right away and it will look like your double-clicked on one of your datafiles.


Rex(Posted 2010) [#5]
Mission accomplished.
This will come in handy for any projects in the future that might need that.

Thanks again.


degac(Posted 2010) [#6]
I've made for my applications a CLI 'interpreter' that can read the commands queue in the following format
MyApp.exe FILE=myfile.txt SEND=OFF COLOR=yes USER=admin

So I can change the order of the parames without future problems if I want to add another 'option' to my app (otherwise with AppPargs(1) I need to remember the position of every options... not very handy)