我希望能从我的程序中启动另外一个无标题栏的应用程序。假设这个程序时Notepad.exe。
Process P = new Process();
P.StartInfo.FileName = "./notepad.exe";
P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
P.Start();
这样做不行。添加
[DllImport("User32.dll")]
public static extern bool ShowWindow(IntPtr HWND, int MSG);
然后
private void Form1_Load(object sender, EventArgs e)
{
Process P = new Process();
P.StartInfo.FileName = "./notepad.exe";
P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
P.Start();
System.Threading.Thread.Sleep(100);
ShowWindow(P.MainWindowHandle, SW_HIDE);
}
这样窗体可以隐藏,但是是出现一小会儿后隐藏。怎样才能让它不出现直接隐藏呢?
Process P = new Process();
P.StartInfo.FileName = "./notepad.exe";
P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
P.Start();
这样做不行。添加
[DllImport("User32.dll")]
public static extern bool ShowWindow(IntPtr HWND, int MSG);
然后
private void Form1_Load(object sender, EventArgs e)
{
Process P = new Process();
P.StartInfo.FileName = "./notepad.exe";
P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
P.Start();
System.Threading.Thread.Sleep(100);
ShowWindow(P.MainWindowHandle, SW_HIDE);
}
这样窗体可以隐藏,但是是出现一小会儿后隐藏。怎样才能让它不出现直接隐藏呢?
private void Form1_Load(object sender, EventArgs e)
{
this.Hide();//窗体隐藏
Process P = new Process();
P.StartInfo.FileName = "./notepad.exe";
P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
P.Start();
System.Threading.Thread.Sleep(100);
ShowWindow(P.MainWindowHandle, SW_HIDE);
}
添加P.StartInfo.CreateNoWindow = true;
{
ProcessStartInfo psi = new ProcessStartInfo("notepad.exe");
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(psi);
}