Application Entry Point

dotnetgirl

Freshman
Joined
Oct 14, 2003
Messages
26
Location
India
Hello All,

Can anybody tell me how the word document for example opens in MS-word on double clicking the document in explorer. How this file type association is done with corresponding editor. i want to do it in Vb.Net or C#.

Any clues?

Thanks.
 
It uses the [api]ShellExecute[/api] API function, but .NET can do it with Process.Start. The file associations are stored in the registry under HKEY_CLASSES_ROOT I think.
 
Yeah,
i know that Process.start can help us to start a perticular process in an event. I can say that my question is more related with file type association with that application. How will i come to know that on clicking a file, i have to open this application and run the openDocument function from it, for example.
Inside the openDocument function, i can handle the process and start an instance of the child window.
But before that how can i associate the document and application?
Can u focus more on this?
 
Its all down to the registry. Let's imagine you wish to register a file type called MyApp Document with the .xyz extension. First create the following key:

HKEY_CLASSES_ROOT\MyApp.Document\Shell\Open\Command

In this key you place the command-line statement you wish to be executed when a file of type MyApp.Document is opened. The variable %1 denotes the filename. Some example values might be:

C:\Program Files\MyDir\MyApp.exe %1
C:\Program Files\MyDir\MyApp.exe "%1"
C:\Program Files\MyDir\MyApp.exe OPEN "%1"

Next, you need to associate the extension .xyz with MyApp.Document. You do this by creating the following key:

HKEY_CLASSES_ROOT\.xyz

In this key set the value to MyApp.Document. This completes the file association process. To associate an icon with your file, create the following key:

HKEY_CLASSES_ROOT\MyApp.Document\DefaultIcon

In this key place the full path and name of the module (EXE or DLL) which contains the icon followed by a comma and then the resource index of the icon you wish to use within the module.
 
Thanks Squirm!

now i ve clear idea. I shall try it out.

Now my next question is, once a file type is asssociated with a perticular application, how to pass that document as a parameter so that the application is run to execute open function to open that perticular document. Means .Net, how to go about it?

Thanks.
:)
 
The name of the file is automatically passed to your program. You can retrieve command line arguments like this:
Visual Basic:
'to get the command line separated
System.Environment.GetCommandLineArgs()
'to get the whole command line as one string
System.Environment.CommandLine()
 
Back
Top