示例#1
0
        /// <summary>
        ///      Implements the OnConnection method of the IDTExtensibility2 interface.
        ///      Receives notification that the Add-in is being loaded.
        /// </summary>
        /// <param term='application'>
        ///      Root object of the host application.
        /// </param>
        /// <param term='connectMode'>
        ///      Describes how the Add-in is being loaded.
        /// </param>
        /// <param term='addInInst'>
        ///      Object representing this Add-in.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        {
            string strAppName = (string)application.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, application, null);

            if (strAppName == "Microsoft Word")
            {
                appThis = new WordApp(application);
            }
            else if (strAppName == "Microsoft Excel")
            {
                appThis = new ExcelApp(application);
            }
            else if (strAppName == "Microsoft Publisher")
            {
                appThis = new PubApp(application);
            }
            else if (strAppName == "Microsoft Access")
            {
                appThis = new AccessApp(application);
            }
            else
            {
                string strError = String.Format("The '{0}' application is not supported!", strAppName);
                System.Windows.Forms.MessageBox.Show(strError, cstrCaption);
                throw new Exception(strError);
            }

            if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
            {
                OnStartupComplete(ref custom);
            }
        }
示例#2
0
		/// <summary>
		///      Implements the OnConnection method of the IDTExtensibility2 interface.
		///      Receives notification that the Add-in is being loaded.
		/// </summary>
		/// <param term='application'>
		///      Root object of the host application.
		/// </param>
		/// <param term='connectMode'>
		///      Describes how the Add-in is being loaded.
		/// </param>
		/// <param term='addInInst'>
		///      Object representing this Add-in.
		/// </param>
		/// <seealso class='IDTExtensibility2' />
		public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
		{
			string strAppName = (string)application.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, application, null);
			if (strAppName == "Microsoft Word")
				 appThis = new WordApp(application);
			else if (strAppName == "Microsoft Excel")
				appThis = new ExcelApp(application);
			else if (strAppName == "Microsoft Publisher")
				appThis = new PubApp(application);
			else if (strAppName == "Microsoft Access")
				appThis = new AccessApp(application);
			else
			{
				string strError = String.Format("The '{0}' application is not supported!", strAppName);
				System.Windows.Forms.MessageBox.Show(strError, cstrCaption);
				throw new Exception(strError);
			}

			if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
			{
				OnStartupComplete(ref custom);
			}
		}