情况如下:
   我有一个其他公司开发的软件,它的内部只提供了一个execu函数(用来调用其他的应用程序),原来这个软件没有 登录退出功能。 现我用c#编了一个小小的login.exe实现登录功能(如果输入用户名,密码正确)就直接关闭调用程序的进程。
现出现的问题是:每当我点一次登录,就运行我login.exe一个实例。多点几下就在进程中就生成了n个login.exe。
我想要达到的目的:在第每点击‘登录'按钮,就运行login.exe,如果有一个login.exe运行就把正在运行的exe显示在最顶层(即不能有多个login.exe的存在)。 最好是能还能够把鼠标的位置给限定了。
请多位高手指点指点;

解决方案 »

  1.   

    处于最顶层的话,将该窗体的topmost属性设置ture限制鼠标需要用到API函数,C#没有现成的了。实现只运行一个:using System;
    using System.Collections.Generic;
    using System.Windows.Forms;namespace School.ReadPaperControl
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                // 控制仅打开单实例进程
                if (System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length == 0)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new frmControl());
                }
            }
        }
    }
      

  2.   


    using System; 
    using System.Collections.Generic; 
    using System.Windows.Forms; namespace School.ReadPaperControl 

        static class Program 
        { 
            /// <summary> 
            /// The main entry point for the application. 
            /// </summary> 
            [STAThread] 
            static void Main() 
            { 
                // 控制仅打开单实例进程 
                if (System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length == 0) 
                { 
                    Application.EnableVisualStyles(); 
                    Application.SetCompatibleTextRenderingDefault(false); 
                    Application.Run(new frmControl()); 
                } 
            } 
        } 
      

  3.   

    你能告诉我用那个api函数?
    在C#怎么调用api函数呀!我菜鸟也!
      

  4.   

    基于.Net平台应用程序唯一运行实例实现,
    我讲了三种方法,提供完整代码,同时分析他们的优缺点。
    http://blog.csdn.net/zhzuo/archive/2006/06/30/857405.aspx
    http://blog.csdn.net/zhzuo/archive/2006/07/04/874745.aspx