解决方案 »

  1.   

    [DllImport("user32.dll", SetLastError=true)]
    static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
      

  2.   

    static void Main()
    {
        int nIndex;    Process   procCurrent = Process.GetCurrentProcess();
        Process[] procProgram = Process.GetProcessesByName("Foo");    /* check if program is already running */
        if(procProgram.Length > 1)
        {
            for(nIndex = 0; nIndex < procProgram.Length; nIndex++)
            {
                /* switch to the other instance and let this one die */
                if(procProgram[nIndex].Id != procCurrent.Id)
                    SwitchToThisWindow(procProgram[nIndex].MainWindowHandle, true);
            }
        }
        else
        {
            /* enable visual style, most commonly associated with the XP operating system */
            Application.EnableVisualStyles();
            Application.DoEvents();
            Application.Run(new frmFoo());
        }
    }
      

  3.   

    问题解决了
    [DllImport("USER32.DLL")]
    public static extern void SwitchToThisWindow(IntPtr hwnd, Boolean fAltTab);如果写成.....(..., bool fAltTab)就不成
    这有什么不同,晕!
      

  4.   

    奇怪..应该说用bool也是可以的..
      

  5.   

    SwitchToThisWindow是从USER32.DLL提取出来的,USER32.DLL不是C#编写的,为了与其他语言兼容,要使用Boolean,bool只是C#的关键字
      

  6.   

    如果要解释,也只能说bool是C#里的关键字,而Boolean则属于.net 的类型..但我觉得这个不能算是什么理由,因为记得用bool也是可以的..