假设有两个程序,分别为“A.exe”、“B.exe”,分别是来自两个不同的解决方案,我在A中用Process.Start("B.exe"); 实现了启动同一目录下的B,此时如何保持B始终在A之前,如果B窗口不取消,则无法在A上操作?
ps:可能表达地不清楚,平时在一些程序中也碰到过类似的,就像这样此时再点击“系统属性”窗口无法选中。WinForm前端
ps:可能表达地不清楚,平时在一些程序中也碰到过类似的,就像这样此时再点击“系统属性”窗口无法选中。WinForm前端
你说的两个exe是两个独立的进程,不一样的场景。
你要这个效果的话,可能要换一下思路了,楼下请继续~
private void Form1_Activated(object sender, EventArgs e)
{
Form2.BringToFront();
}
然后用SetParent将它的父窗口设置为第一个窗口,那么它永远在第一个窗口前面。
private static extern IntPtr FindWindow(string strclassName, string strWindowName);
IntPtr hWnd = (IntPtr)FindWindow(null, Title);
if (hWnd != IntPtr.Zero)
{
bool isIcon = IsIconic(hWnd);
if (!isIcon)
{
SetForegroundWindow(hWnd);
}
else
{
OpenIcon(hWnd);
}
}
title就是要激活的窗口标题
那用委托吧
启动前将主画面设为this.Enabled =FALSEp.SynchronizingObject = this;
p.Exited += (sender, e) =>
{
this.Enabled = true;
};
p.EnableRaisingEvents = true;
调用计算器为例: Process.Start("calc");
Thread.Sleep(1000);
IntPtr hwnd = FindWindow(null, "计算器");
if (hwnd != IntPtr.Zero)
{
SetForegroundWindow(hwnd);
//Process.Start(@"C:\Documents and Settings\10989889a\桌面\反汇编工具.exe");
//IntPtr hWnd = (IntPtr)FindWindow(null, "打开文件 - 安全警告");
SetParent(hwnd, this.Handle);
////DialogBoxParam(hWnd, null, this.Handle, IntPtr.Zero, IntPtr.Zero);
}
调用计算器为例: Process.Start("calc");
Thread.Sleep(1000);
IntPtr hwnd = FindWindow(null, "计算器");
if (hwnd != IntPtr.Zero)
{
SetForegroundWindow(hwnd);
//Process.Start(@"C:\Documents and Settings\10989889a\桌面\反汇编工具.exe");
//IntPtr hWnd = (IntPtr)FindWindow(null, "打开文件 - 安全警告");
SetParent(hwnd, this.Handle);
////DialogBoxParam(hWnd, null, this.Handle, IntPtr.Zero, IntPtr.Zero);
}
sorry。你理解错误了
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool OpenIcon(IntPtr hWnd); [System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd); [System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hWnd);