Esempio n. 1
0
        static void Main(string[] args)
        {
            var assem = System.Reflection.Assembly.GetExecutingAssembly();
            var attr  = (System.Runtime.InteropServices.GuidAttribute)Attribute.GetCustomAttribute(assem, typeof(System.Runtime.InteropServices.GuidAttribute));
            var guid  = attr.Value;

            System.Threading.Mutex mutex;
            bool hasHandle = false;

            using (mutex = new System.Threading.Mutex(false, guid)) {
                try {
                    try {
                        // Mutexの所有権を要求
                        hasHandle = mutex.WaitOne(0, false);
                    } catch (System.Threading.AbandonedMutexException) {
                        // 別アプリがMutexオブジェクトを開放しないで終了した場合
                        hasHandle = true;

                        //throw;
                    }
                    if (hasHandle == false)
                    {
                        // Mutexの所有権が得られなかったため、起動済みと判断して終了
                        MessageBox.Show("既に起動されています。");
                        return;
                    }

                    //---------------------------------------------------------
                    // アプリケーション開始
                    //---------------------------------------------------------
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    //AoedeGlobal _g = new AoedeGlobal();
                    AoedeStaticGlobal.Settings = AoEDEAlarmSettings.LoadXml();
                    StartHotkeys();
                    NotifyIcon ni = SetNotifyIcon();

                    System.Windows.Forms.Application.Run();

                    ni.Dispose();
                    AoEDEAlarmSettings.SaveXml(AoedeStaticGlobal.Settings);
                } catch (Exception ex) {
                    // アプリケーション例外処理
                    Console.WriteLine(ex.Message);

                    //throw;
                } finally {
                    if (hasHandle)
                    {
                        mutex.ReleaseMutex();
                    }
                    mutex.Close();
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            AoedeStaticGlobal.Settings.Hotkey_Run       = (int)KeysArr[0];
            AoedeStaticGlobal.Settings.Hotkey_Stop      = (int)KeysArr[1];
            AoedeStaticGlobal.Settings.Hotkey_Customise = (int)KeysArr[2];

            AoEDEAlarmSettings.SaveXml(AoedeStaticGlobal.Settings);

            MessageBox.Show(text: "位置を保存しました。"
                            , caption: "画像位置設定"
                            , buttons: MessageBoxButtons.OK
                            , icon: MessageBoxIcon.Information
                            , defaultButton: MessageBoxDefaultButton.Button1
                            , options: MessageBoxOptions.DefaultDesktopOnly
                            );

            this.Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            AoedeStaticGlobal.Settings.Wood.X      = _ps.Wood.X;
            AoedeStaticGlobal.Settings.Wood.Y      = _ps.Wood.Y;
            AoedeStaticGlobal.Settings.Wood.Width  = _ps.Wood.Width;
            AoedeStaticGlobal.Settings.Wood.Height = _ps.Wood.Height;

            AoedeStaticGlobal.Settings.Food.X      = _ps.Food.X;
            AoedeStaticGlobal.Settings.Food.Y      = _ps.Food.Y;
            AoedeStaticGlobal.Settings.Food.Width  = _ps.Food.Width;
            AoedeStaticGlobal.Settings.Food.Height = _ps.Food.Height;

            AoedeStaticGlobal.Settings.Gold.X      = _ps.Gold.X;
            AoedeStaticGlobal.Settings.Gold.Y      = _ps.Gold.Y;
            AoedeStaticGlobal.Settings.Gold.Width  = _ps.Gold.Width;
            AoedeStaticGlobal.Settings.Gold.Height = _ps.Gold.Height;

            AoedeStaticGlobal.Settings.Stone.X      = _ps.Stone.X;
            AoedeStaticGlobal.Settings.Stone.Y      = _ps.Stone.Y;
            AoedeStaticGlobal.Settings.Stone.Width  = _ps.Stone.Width;
            AoedeStaticGlobal.Settings.Stone.Height = _ps.Stone.Height;

            AoedeStaticGlobal.Settings.Population.X      = _ps.Population.X;
            AoedeStaticGlobal.Settings.Population.Y      = _ps.Population.Y;
            AoedeStaticGlobal.Settings.Population.Width  = _ps.Population.Width;
            AoedeStaticGlobal.Settings.Population.Height = _ps.Population.Height;

            AoEDEAlarmSettings.SaveXml(AoedeStaticGlobal.Settings);

            MessageBox.Show(text: "位置を保存しました。"
                            , caption: "画像位置設定"
                            , buttons: MessageBoxButtons.OK
                            , icon: MessageBoxIcon.Information
                            , defaultButton: MessageBoxDefaultButton.Button1
                            , options: MessageBoxOptions.DefaultDesktopOnly
                            );

            this.Close();
        }