Frequently Asked Questions

Associating a file extension with your PC application

Question:

How do I associate a file extension with my mProjector application on the PC -- i.e. launch my app when a user double-clicks a file of a certain type?

Answer:

PART I -- Associating a file extension with your application

Here is the code we use to associate an ".mproj" file with mProjector.

Code:

mRegistry.setValue("HKEY_CLASSES_ROOT\. mproj", "", "mProjector Project"); 
mRegistry.setValue("HKEY_CLASSES_ROOT\mProjector Project", "", "mProjector"); 
mRegistry.setValue("HKEY_CLASSES_ROOT\mProjector Project\shell\open\command", "", mApplication.getArguments()[0]+" %1");


The first line tells Windows a file with an ". mproj" extension is an mProjector project file.

The second line associates mProjector project files with the application named "mProjector".

The third line defines the DOS command Windows OS runs when the user double-clicks an mProjector project file. The value in this registry key, the second param, is the path to the application exe file + " %1". Running this command will launch the application with the path to the mProjector project file as it's first argument.

The effective DOS command might look like this:
"C:\Program Files\mProjector v4\Projector.exe" " C:\project_file.mpr"

You can check your Registry changes using the Windows utility "RegEdit". To run RegEdit, click the "Start" button, select the "Run..." menu item, type "regedit" in the text box, click "Open", and navigate to your registry key.

Before creating your file association you will want to check what other applications use the extension. There are a bunch of websites that list know file associations. Here is one: http://www.fileinfo.net/

A word of warning... anytime you mess with the Registry you can really screw up your computer. Make your changes carefully.

PART II -- What to do when your app is launched by an associated file.

Your application will need code to handle being launched by an associated file. The code will verify it's been launched by an associated file then load the file into your application.

The key mProjector command for this code is mApplication.getArguments() returns the array of command line arguments that launched the application.

The [0]th argument returned by mApplication.getArguments() is the full path to the exe. You get this anytime the application is launched -- whether the user double-clicks the exe or an associated file. Notice I used this value in the mRegistry.setValue() command in Part I to set the path to mProjector.

A good arguments[1] value will be the full path to the project file. When mProjector runs, it checks to see if it has a good project file, and when it finds one, it loads the project. If arguments[1] is undefined, mProjector launches using it's default settings.

Code:
var arguments:Array = mApplication.getArguments(); 
var initProjectFilePath:String = arguments[1]; 
var foundProjectFile:Boolean = isThisAGoodProjectFile(initProjectFilePath); 
if (foundProjectFile) { 
	loadProject(initProjectFilePath); 
} else { 
	loadDefaultSettings(); 
}

 

 

If you have additional questions or have ideas on how to improve an FAQ, contact us. Please include a link to the FAQ in your email.