Solved

Launch an app from its document-How?

Posted on 1997-08-03
2
160 Views
Last Modified: 2010-04-04
Hi,
  Could someone please explain to me how to execute an application by double-clicking on a document file it created. The launched application should then open the document file. In other words, what do I need to do to link a program and its documents so that I can open the document in Windows file manager by double-clicking on the document's icon? This seems to be a standard with Windows applications, but I can't find any info on how to do it with Delphi (I'm using D1)Any help would be greatly appreciated.

Regards,

James Chen
cgcsci@aol.com
0
Comment
Question by:jjchen
2 Comments
 

Accepted Solution

by:
iainmagee earned 100 total points
ID: 1340399
In win95 or NT4 file associations are stored in the registry. If your program has limited circulation, then the simplest (and safest!) way of registering your data type is by adding the details manually in Explorer. To do this you just select 'Options' from the 'View' menu in Explorer, then select the 'File types' tab. You can then use 'New Type' button to create a new association type and link it to your application.

However if you're distributing your software on a larger scale and have an installation routine, then it will be necessary to have the installation automatically add the relevant details to the registry. The MSDN gives two ways of doing this. The following extract is what it says:


----------------->>>>>>>>>>>>>>>>>>>>>>>>>>> From MSDN

You can also set the associations programmatically. This is useful when setting up your application on other machines. You would provide this functionality through your installation program. The first way to do this (the simplier method) is to use regedit to merge the changes from a file. The syntax for this is:

   regedit <filename>.reg



An example of a <filename>.reg is:

   REGEDIT
   HKEY_CLASSES_ROOT\.riy = FMA000_File_assoc
   HKEY_CLASSES_ROOT\FMA000_File_assoc = File_assoc
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\command = fileasso.EXE
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec = [Open(%1)]
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\application
= Myserver
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\topic = system
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\command = fileasso.EXE
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec = [Open(%1)]


HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec\application = MYServer
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec\topic = System
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec\ifexec =


[Test(%1)


]


In the program, you can also add keys to the registry by using the registry APIs. The developer needs to add the following keys to the registration database:

   // Your extensions.
   HKEY_CLASSES_ROOT\.riy = FMA000_File_assoc

   //File type name.
   HKEY_CLASSES_ROOT\FMA000_File_assoc = File_assoc

   // Command to execute when application is not running or dde is not
   // present and Open command is issued.
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\command = fileasso.EXE

   // DDE execute statement for Open.
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec = [Open(%1)]

   // The server name your application responds to.
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\application =
   Myserver

   // Topic name your application responds to.
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\topic = system

   // Command to execute when application is not running or dde is not
   // present and print command is issued.
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\command = fileasso.EXE

   // DDE execute statement for Print.
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec = [Open(%1)]

   // The server name your application responds to.
   HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec\application =
   MYServer

   // Topic name your application responds to.
   HKEY_CLASSES_ROOT\FMA000_File assoc\shell\print\ddeexec\topic = System

   // DDE execute statement for print if the application is not already
   // running. This gives the options for a an application to Run, Print
   // and Exit.
   HKEY_CLASSES_ROOT\FMA000_File assoc\shell\print\ddeexec\ifexec =
   [Test(%1)]



REFERENCES
Windows SDK Programmers Reference, Volume 1, chapter 7, Shell Library or Books Online.
Window 3.1 SDK Help file, Registration Database, Shell Library Functions.
Win32 Programmers Reference, Volume 2, chapter 52, Registry and Initialization Files or Books Online.


------------------------

I have to admit this looks a little daunting, but my money's on the 2nd method - it seems the most straightforward, though I haven't really tested either method in a production environment.

Hope this helps, and your registry survives ;-)

Iain.
0
 

Author Comment

by:jjchen
ID: 1340400
Iain,
  Thanks for your help. This will get me started, although there might be more to it to have it completely working for me.

James
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now