Single Application Instance + Loading New Files

A

Anthony

Hi, all --

I've seen several very good articles which discuss how to make a single instance Windows Form and even how to give an existing instance of the application the focus. This question takes the issue to the next level. Here's the requirement, for which I can't find any samples or instructions online:

One instance of MyApp.exe is already running. I minimize the application and double click on a file on the Desktop whose file type, .my, is associated with MyApp.exe. Then not only does MyApp get maximized but it ALSO loads the contents of the clicked-on file. The second part of that sentence is missing in all of the samples I've seen so far.

For simplicity sake, imagine that MyApp.exe is an MDI-based application and that each MDI child form hosts a single RTF control. So, each file contains basic RTF text information and its file type is .my.

Any advice or links to existing articles would be greatly appreciated!

Cheers,
Anthony


P.S. --
Thanks to several folks who offer good info on basic single-instance application coding:

- iDesign.net
- Pedro Silva on DevHood
- Bob Powell
 
W

Wiktor Zychla

One instance of MyApp.exe is already running. I minimize the application
and double click on a file on the Desktop whose file type, .my, is
associated with MyApp.exe. Then not only does MyApp get maximized but it
ALSO loads the contents of the clicked-on file. The second part of that
sentence is missing in all of the samples I've seen so far.
For simplicity sake, imagine that MyApp.exe is an MDI-based application
and that each MDI child form hosts a single RTF control. So, each file
contains basic RTF text information and its file type is .my.

at first you should register your own file extension. there are many
examples on how to do that (the first one from google:
http://www.delphi32.com/info_facts/faq/faq_551.asp).

note that when the user clicks the file, the new instance of the application
comes up and tries to load the file. you have to make sure that the new
instance will somehow pass the file info to the existing instance and exit
so that the first instance would handle the file.

passing messages between instances is another topic. you can somehow use
System.Messaging namespace or you can use an old Win32 trick: use
SendMessage with HWND_BROADCAST to broadcast messages between open windows
(you can handle messages by overriding WndProc). the latter technique should
be rather easy to implement.

Regards,
Wiktor Zychla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top