示例#1
0
        static void Main()
        {
            System.IO.Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            IocRegister.Register();
            bool createdNew = false;

            using (Mutex mutex = new Mutex(true, "Client.WinMain", out createdNew))
            {
                if (createdNew)
                {
                    Application.ThreadException += Application_ThreadException;
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }
                else
                {
                    try
                    {
                        string path = WinAPIs.GetHandleFile();
                        if (System.IO.File.Exists(path))
                        {
                            string s = System.IO.File.ReadAllText(path, System.Text.Encoding.UTF8) ?? "";
                            int    h = 0;
                            if (!string.IsNullOrEmpty(s) && int.TryParse(s, out h) && h > 0)
                            {
                                IntPtr hwnd = new IntPtr(h);
                                WinAPIs.PostMessage(hwnd, WinAPIs.WM_OPEN_FORM, 0, 0);
                            }
                        }
                    }
                    catch { }
                }
            }
        }
        public MainForm()
        {
            InitializeComponent();

            Current         = this;
            this.FileClient = IocUtils.Get <IFileClient>();
            this.Login();

            try { File.WriteAllText(WinAPIs.GetHandleFile(), this.Handle.ToString(), Encoding.UTF8); }
            catch { }
        }
        public LoginForm()
        {
            InitializeComponent();

            this.client = MainForm.Current.FileClient;
            try { File.WriteAllText(WinAPIs.GetHandleFile(), this.Handle.ToString(), Encoding.UTF8); }
            catch { }

            this.lb_Msg.Text = "";

            this.SetEnabled(true);

            if (ConfigUtils.IsRememberPassword)
            {
                this.txt_Account.Text      = ConfigUtils.Account;
                this.txt_Pwd.Text          = ConfigUtils.Password;
                this.checkBox_User.Checked = true;
            }
        }