//关闭当前程序,显示已打开程序
private void App_Startup( object sender, StartupEventArgs e )
{
var current_process = Process.GetCurrentProcess( );
var other_process = Process.GetProcessesByName( current_process.ProcessName ).FirstOrDefault( p => p.Id != current_process.Id );
if( other_process != null && other_process.MainWindowHandle != IntPtr.Zero )
{
if( IsIconic( other_process.MainWindowHandle ) )
{
ShowWindow( other_process.MainWindowHandle, SW_RESTORE );
}
SetForegroundWindow( other_process.MainWindowHandle );
Shutdown( );
}
}
//是否窗口最小化
[DllImport( "user32" )]
static extern bool IsIconic( IntPtr hWnd );
//显示窗口
[DllImport( "user32" )]
static extern bool ShowWindow( IntPtr hWnd, int cmdShow );
const int SW_RESTORE = 9;
//将窗口显示在最前面
[DllImport( "user32" )]
static extern bool SetForegroundWindow( IntPtr hWnd );