[System.Runtime.InteropServices.DllImport( "user32.dll" )]
public static extern void BringWindowToTop( IntPtr hWnd );
[System.Runtime.InteropServices.DllImport( "user32.dll" )]
public static extern void SetForegroundWindow( IntPtr hWnd );
[System.Runtime.InteropServices.DllImport( "user32.dll" )]
public static extern IntPtr FindWindow( string lpClassName, string lpWindowName );
[System.Runtime.InteropServices.DllImport( "user32.dll" )]
public static extern IntPtr SendMessage( IntPtr hWnd, uint Msg, int wParam, int lParam );
[System.Runtime.InteropServices.DllImport( "user32.dll" )]
static extern bool ShowWindow( IntPtr hWnd, int nCmdShow );
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
bool isNew;
Mutex dup = new Mutex( true, "RunManager", out isNew );
if ( isNew )
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new Form1() );
dup.ReleaseMutex();
}
else
{
IntPtr wHandle = FindWindow( null, "RunManager" );
if(wHandle != IntPtr.Zero)
{
ShowWindow( wHandle, 1 );
BringWindowToTop( wHandle );
SetForegroundWindow( wHandle );
}
Application.Exit();
}
}