File extensions in Windows

  • Thread starter Thread starter Jane
  • Start date Start date
J

Jane

Is there a standard way that Windows programs open files? You know how
you can associate a file type with a program, by telling Windows to
always open a type with a program? Is the filename always passed as a
command line argument to the program? How does that work?

(I'm new to Windows programming and part of a program I'd like to write
involves opening a document with another program.)

Thanks.
 
Jane said:
Is there a standard way that Windows programs open files? You know how
you can associate a file type with a program, by telling Windows to
always open a type with a program? Is the filename always passed as a
command line argument to the program? How does that work?

(I'm new to Windows programming and part of a program I'd like to write
involves opening a document with another program.)

It usually is. Some applications, like MS Word for example, publish details
of the dynamic data exchange (DDE) transaction that a shell can use as well.
So, if the user clicks on a .doc file, the shell checks to see if the
associated application is running. If it is not, it checks the registry for
information on the associated application and the format of the command line
required by the process. Then it launches it. If the application is already
running, the shell sends a message to the application to open another
document in the context of the same application which often uses a multiple
document interface (MDI).

Some applications forgo the use of the DDE messages. They are smart enough
to know if a second (or subsequent) instance of itself is being started. In
that case, they send their command line parameters (typically the file name
and perhaps an option like "/print") via a convenient method (window message
etc) to the first instance and quickly exit.

Some other applications, like Notepad, simply make no provision for opening
multiple documents. With no DDE info in the registry, and no special
processing on the part of Notepad, what you get is a new instance of the
application for every document.

I have just scratched the surface of this topic. More detail is here:

http://msdn.microsoft.com/library/d...sics_extending/fileassociations/fileassoc.asp

though it is written from an operating system rather than .Net perspective.

If you need to launch an application programmatically check the docs for the
ProcessStartInfo class and its UseShellExecute property.

(Just by the way, ShellExecute is the name of the unmanaged function that
the shell and applications use to launch applications via an associated
file).

Regards,
Will
 
Back
Top