File associations

BlitzPlus Forums/BlitzPlus Programming/File associations

Cold Harbour(Posted 2006) [#1]
Hi,

If I do a clean install of Windows and then install Office, I can double click on a file called ‘kittens.doc’ and the file will be opened in Word. I haven’t myself told windows or Word what to do with a doc file - it just works.

My B+ app saves a file in .csw format. This is my own format that no other program can understand. I want users to me able to double click on these ‘CSW’ file (assuming no other program has already registered that extension) and my app runs and loads the .cws file.

The problem seems to be twofold.

1) How do I automatically get Windows to load my app when a user double clicks on a .cws file? I just want Windows to know what to do. I don’t want users to go through the ‘Open With’ procedure.

2) How do I pass this .cws file to my app to make it load the right file? My app knows how to load the file. I just need to tell it that it needs to load it.

This may be useful to other B+ programmers too.

Thanks for any help.


xlsior(Posted 2006) [#2]
If I do a clean install of Windows and then install Office, I can double click on a file called ‘kittens.doc’ and the file will be opened in Word. I haven’t myself told windows or Word what to do with a doc file - it just works.


You didn't, but Word itself did during the install.

There some info in the registry which states the application name, location, and sometimes some additional command line parameters.

In order to register your own extension automatically, you'll need to add the appropriate info to the registry yourself.

when you double-click on a file, windows will simply launch the application with the pre-defined parameters, which include the name of the file you clicked on. The program can see this info passed along as a command line parameter, through commandline$()

so... when you launch your app, have it look at commandline$() and you can find out if it received a file to load.

most of these programs will check upon startup if they are already running, and if so they'll just change the focus to the already running copy and quit themselves, rather than launching a 2nd copy. It can pass along info on loading the 2nd document through an API call to the other program.


Cold Harbour(Posted 2006) [#3]
Thanks xlsior.