Solved

How to make an application opening files using DDE

Posted on 1998-03-15
6
355 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:HarisIV
6 Comments
 
LVL 2

Expert Comment

by:Waldek
ID: 1360508
Create a mutex and when mutex already created switch to first instance
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1360509
Sorry, may mutexes be global? should this work on both Win16 and Win32?
0
 
LVL 2

Expert Comment

by:Waldek
ID: 1360510
Mutex only in Win32 , under Win16 check hInstance <>0
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:julio011597
ID: 1360511
Thanks.
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 210 total points
ID: 1360512
Hi

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".)

REGEDIT4

[HKEY_CLASSES_ROOT\.txt]
@="TextFile"
[HKEY_CLASSES_ROOT\.txt\ShellNew]
NullFile=""
Command="C:\WhatEver\TEd.exe /n"
[HKEY_CLASSES_ROOT\TextFile]
@="Text Document"
[HKEY_CLASSES_ROOT\TextFile\DefaultIcon]
@="C:\WhatEver\TEd.exe,1"
[HKEY_CLASSES_ROOT\TextFile\Shell\Open]
@="&Open"
[HKEY_CLASSES_ROOT\TextFile\Shell\Open\Command]
@="C:\WhatEver\TEd.exe "%1%"
[HKEY_CLASSES_ROOT\TextFile\Shell\Open\ddeexec]
@="Open "%1""
[HKEY_CLASSES_ROOT\TextFile\Shell\Open\ddeexec\Topic]
@="System"


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);
var
  i: Integer;
begin
  for i := 0 to Msg.Count - 1 do
    ShowMessage(Msg[i]);
end;


Hope this helps you.

Regards,
JB
0
 

Author Comment

by:HarisIV
ID: 1360513
Thanks JimBob! Your answer is what I was looking for.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

25 Experts available now in Live!

Get 1:1 Help Now