⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splashscreen.cs

📁 微软的行业应用解决方案示例
💻 CS
字号:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Launcher.Properties;

namespace Launcher
{
    public partial class SplashScreen : Form
    {
        #region Fields & Constants

        private StatusMessageWindow receiveMessageWindow;
        private string _targetApplicationPath = string.Empty;

        //Using hard GUIDs to allow each process to discover the other
        private const string CALLBACK_WINDOW_ID = "A91BE6D8-C4F1-11DC-A074-83ED55D89593";

        private const string TARGET_APP_EXECUTABLE_NAME = "\\HardwareDistributor.exe";

        #endregion

        #region Constructors

        /// <summary>
        /// Keep light so the form UI comes up quicker
        /// </summary>
        public SplashScreen()
        {
            InitializeComponent();
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// Launch the target application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SplashScreen_Load(object sender, EventArgs e)
        {
            //initialize target application path
            _targetApplicationPath = System.IO.Path.GetDirectoryName(this.GetType().Assembly.GetName().CodeBase)
                 + TARGET_APP_EXECUTABLE_NAME;

            bool targetAppInMemory = CheckTargetAppInMemory();

            //we need to listen for status messages only on fresh startup
            if (!targetAppInMemory)
                ListenForMessages();

            //if target app not running, this will launch it
            //in case the app is already running, then this call will bring it up in focus
            LaunchApplication();

            //if the app was already running, then shut ourself down
            if (targetAppInMemory)
                Shutdown();
        }

        #endregion

        #region Methods

        /// <summary>
        /// Initiate window that will listen for messages addressed to the 
        /// launcher appplication
        /// </summary>
        private void ListenForMessages()
        {

            // Create a message window using this form for its constructor.
            // CALLBACK_WINDOW_ID is used by the target app to address messages
            this.receiveMessageWindow = new StatusMessageWindow(this, CALLBACK_WINDOW_ID);
        }

        /// <summary>
        /// Start target application on new thread.If target application is already running, 
        /// then bring it into focus
        /// </summary>
        private void LaunchApplication()
        {
            //start the main application in the background
            //pass in the status window name as parameter - this will be used by the main app 
            //to send back messages
            ProcessStartInfo startinfo =
                new ProcessStartInfo(_targetApplicationPath, CALLBACK_WINDOW_ID + " \"" + Resources.TargetWindowName + "\"");
            

            Process.Start(startinfo);

        }

        /// <summary>
        /// Figure out whether the target application is already running in memory or not
        /// </summary>
        /// <returns></returns>
        private bool CheckTargetAppInMemory()
        {
			return (Native.FindWindow(null, Resources.TargetWindowName) != IntPtr.Zero);

        }

        /// <summary>
        /// Close the form. Called by the message window thread
        /// </summary>
        internal void Shutdown()
        {
            this.Close();
        }

        /// <summary>
        /// Update the status bar with new text. Called by message window
        /// </summary>
        /// <param name="newStatus"></param>
        internal void UpdateStatus(string newStatus)
        {
            StatusLabel.Text = newStatus;
        }

        #endregion

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -