Hi Susan
There are two separated issues in your post, how to detect that a previous
instance is running and how to send a message to another windows to make it
the foremost window.
1- Detect a previous instance:
You can use several techniques, basically ALL of them involve the creation
of a unique object, you can use a Mutex for example, or search by process
name. if you do a search in the archives of this NG you will find several
suggestions as this is an issue that is constantly asked.
2- All you need is the handle of the main windows of the other isntance, you
get it using Process.MainWindowHandle
Here is some code I have used
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
//yyou need this namespace
using System.Runtime.InteropServices;
// P/invoke declarations
public class Form1 : System.Windows.Forms.Form
{
//I search by process name
static public Process FindParallelProcess()
{
string currentprocname = Process.GetCurrentProcess().ProcessName;
foreach( Process process in Process.GetProcessesByName(
currentprocname) )
{
if ( process.Id != Process.GetCurrentProcess().Id )
return process;
}
return null;
}
[DllImport("user32.dll",EntryPoint="SetForegroundWi ndow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
//Detection
static void Main()
{
Process previous = Form1.FindParallelProcess();
if ( previous == null )
Application.Run(new Form1());
else
{
//Give the focus to the other instance
SetForegroundWindow( previous.MainWindowHandle);
}
}
"Susan" <an*******@discussions.microsoft.com> wrote in message
news:FB**********************************@microsof t.com...
I have an application. When a user minimizes it it hides itselfs but
stays activate in the system tray. Since it is hidden the user may think
that they have exited the application and now may attempt to create a new
instance by launching the program again. The problem that I am running into
is being able to restore the previous application. I am able to end the
multiple instance application but since the previous application is hidden I
cannot find a way to 'show' previous application. Any suggestions? I need an answer fast.