需要自动运行一个程序,但有时候开启的时候会处于最小化或被切换到其他程序,而无法保证其主界面在前台显示,有何办法保证Process.Start开启的程序在前台谢谢!

解决方案 »

  1.   

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr FindWindow(string className, string windowName);[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern bool SetForegroundWindow(IntPtr hWnd);[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern bool IsIconic(IntPtr hWnd);[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern bool OpenIcon(IntPtr hWnd);private void button1_Click(object sender, EventArgs e)
    {
        IntPtr handle = FindWindow(null, "");
        if (handle != IntPtr.Zero)
        {
            if (IsIconic(handle))
            {
                OpenIcon(handle);
            }
            else
            {
                SetForegroundWindow(handle);
            }
        }