Single instance behaviour like Messenger and Outlook

  • Thread starter Thread starter Stephen Inkpen
  • Start date Start date
S

Stephen Inkpen

I am trying to duplicate the single instance behaviour of Messenger
and Outlook. When the 'X' is pressed, the applications minimize to the
system tray. They can then be brought to the foreground either by
running the program from the start menu or by double-clicking the icon
in the system tray.

I've looked at various ways of attempting to accomplish the same
behaviour but have not found one I particularly like. If anyone has
any ideas other than the ones I mention below please send them along.
Also, if there is anyone who knows how Messenger or Outlook does it,
that solution would be gold.

1. Get MainWindowHandle from process object. Unfortuneatly, the window
is hidden so this value returns 0.

2. Iterate through all the Windows in the system, matching the text.
Didn't have much luck but I really didn't think that was a very
elegant way of doing it anyways... specially since my window label may
change.

3. Client/Service socket. If the application is already running
(Mutex) then connect to the server (first instance) and tell it to
restore itself. This is doable but seems to be overkill.

4. Remoting. Same as 3 but also seems to be overkill just to restore
the initial application.

I would really like to know how Messenger or Outlook does it as their
method does seem to work quite well and has been tested extensively.

Thanks,

Stephen Inkpen
 
One possible way would be to create a service which until you actually "EXIT"
the program, the service will continue to run. The GUI would then be an
extension of the service, so even if you closed it, it would not stop the
service.
 
=?Utf-8?B?RGFpc3VrZQ==?= said:
One possible way would be to create a service which until you actually "EXIT"
the program, the service will continue to run. The GUI would then be an
extension of the service, so even if you closed it, it would not stop the
service.

This is true but I'm also trying to avoid the startup costs associated
with the GUI application as well.

Stephen
 
Back
Top