显示另一个被隐藏的程序 ?
有2个程序A.exe 与 B.exe
B.exe 被隐藏 //this.Visible = False;
问题:
想要用 A.exe 来显示 B.exe
该怎么实现?......
[解决办法]
调用2个API函数,用FindWindow找到另一个程序窗口的句柄,用ShowWindow显示出来。
[解决办法]
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr FindWindow(string strclassName, string strWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IntPtr trayHwnd = FindWindow(null, null);//如果通过窗口类查找目标程序填写第一个参数,如果通过窗口的标题查找程序填写第二个参数,相反另一个不用的参数填写为null
if (trayHwnd != IntPtr.Zero)
{
ShowWindow(trayHwnd, 0);//为0隐藏,为1显示
}
}