解决方案 »

  1.   

    自己补上API定义h = FindWindow(主程序标题, null);
    SetForeGroundWindow(h);
    Application.Exit();
      

  2.   


    哥API定义什么呢。。我是新手。。可以说明白点吗?
      

  3.   


    if (yearTermForm == null || yearTermForm.IsDisposed)
                {
                    yearTermForm = new YearTermForm();
                    yearTermForm.MdiParent = this;
                    yearTermForm.WindowState = FormWindowState.Maximized;
                    yearTermForm.Show();
                }
                else
                    yearTermForm.Activate();yearTermForm 是定义好的全局变量。
      

  4.   

     [DllImport("user32.dll",EntryPoint="Findwindow")]
    public static extern int FindWindow (string lpClassName, string lpWindowName);[DllImport("user32.dll")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);这就是那两个需要导入的API
      

  5.   

    在program.cs里操作如下:
    添加命名空间:
    using System.Diagnostics;
    using System.Threading;
    然后在主函数里:
    main()
    {
                bool instantiated;
                Mutex mutex = new Mutex(true,"f6ForSingle", out instantiated);
                if (!instantiated)
                {
                    MessageBox.Show("你已经启动程序了。别闹了,好吗?");
                    return;
                }            Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Login());
                GC.KeepAlive(mutex);}
      

  6.   

    哥,您的方法的确可以,但是不明白当中的f6ForSingle是什么意思,然后 MessageBox.Show("你已经启动程序了。别闹了,好吗?");
    怎么做到如果已经有运行了,那么把运行了的最前置呢?
      

  7.   

    [DllImport("User32.dll", EntryPoint = "FindWindow")] 
            
    private static extern int FindWindow(string lpClassName, string lpWindowName);private void test()
    {
        int count =  FindWindow(null, "主程序标题");
        if(count!=0){
               //已打开
         }else
         {
               //未打开
         }
    }
      

  8.   


    [DllImport("User32.dll", EntryPoint = "FindWindow")] 
            
    private static extern int FindWindow(string lpClassName, string lpWindowName);private void test()
    {
        int count =  FindWindow(null, "Home");
        if(count!=0){
               //已打开
         }else
         {
               //未打开
         }
    }
      

  9.   


    哥  您的这个是需要写在 Program 中的吗?  8楼的那个方法我感觉可以实现具体就不会了
      

  10.   

     [DllImport("user32.dll")]
            private static extern bool SetForegroundWindow(IntPtr hWnd);
            [DllImport("user32.dll")]
            private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
            [DllImport("user32.dll")]
            private static extern bool IsIconic(IntPtr hWnd);
            private const int SW_RESTORE = 9;        [STAThread]
            static void Main()
            {
                
                bool flag = false;
                Mutex mutex = new Mutex(true, "ZZZZZ", out flag);
                if (!flag)
                {
                    Process proc = Process.GetCurrentProcess();
                    Process.GetProcesses();
                    foreach (Process otherProc in Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName))
                    {
                        if (proc.Id != otherProc.Id)
                        {
                            IntPtr hWnd = otherProc.MainWindowHandle;
                            if (IsIconic(hWnd))
                            {
                                ShowWindowAsync(hWnd, 9);
                            }
                            SetForegroundWindow(hWnd);
                            break;
                        }
                    }               
                    Application.Exit();
                }
                else
                { 
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Home());
                }
            }
    Program中需要填写的内容,首先需要获取窗口句柄,然后判断进程,最后激活之前的窗口
      

  11.   

    http://www.360doc.com/content/13/0325/15/10504424_273826790.shtml 
    给你个写的比较乱的参考。