Esempio n. 1
0
        /// <summary>
        /// Splashフォームを消す
        /// </summary>
        public static void CloseSplash()
        {
            try
            {
                if (_closing)
                {
                    SaveCcConfigurationLog("Already closing");
                    return;
                }

                _closing = true;

                SaveCcConfigurationLog("");
                SaveCcConfigurationLog("Start CloseSplash");

                if (_mainForm != null)
                {
                    //SaveCcConfigurationLog("Start _MainForm_Activated");
                    //_mainForm.Activated -= new EventHandler(_mainForm_Activated);
                    ////メインフォームをアクティブにする
                    _mainForm.Activate();
                    //SaveCcConfigurationLog("End _MainForm_Activated");
                }

                if (_form != null && _form.IsDisposed == false)
                {
                    //Splashフォームを閉じる
                    //Invokeが必要か調べる
                    if (_form.InvokeRequired)
                    {
                        SaveCcConfigurationLog("Start _form.Invoke(new MethodInvoker(_form.Close))");
                        _form.Invoke(new MethodInvoker(_form.Close));
                        SaveCcConfigurationLog("End _form.Invoke(new MethodInvoker(_form.Close))");
                    }
                    else
                    {
                        SaveCcConfigurationLog("Start _form.Close");
                        _form.Close();
                        SaveCcConfigurationLog("End _form.Close");
                    }
                }

                //if ( _mainForm != null )
                //{
                //	SaveCcConfigurationLog("Start _MainForm_Activated");
                //	_mainForm.Activated -= new EventHandler(_mainForm_Activated);
                //	//メインフォームをアクティブにする
                //	_mainForm.Activate();
                //	SaveCcConfigurationLog("End _MainForm_Activated");
                //}

                _message1 = string.Empty;
                _message2 = string.Empty;

                if (_messageFont != null)
                {
                    _messageFont.Dispose();
                    _messageFont = null;
                }

                if (_messageBrush != null)
                {
                    _messageBrush.Dispose();
                    _messageBrush = null;
                }

                _form = null;
#if (USE_MULTI_THRED_SPLASH_FORM)
                _thread = null;
#endif
                _mainForm = null;
                SaveCcConfigurationLog("End CloseSplash");
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp.Message);
            }
        }
Esempio n. 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new ccMushroom());

            try
            {
                ccMushroom.appTitle = Application.ProductName;

                // コマンド ライン パラメータ
                string[] cmdParam = Environment.GetCommandLineArgs();
                for (int i = 0; i < cmdParam.Length; i++)
                {
                    if (cmdParam[i] == update.CMDPARAM_SHOW_PROG_UPDATE_MESSAGE)
                    {
                        showProgUpdateMessage = true;
                    }
                    else if (cmdParam[i] == CMDPARAM_OFFLINE)
                    {
                        onlineEnable = false;
                    }
                    else if (cmdParam[i].StartsWith(CMDPARAM_APP_TITLE))
                    {
                        ccMushroom.appTitle = cmdParam[i].Substring(CMDPARAM_APP_TITLE.Length);
                    }
                    else if (cmdParam[i] == CMDPARAM_DEBMODE)
                    {
                        debMode = true;
                    }
                    else if (cmdParam[i] == CMDPARAM_EXPERT_MODE)
                    {
                        expertMode = true;
                    }
                    else if (cmdParam[i].StartsWith(CMDPARAM_DELAY_TIME))
                    {
                        int delayTime = int.Parse(cmdParam[i].Substring(CMDPARAM_DELAY_TIME.Length));
                        if (delayTime != 0)
                        {
                            Thread.Sleep(delayTime * 1000);
                        }
                    }
                    else if (cmdParam[i].StartsWith(CMDPARAM_BUTTON_TEXT))
                    {
                        try
                        {
                            string      buttonText         = cmdParam[i].Substring(CMDPARAM_BUTTON_TEXT.Length);
                            XmlDocument xmlCcConfiguration = new XmlDocument();
                            xmlCcConfiguration.Load(Application.StartupPath + "\\" + ccMushroom.CC_CONFIGURATION_FILE_NAME);
                            string  xpath       = ccMushroom.TAG_APPLICATION + "[" + ccMushroom.TAG_BUTTON_TEXT + "='" + buttonText + "']";
                            XmlNode application = xmlCcConfiguration.DocumentElement.SelectSingleNode(xpath);
                            if (application != null)
                            {
                                ProcessStart(application, null);
                            }
                        }
                        catch (Exception exp)
                        {
                            MessageBox.Show(exp.Message, ccMushroom.appTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        return;
                    }
                }

/*#if (DEBUG)
 *                              debMode = true;
 #endif*/

                if (!GetAppConfig())
                {
                    MessageBox.Show(messageApplicationError, "APPLICATION CONFIG ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // ウィンドウの位置とサイズ
                ccMushroom.GetWindowRectangle();

                // ミューテックスを確認して、アプリケーションを起動する
                Mutex m = new Mutex(false, ccMushroom.appTitle);

                if (m.WaitOne(0, false))                        // 最初の起動?
                {
                    if (ProgramUpdateRelaunch())
                    {
                        m.ReleaseMutex();
                        m.Close();
                        return;
                    }

                    ccMushroom formCcMushroom = new ccMushroom();

#if (SHOW_STARTING_SPLASH_FORM)
                    ////スプラッシュウィンドウを表示
#if (USE_MULTI_THRED_SPLASH_FORM)
                    SplashForm.ShowSplash(formCcMushroom);
#else
                    SplashForm splash = new SplashForm(formCcMushroom);
                    splash.Show();
                    Application.DoEvents();
#endif
#endif

                    Application.Run(formCcMushroom /*new ccMushroom()*/);
                    m.ReleaseMutex();
                }
                else
                {
                    // bring old instance to the front
                    IntPtr hWnd = api.FindWindow(null, ccMushroom.appTitle);
                    if (hWnd != IntPtr.Zero)
                    {
                        if (api.IsIconic(hWnd) || !api.IsWindowVisible(hWnd))
                        {
                            api.ShowWindow(hWnd, api.SW_SHOWNOACTIVATE);
                        }
                        api.SetForegroundWindow(hWnd);
                    }
                }

                // アプリケーションが終わるまでmへの参照を維持するようにする
                GC.KeepAlive(m);
                m.Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, MethodBase.GetCurrentMethod().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }