Run a Blitz3D .exe by clicking on a data file?

Blitz3D Forums/Blitz3D Programming/Run a Blitz3D .exe by clicking on a data file?

Cold Storage(Posted 2010) [#1]
Many programs can run by being associated with a file type.

Is it possible to do this in Blitz 3D?

Here's a (naff) but simple example;

You write a simple text editor in Blitz3D called b3dtext.exe which writes out files with the extension .b3t

The user associated .b3t files with b3dtext.exe.

The user double-clicks on a .b3t file which causes b3dtext.exe to run, and also opens the file.

Thanks in advance for any help... ;O)

P.S.
How would you automate the process of associating .b3t files with b3dtext.exe? I'm guessing this is something your installation program should do in the registry? Then of course there's the thorny topic of if it's done one way in WinXP how is this done for Vista / Win7.


xlsior(Posted 2010) [#2]
I'm pretty sure that Windows has an API to create a file association, which should work the same on all versions of windows.

The file association itself would specify the name of the executable, plus the necessary parameters that get passed when one double-clicks on the file.
One of those parameters is normally %1, which indicates the name of the file you clicked on.


Kryzon(Posted 2010) [#3]
This is definitely more related to Windows internals than B3D. You should focus your study in that.

Try reading this: http://technet.microsoft.com/en-us/library/cc749986(printer).aspx

It explains how things work with the registry. If you can add that to the registry (any good Setup Maker application allows you to add things to the registry), you can make your application be associated with a certain filetype.

Of course, always ask the user before doing anything, and always put the choice as "off" to begin with.


Zethrax(Posted 2010) [#4]
I'm not sure how you set file associations programmatically, but you can do it manually by right clicking on the data file, clicking on the 'Properties' menu option, and then by using the Properties window to change which program is set to open files with that file extension.

The Blitz3D program should use the CommandLine$() function to get the path to the file to be opened (which will probably be surrounded by quotes, which you will need to remove).

eg. filepath$ = Replace$(CommandLine$(), chr(34), "")

Apparently you use the registry to programmatically set file associations.

INFO: http://support.microsoft.com/kb/122787 (Scroll down to 'Using a Program to Set File Associations'.)


Serpent(Posted 2010) [#5]
Bill is right. File associations are held in the registry - u'll need to use userlibs to modify registry values and add your '.b3t' files to the list. Then, yes, it should be a simple CommandLine$() to get the path of the file that was 'opened'.


Warner(Posted 2010) [#6]
Maybe it is possible to use innosetup&istool to associate files? Probably it is best if an installer performs the file associations.


Cold Storage(Posted 2010) [#7]
Thanks guys!

I'll see if I can get it working... ;O)