如果你怕程序关不了可以这样了 foreach (Process p in Process.GetProcesses()) { if (p.ProcessName == "A.exe")//A中写B。EXE,反之则反。 { p.Kill(); } }
using System; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices;namespace WindowsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("user32.dll", EntryPoint = "FindWindow")] public static extern int FindWindow( string lpClassName, string lpWindowName ); [DllImport("user32.dll", EntryPoint = "SetParent")] public static extern int SetParent( int hWndChild, int hWndNewParent ); private void Form1_Load(object sender, EventArgs e) { System.Diagnostics.Process.Start("calc.exe"); System.Threading.Thread.Sleep(100); SetParent(FindWindow("SciCalc", "计算器"), this.Handle.ToInt32()); } } }
2、如果你实现了将一个程序打包,那么两个程序打包就水到渠成了
System.Diagnostics.Process.Start(Application.StartupPath + "B.exe");
Application.Exit();
在B程序中写入
System.Diagnostics.Process.Start(Application.StartupPath + "A.exe");
Application.Exit();
搞定了。
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName == "A.exe")//A中写B。EXE,反之则反。
{
p.Kill();
}
}
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} [DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(
string lpClassName,
string lpWindowName
); [DllImport("user32.dll", EntryPoint = "SetParent")]
public static extern int SetParent(
int hWndChild,
int hWndNewParent
); private void Form1_Load(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("calc.exe");
System.Threading.Thread.Sleep(100);
SetParent(FindWindow("SciCalc", "计算器"), this.Handle.ToInt32());
}
}
}
在C# 中插入标准C 代码?
标准C 代码中另外还含有多个.h文件,一个Lib,3个DLL 文件(实际上是标准C 调用他们的),DLL 是C 写成的。有没有人帮我解决,小弟先谢谢了:把这些标准C 代码放在C# 中,让他在C# 平台中执行
我的QQ:617972928 ,[email protected]