首页  编辑  

打开计算器,如果存在则激活主窗体

Tags: /C#/进程、线程处理/   Date Created:

using System . Diagnostics;

using System . Runtime . InteropServices;

[ DllImport ( "user32.dll" )]

public static extern bool SetForegroundWindow( IntPtr hWnd);        

private void button1_Click( object sender , EventArgs e)

{

    Process [] vProcesses = Process . GetProcessesByName( "calc" );

    if (vProcesses . Length <= 0 )

        Process . Start( "calc.exe" );

    else SetForegroundWindow(vProcesses[ 0 ] . MainWindowHandle);

}