How to make an application opening files using DDE

My application is associated with a file type, when the user clicks on a file of this type my application starts and opens that file, if the user redo that, the application will start again resulting two instances of the application. That I want is an example or were I can find info on making my application communicating with explorer using DDE preventing that situation.
Also I want if the user clicks to another file, my program to be able to get the name of the file and open it in the same instance of my program. E.g. MS Word, if you click to open a word file from explorer and word is already running,
word will not run again, but will open the file in the same word instance.
Who is Participating?
JimBob091197Connect With a Mentor Commented:

This can (and should) be accomplished using the Registry.  Here's an example that will assign .txt files to your Text Editor, called TEd.exe (written in Delphi) in the directory C:\WhatEver.

1.  Create a .reg file with the following contents, and merge it (R-Click, Merge) with the Registry:  (The first line must be "REGEDIT4".)


Command="C:\WhatEver\TEd.exe /n"
@="Text Document"
@="C:\WhatEver\TEd.exe "%1%"
@="Open "%1""

A few notes about the above reg file:
a)  In the reg file, when you see @="..." the @ means that the value is the default value.  (In RegEdit you will often see (Default).  This is entered with the @ char.)

b)  I create a key "HKEY_CLASSES_ROOT\TextFile\Shell\Open"  This means that when a user right-clicks on a text file in Explorer, there will be an "Open" command on the menu.  You can add "Print", etc...

c)  Open the Registry Editor.  Go through the HKEY_CLASSES_ROOT section.  You will see all the different file types that have been registered with Win 95.  Each file type (e.g. ".txt") will have a corresponding description (e.g. TextFile).  That description will also be found in the registry.  E.g.  If the file type is .txt, you will find HKEY_CLASSES_ROOT\.txt with the default value = "TextFile", and you will thus also find HKEY_CLASSES_ROOT\TextFile.
Look around; have fun changing values!!  ;-)  Be careful!

2.  Now, in Delphi, do the following:

Put a TDdeServerConv component (on "System" tab) on main form.
Call it "System".  This is important.  Notice in the above registry file, the ddetopic is "System".  This MUST be the same as the component name, so in Delphi's Object Inspector, set the Name of this TDdeServerConv component to System.

In the OnExecuteMacro event of this component, add this code.  This will allow you to see what Explorer is sending to your app.  You can modify it to open the files, etc...

procedure TForm1.SystemExecuteMacro(Sender: TObject; Msg: TStrings);
  i: Integer;
  for i := 0 to Msg.Count - 1 do

Hope this helps you.

Create a mutex and when mutex already created switch to first instance
Sorry, may mutexes be global? should this work on both Win16 and Win32?
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Mutex only in Win32 , under Win16 check hInstance <>0
HarisIVAuthor Commented:
Thanks JimBob! Your answer is what I was looking for.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.