Computer Science Canada

[Tutorial]Arguments

Author:  I Smell Death [ Wed Apr 23, 2008 10:32 am ]
Post subject:  [Tutorial]Arguments

So you've created a program that can open files ,say .abcde files, if the program is running. Now you're wondering how to get it to launch the program and open the file if you double click on a .abcde file. Well for starters the Sys.Nargs will always return a value of 0. So forget about the Sys. commands to get this to work.

If i were to double click on test.doc, it would be like going into the command prompt and typing C:\.....\Word.exe C:\.....\test.doc
unfortunately turing doesn't understand this. To get around this problem we need to create a batch file that when run saves the C:\.....\test.doc in a third file, which the main program then looks for on start up.

To do this do the following:

Open Notepad and type the following lines

@echo OFF
echo %* >> temp.txt
C:\......\MainProgram.exe


line 2 saves the full path of test.abcde to a file called temp.txt
line 3 runs the main program

this file should then be saved (don't click on save as) as a .bat file in the same directory as the main program

Now we need to tell the pc what to do when a .abcde file is double clicked
You will need to come up with a name for that type of file. for example a .doc file is called a WordDocument.
open the command prompt and type the following

replace .abcde with your file extension
replace FileType with your file type
replace BatchFile.bat with the location of your batch file


ftype FileType=C:\.....\BatchFile.bat %1
assoc .abcde=FileType


now all that needs to be done is to tell the main program to look for a temp.txt file when it opens. if it finds it, read the path in it, open that file, and delete the temp.txt file. In order for this to work you must compile the main program into a single exe file.
!NOTE: the temp.txt file must be deleted or every time the program is run, it will open the file specified in the temp.txt file

I will post pics later on.


: