private Outlook.Explorer m_WindowsNew; // wrapped window object

        #endregion Fields

        #region Constructors

        /// <summary>
        /// <c>OutlookExplorerWrapper</c>
        /// Create new instance for explorer class 
        /// </summary>
        /// <param name="explorer"></param>
        public OutlookExplorerWrapper(Outlook.Explorer explorer)
        {
            //m_WindowsNew = explorer;
            m_WindowsNew = ThisAddIn.OutlookObj.ActiveExplorer();
            cbWidget = m_WindowsNew.CommandBars;
            ((Outlook.ExplorerEvents_Event)explorer).Close += new Microsoft.Office.Interop.Outlook.ExplorerEvents_CloseEventHandler(OutlookExplorerNew_Close);
        }
Beispiel #2
0
        private void ListAllCommands()
        {
            try
            {
                List <String> result = new List <string>();
                //
                Office.CommandBars cmds = Globals.ThisAddIn.Application.CommandBars;
                if (cmds.Count > 0)
                {
                    foreach (Office.CommandBar cmd in cmds)
                    {
                        result.Add(cmd.Name + "|" + cmd.Id);
                        if (cmd.Controls.Count > 0)
                        {
                            foreach (Office.CommandBarControl ctrl in cmd.Controls)
                            {
                                GetCommandBarControls(ctrl, "", result);
                            }
                        }
                    }
                }

                Excel.Worksheet sheet = (Excel.Worksheet)Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets.Add();
                for (Int32 i = 0; i < result.Count; i++)
                {
                    sheet.Range["A" + (i + 1)].Value = result[i];
                }
                //sheet.Range["A1:A" + result.Count].Value = result.ToArray();
            }
            catch (Exception ex)
            {
                ShowError("列举命令异常:" + ex.Message + ex.StackTrace);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Add a new CommandBar
        /// </summary>
        internal void Add()
        {
            if (_explorer == null)
            {
                return;
            }

            _commandBar = Find(_cmdBarName);
            if (_commandBar == null)
            {
                Office.CommandBars bars = _explorer.CommandBars;
                _commandBar = bars.Add(_cmdBarName, Office.MsoBarPosition.msoBarTop, false, true);
            }
            _commandBar.Visible = true;

            foreach (string btn in new string[] { "About", "Settings", "Decrypt", "Verify" })
            {
                _buttons.Add(btn, (Office.CommandBarButton)_commandBar.Controls.Add(Office.MsoControlType.msoControlButton,
                                                                                    Type.Missing, Type.Missing, 1, true));
                _buttons[btn].Style   = Office.MsoButtonStyle.msoButtonIconAndCaption;
                _buttons[btn].Caption = btn;
                _buttons[btn].Tag     = "GnuPG" + btn;
            }

            // http://www.kebabshopblues.co.uk/2007/01/04/visual-studio-2005-tools-for-office-commandbarbutton-faceid-property/
            _buttons["Decrypt"].FaceId  = 718;
            _buttons["Verify"].FaceId   = 719;
            _buttons["About"].FaceId    = 700;
            _buttons["Settings"].FaceId = 2144;

            _buttons["Decrypt"].Picture  = ImageConverter.Convert(Properties.Resources.lock_edit);
            _buttons["Verify"].Picture   = ImageConverter.Convert(Properties.Resources.link_edit);
            _buttons["About"].Picture    = ImageConverter.Convert(Properties.Resources.Logo);
            _buttons["Settings"].Picture = ImageConverter.Convert(Properties.Resources.database_gear);
        }
Beispiel #4
0
        /**
         * AddToolbar
         * Adds the toolbar and button to Excel
         **/
        private void AddToolbar()
        {
            if (this.toolbar == null)
            {
                Office.CommandBars cmdBar = this.Application.CommandBars;
                this.toolbar         = cmdBar.Add("MedPC Import Utility", Office.MsoBarPosition.msoBarTop, false, true);
                this.toolbar.Visible = true;
            }

            try
            {
                importButton         = (Office.CommandBarButton)toolbar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);
                importButton.Caption = "Quick-import data";
                importButton.Tag     = "MPC_Import";
                importButton.Click  += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(quickImportButton_click);
                importButton.Picture = getImage();

                importButton         = (Office.CommandBarButton)toolbar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);
                importButton.Caption = "Import data";
                importButton.Tag     = "MPC_Import";
                importButton.Click  += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(importButton_click);
                importButton.Picture = getImage();

                dataFilePath = "c:\\MED-PC IV\\Data";
                xmlFilePath  = "c:\\MED-PC IV\\MPC";
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        public virtual void LoadMenu()
        {
            Office.CommandBars oCommandBars = null;

            try
            {
                oCommandBars = (Office.CommandBars)m_app.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, m_app, null);
            }
            catch (Exception)
            {
            }

            try
            {
                NewMenuBar = oCommandBars[cstrMenuTitle];
            }
            catch (Exception)
            {
                // doesn't exist yet, so create it
                NewMenuBar         = oCommandBars.Add(cstrMenuTitle, 1, missing, true);
                NewMenuBar.Visible = true;
            }

            ReleaseComObject(oCommandBars);
        }
        private void InitializeToolbar()
        {
            if (cbNieuwsbrief == null)
            {
                // Adding the commandbar to Active explorer
                Office.CommandBars commandBars = this.Application.ActiveExplorer().CommandBars;

                // Adding Nieuwsbrief Toolbar to the commandBars
                cbNieuwsbrief = commandBars.Add(COMMANDBAR_TITLE, Office.MsoBarPosition.msoBarTop, false, true);
            }
        }
Beispiel #7
0
        public static void DisplayCommandBars(object objApp, string appName)
        {
            // Show all the command bars
            // Will need to cast objApp if Option Strict
            string s = "";

            Office.CommandBars cbars = null;

            switch (appName)
            {
            case "Microsoft Excel":
                MsoExcel.Application appExcel = (MsoExcel.Application)objApp;
                cbars = appExcel.CommandBars;
                break;

            case "Microsoft PowerPoint":
                MsoPowerPoint.Application appPowerPoint = (MsoPowerPoint.Application)objApp;
                cbars = appPowerPoint.CommandBars;
                break;

            case "Microsoft Project":
                MsoProject.Application appProject = (MsoProject.Application)objApp;
                cbars = appProject.CommandBars;
                break;

            case "Microsoft Visio":
                MsoVisio.Application appVisio = (MsoVisio.Application)objApp;
                cbars = (Office.CommandBars)appVisio.CommandBars;
                break;

            case "Microsoft Word":
                MsoWord.Application appWord = (MsoWord.Application)objApp;
                cbars = appWord.CommandBars;
                break;

            case "Outlook":
                MsoOutlook.Application appOutlook = (MsoOutlook.Application)objApp;
                MsoOutlook.Explorer    explorer   = appOutlook.ActiveExplorer();
                cbars = explorer.CommandBars;
                break;

            default:
                MessageBox.Show("DisplayCommandBars:Unknown appName->" + appName + "<");
                return;
            }

            foreach (Office.CommandBar bar in cbars)
            {
                s = s + String.Format("{0}\n", bar.Name);
            }

            MessageBox.Show(s);
        }
Beispiel #8
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // Define the Old Menu Bar
            PacktOldMenuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
            // Define the new Menu Bar into the existing menu bar
            PacktNewMenuBar = (Office.CommandBarPopup)PacktOldMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, false);
            //If PacktNewMenuBar not found then the code will add it
            if (PacktNewMenuBar != null)
            {
                // Set caption for the Menu
                PacktNewMenuBar.Caption = "Analyze PKCS#7 structure";
                // Tag string value passing
                PacktNewMenuBar.Tag = strMenuString;
                // Assigning button type
                PacktButton1 = (Office.CommandBarButton)PacktNewMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);
                // Setting up the button style
                PacktButton1.Style = Office.MsoButtonStyle.msoButtonIconAndCaptionBelow;
                // Set button caption
                PacktButton1.Caption = "Analyze PKCS#7 structure";
                // Set the menu visible
                PacktNewMenuBar.Visible = true;
            }



            // Verify the PacktCustomToolBar exist and add to the application
            if (PacktCustomToolBar == null)
            {
                // Adding the commandbar to Active explorer
                Office.CommandBars PacktBars = this.Application.ActiveExplorer().CommandBars;
                // Adding PacktCustomToolBar to the commandbars
                PacktCustomToolBar = PacktBars.Add("NewPacktToolBar", Office.MsoBarPosition.msoBarTop, false, true);
            }
            // Adding button to the custom tool bar
            Office.CommandBarButton MyButton1 = (Office.CommandBarButton)PacktCustomToolBar.Controls.Add(1, missing, missing, missing, missing);
            // Set the button style
            MyButton1.Style = Office.MsoButtonStyle.msoButtonCaption;
            // Set the caption and tag string
            MyButton1.Caption = "Analyze PKCS#7 structure";
            MyButton1.Tag     = "Analyze PKCS#7 structure";
            if (this.PacktButtonA == null)
            {
                // Adding the event handler for the button in the toolbar
                this.PacktButtonA   = MyButton1;
                PacktButtonA.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonClick);
            }
            olApp = new Outlook.ApplicationClass();
            Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");

            olExplorer = olApp.ActiveExplorer();
            //  olExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
        }
Beispiel #9
0
        private void AddToolbar()
        {
            if (newToolBar == null)
            {
                Office.CommandBars cmdBars = this.Application.ActiveExplorer().CommandBars;
                //cmdBars.
                newToolBar = cmdBars.Add("Banckle CRM", Office.MsoBarPosition.msoBarTop, false, true);
            }
            try
            {
                //Office.

                btnBanckle         = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing);
                btnBanckle.Style   = Office.MsoButtonStyle.msoButtonIcon;
                btnBanckle.Caption = "Banckle CRM";
                btnBanckle.Tag     = "Banckle CRM";
                btnBanckle.Picture = getImage(Properties.Resources.crm_16x16);
                btnBanckle.Click  += new Office._CommandBarButtonEvents_ClickEventHandler(btnBanckleClick);


                btnSync            = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing);
                btnSync.Style      = Office.MsoButtonStyle.msoButtonIconAndCaption;
                btnSync.Caption    = "Sync";
                btnSync.Tag        = "Sync";
                btnSync.Picture    = getImage(Properties.Resources.sync_16x16);
                btnSync.BeginGroup = true;
                btnSync.Click     += new Office._CommandBarButtonEvents_ClickEventHandler(btnSyncClick);


                btnSettings         = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing);
                btnSettings.Style   = Office.MsoButtonStyle.msoButtonIconAndCaption;
                btnSettings.Caption = "Settings";
                btnSettings.Picture = getImage(Properties.Resources.settings_16x16);
                btnSettings.Tag     = "Settings";
                newToolBar.Visible  = true;
                btnSettings.Click  += new Office._CommandBarButtonEvents_ClickEventHandler(btnSettingsClick);

                btnAbout            = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing);
                btnAbout.Style      = Office.MsoButtonStyle.msoButtonIconAndCaption;
                btnAbout.Caption    = "About";
                btnAbout.Picture    = getImage(Properties.Resources.banckle_16x16);
                btnAbout.BeginGroup = true;
                btnAbout.Tag        = "About";
                btnAbout.Visible    = true;
                btnAbout.Click     += new Office._CommandBarButtonEvents_ClickEventHandler(btnAboutClick);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error:" + ex.Message, "Error");
            }
        }
Beispiel #10
0
        public Office.CommandBarButton AddOptionToContextMenu(String name, int beforePos
                                                              , Office._CommandBarButtonEvents_ClickEventHandler handler)
        {
            Office.CommandBars commandbars = Globals.ThisAddIn.Application.CommandBars;

            Office.CommandBar       ccb    = commandbars["Cell"];
            Office.CommandBarButton button = (Office.CommandBarButton)ccb.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, beforePos + 1, true);
            button.Style   = Office.MsoButtonStyle.msoButtonCaption;
            button.Caption = name;
            button.Tag     = name;
            button.Visible = true;
            button.Click  += handler;

            return(button);
        }
        private void AddToolbar()
        {
            if (newToolBar == null)
            {
                Office.CommandBars cmdBars =
                    this.Application.ActiveExplorer().CommandBars;
                newToolBar = cmdBars.Add("NewToolBar",
                                         Office.MsoBarPosition.msoBarTop, false, true);
            }
            try
            {
                Office.CommandBarButton btnBanckleContacts =
                    (Office.CommandBarButton)newToolBar.Controls
                    .Add(1, missing, missing, missing, missing);
                btnBanckleContacts.Style = Office
                                           .MsoButtonStyle.msoButtonCaption;
                btnBanckleContacts.Caption = "Banckle Contacts";
                btnBanckleContacts.Tag     = "BanckleContacts";
                if (this.firstButton == null)
                {
                    this.firstButton   = btnBanckleContacts;
                    firstButton.Click += new Office.
                                         _CommandBarButtonEvents_ClickEventHandler
                                             (ButtonClick);
                }

                Office.CommandBarButton OutlookContacts = (Office
                                                           .CommandBarButton)newToolBar.Controls.Add
                                                              (1, missing, missing, missing, missing);
                OutlookContacts.Style = Office
                                        .MsoButtonStyle.msoButtonCaption;
                OutlookContacts.Caption = "Button 2";
                OutlookContacts.Tag     = "Button2";
                newToolBar.Visible      = true;
                if (this.secondButton == null)
                {
                    this.secondButton   = OutlookContacts;
                    secondButton.Click += new Office.
                                          _CommandBarButtonEvents_ClickEventHandler
                                              (ButtonClick);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        // Initialize Control
        private void InitializeCustomComponents()
        {
            // Add a custom commandbar button and set the name is "Start checking shapes"
            commandBarStart = this.Application.CommandBars.ActiveMenuBar;

            // Add the commandbar button into the commandbar
            commandBarButtonStart         = (Office.CommandBarButton)commandBarStart.Controls.Add(Office.MsoControlType.msoControlButton, Before: 1, Temporary: true);
            commandBarButtonStart.Style   = Office.MsoButtonStyle.msoButtonCaption;
            commandBarButtonStart.Caption = StartJob;
            commandBarButtonStart.FaceId  = 60;
            commandBarButtonStart.Visible = true;

            // Register click event of commandbarbutton
            commandBarButtonStart.Click += new Office._CommandBarButtonEvents_ClickEventHandler(commandBarButtonStart_Click);

            // Use CommandBars.OnUpdate event to detect shapes' event
            commandBars           = this.Application.CommandBars;
            commandBars.OnUpdate += new Office._CommandBarsEvents_OnUpdateEventHandler(commandBars_OnUpdate);

            // Initialize Task Panel
            // set the Position and width of task panel
            customTaskPanel = new CustomTaskPanel();
            Microsoft.Office.Tools.CustomTaskPane mycustomerTaskPane = this.CustomTaskPanes.Add(customTaskPanel, "Custom Task Panel Tracking Event");
            mycustomerTaskPane.Visible      = true;
            mycustomerTaskPane.Width        = 430;
            mycustomerTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;

            // Initialize Shapes in active worksheet
            Excel.Worksheet shapeworksheet = this.Application.ActiveSheet;
            Excel.Shape     shapeRect;
            Excel.Shape     shapeCircle;
            shapeRect   = shapeworksheet.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRectangle, 60, 80, 80, 30);
            shapeCircle = shapeworksheet.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeOval, 200, 30, 50, 50);

            rectangleShape = new MyShape(shapeRect);
            circleShape    = new MyShape(shapeCircle);

            // Initialize Shapes and Selected shape before the shapes change
            shapeSelectedLastTime  = GetShapeSelected();
            shapesExistingLastTime = new MyShapes(shapeworksheet);
        }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {

            vis_cmd_bars = this.Application.CommandBars as Office.CommandBars;

            vis_file_menu = vis_cmd_bars["Menu Bar"].Controls["&File"] as Office.CommandBarPopup;

            new_button = (Office.CommandBarButton) vis_file_menu.Controls.Add(
                Office.MsoControlType.msoControlButton, // Type
                this.missing, // Object
                this.missing, // Id
                2, // Before
                true // Temporary
                ) ;

            new_button.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;
            new_button.Caption = "My New Menu Item";
            //new_button.Tag = "My New Menu Item";
            new_button.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnOpen_Click);

        }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            if (this.Application.ActiveWindow != null)
            {
                Office.CommandBars commandBars = (Office.CommandBars) this.Application.ActiveWindow.CommandBars;
                Office.CommandBar  standardBar = commandBars["Standard"];

                if (standardBar != null)
                {
                    Office.CommandBarButton converterButton = (Office.CommandBarButton)standardBar.Controls.Add(
                        Office.MsoControlType.msoControlButton, Type.Missing,
                        Type.Missing, Type.Missing, true);

                    converterButton.Caption = "Convert";
                    converterButton.Visible = true;
                    converterButton.Enabled = true;
                    converterButton.Style   = Office.MsoButtonStyle.msoButtonCaption;

                    converterButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(openConverter_Click);
                }
            }
        }
Beispiel #15
0
        AddToolBar(
            Office.CommandBars cbars,
            string toolBarName)
        {
            Office.CommandBar cbar;

            // Check to see if the toolbar already exists.  Delete it if found.
            // Need to do this in a loop as some apps allow multiple bars with
            // same name.

            foreach (Office.CommandBar cb in cbars)
            {
                if (cb.Name == toolBarName)
                {
                    cb.Delete();
                }
            }

            cbar         = cbars.Add(toolBarName, Office.MsoBarPosition.msoBarTop, false, true);
            cbar.Visible = true;
            return(cbar);
        }
Beispiel #16
0
        public void OnStartupComplete(ref System.Array custom)
        {
            /*
             *
             * When outlook is opened it loads a Menu if Outlook plugin is installed.
             * PengERP - > Push, Partner ,Documents, Configuration
             *
             */
            Microsoft.Office.Interop.Outlook.Application app = null;
            try
            {
                app = new Microsoft.Office.Interop.Outlook.Application();
                object omissing = System.Reflection.Missing.Value;
                menuBar = app.ActiveExplorer().CommandBars.ActiveMenuBar;
                ConfigManager config = new ConfigManager();
                config.LoadConfigurationSetting();
                PengERPOutlookPlugin openerp_outlook = Cache.PengERPOutlookPlugin;
                PengERPConnect       openerp_connect = openerp_outlook.Connection;
                try
                {
                    if (openerp_connect.URL != null && openerp_connect.DBName != null && openerp_connect.UserId != null && openerp_connect.pswrd != "")
                    {
                        string decodpwd = Tools.DecryptB64Pwd(openerp_connect.pswrd);
                        openerp_connect.Login(openerp_connect.DBName, openerp_connect.UserId, decodpwd);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Unable to connect remote Server ' " + openerp_connect.URL + " '.", "PengERP Connection", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                newMenuBar = (office.CommandBarPopup)menuBar.Controls.Add(office.MsoControlType.msoControlPopup, omissing, omissing, omissing, true);
                if (newMenuBar != null)
                {
                    newMenuBar.Caption = "PengERP";
                    newMenuBar.Tag     = "My";

                    btn_open_partner         = (office.CommandBarButton)newMenuBar.Controls.Add(office.MsoControlType.msoControlButton, omissing, omissing, 1, true);
                    btn_open_partner.Style   = office.MsoButtonStyle.msoButtonIconAndCaption;
                    btn_open_partner.Caption = "Contact";
                    //Face ID will use to show the ICON in the left side of the menu.
                    btn_open_partner.FaceId = 3710;
                    newMenuBar.Visible      = true;
                    btn_open_partner.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_partner_Click);

                    btn_open_document         = (office.CommandBarButton)newMenuBar.Controls.Add(office.MsoControlType.msoControlButton, omissing, omissing, 2, true);
                    btn_open_document.Style   = office.MsoButtonStyle.msoButtonIconAndCaption;
                    btn_open_document.Caption = "Documents";
                    //Face ID will use to show the ICON in the left side of the menu.
                    btn_open_document.FaceId = 258;
                    newMenuBar.Visible       = true;
                    btn_open_document.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_document_Click);

                    btn_open_configuration_form         = (office.CommandBarButton)newMenuBar.Controls.Add(office.MsoControlType.msoControlButton, omissing, omissing, 3, true);
                    btn_open_configuration_form.Style   = office.MsoButtonStyle.msoButtonIconAndCaption;
                    btn_open_configuration_form.Caption = "Configuration";
                    //Face ID will use to show the ICON in the left side of the menu.
                    btn_open_configuration_form.FaceId = 5644;
                    newMenuBar.Visible = true;
                    btn_open_configuration_form.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_configuration_form_Click);
                }
            }
            catch (Exception)
            {
                object oActiveExplorer;
                oActiveExplorer = applicationObject.GetType().InvokeMember("ActiveExplorer", BindingFlags.GetProperty, null, applicationObject, null);
                oCommandBars    = (office.CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, oActiveExplorer, null);
            }
        }
Beispiel #17
0
        public static void RemoveMenu(object objApp, string appName, Office.CommandBar cbar, string menuName, string Name)
        {
            Office.CommandBars cbars = null;

            try
            {
                switch (appName)
                {
                case "Microsoft Excel":
                    MsoExcel.Application appExcel = (MsoExcel.Application)objApp;
                    cbars = appExcel.CommandBars;
                    break;

                case "Microsoft PowerPoint":
                    MsoPowerPoint.Application appPowerPoint = (MsoPowerPoint.Application)objApp;
                    cbars = appPowerPoint.CommandBars;
                    break;

                case "Microsoft Project":
                    MsoProject.Application appProject = (MsoProject.Application)objApp;
                    cbars = appProject.CommandBars;
                    break;

                case "Microsoft Visio":
                    MsoVisio.Application appVisio = (MsoVisio.Application)objApp;
                    cbars = (Office.CommandBars)appVisio.CommandBars;
                    break;

                case "Microsoft Word":
                    MsoWord.Application appWord = (MsoWord.Application)objApp;
                    cbars = appWord.CommandBars;
                    break;

                // TODO: There is no ActiveExplorer when we exit app.  How to handle?
                //case "Outlook":
                //    Outlook.Application appOutlook = (Outlook.Application)objApp;
                //    Outlook.Explorer explorer = appOutlook.ActiveExplorer();
                //    cbars = explorer.CommandBars;
                //    break;

                default:
                    MessageBox.Show("RemoveMenu:Unknown appName->" + appName + "<");
                    return;
                }

                cbar = cbars[menuName];

                foreach (Office.CommandBarControl cbc in cbar.Controls)
                {
                    if (cbc.Caption == Name)
                    {
                        cbc.Delete(Missing.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                throw;
            }
        }
Beispiel #18
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            try
            {
                test();
                menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
                RemoveMenubar();
                AddMenuBar();

                _Explorer = (Outlook.ExplorerClass)this.Application.ActiveExplorer();
                _CommandBars = _Explorer.CommandBars;
                _CommandBars.OnUpdate += new Microsoft.Office.Core._CommandBarsEvents_OnUpdateEventHandler(_CommandBars_OnUpdate);
                buttonConfig.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonConfig_Click);

                //MessageBox.Show("The Outlook add-in has been deployed successfully.");
            }
            catch (Exception ex)
            {
                FormError bob = new FormError(e.ToString(), "Erreur lors du deploiement du plugin."
            + System.Environment.NewLine + "Veuillez redémarrez le programme, réessayez ou contactez l'administrateur si le problème persiste.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Problème deploiement plugin :" + ex);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(ex + "\n\t\n\t");
                    file.Close();
                }
            }
        }
Beispiel #19
0
        public void OnStartupComplete(ref System.Array custom)
        {
            /*

             * When outlook is opened it loads a Menu if Outlook plugin is installed.
             * OpenERP - > Push, Partner ,Documents, Configuration

             */
            Microsoft.Office.Interop.Outlook.Application app = null;
            try
            {
                app = new Microsoft.Office.Interop.Outlook.Application();
                object omissing = System.Reflection.Missing.Value;
                menuBar = app.ActiveExplorer().CommandBars.ActiveMenuBar;
                ConfigManager config = new ConfigManager();
                config.LoadConfigurationSetting();
                OpenERPOutlookPlugin openerp_outlook = Cache.OpenERPOutlookPlugin;
                OpenERPConnect openerp_connect = openerp_outlook.Connection;
                try
                {
                    if (openerp_connect.URL != null && openerp_connect.DBName != null && openerp_connect.UserId != null && openerp_connect.pswrd != "")
                    {
                        string decodpwd = Tools.DecryptB64Pwd(openerp_connect.pswrd);
                        openerp_connect.Login(openerp_connect.DBName, openerp_connect.UserId, decodpwd);
                    }
                }
                catch(Exception )
                {
                    MessageBox.Show("Unable to connect remote Server ' " + openerp_connect.URL + " '.", "OpenERP Connection",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                }
                newMenuBar = (office.CommandBarPopup)menuBar.Controls.Add(office.MsoControlType.msoControlPopup, omissing, omissing, omissing, true);
                if (newMenuBar != null)
                {
                    newMenuBar.Caption = "OpenERP";
                    newMenuBar.Tag = "My";

                    btn_open_partner = (office.CommandBarButton)newMenuBar.Controls.Add(office.MsoControlType.msoControlButton, omissing, omissing, 1, true);
                    btn_open_partner.Style = office.MsoButtonStyle.msoButtonIconAndCaption;
                    btn_open_partner.Caption = "Contact";
                    //Face ID will use to show the ICON in the left side of the menu.
                    btn_open_partner.FaceId = 3710;
                    newMenuBar.Visible = true;
                    btn_open_partner.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_partner_Click);

                    btn_open_document = (office.CommandBarButton)newMenuBar.Controls.Add(office.MsoControlType.msoControlButton, omissing, omissing, 2, true);
                    btn_open_document.Style = office.MsoButtonStyle.msoButtonIconAndCaption;
                    btn_open_document.Caption = "Documents";
                    //Face ID will use to show the ICON in the left side of the menu.
                    btn_open_document.FaceId = 258;
                    newMenuBar.Visible = true;
                    btn_open_document.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_document_Click);

                    btn_open_configuration_form = (office.CommandBarButton)newMenuBar.Controls.Add(office.MsoControlType.msoControlButton, omissing, omissing, 3, true);
                    btn_open_configuration_form.Style = office.MsoButtonStyle.msoButtonIconAndCaption;
                    btn_open_configuration_form.Caption = "Configuration";
                    //Face ID will use to show the ICON in the left side of the menu.
                    btn_open_configuration_form.FaceId = 5644;
                    newMenuBar.Visible = true;
                    btn_open_configuration_form.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_configuration_form_Click);

                }

            }
            catch (Exception)
            {
                object oActiveExplorer;
                oActiveExplorer = applicationObject.GetType().InvokeMember("ActiveExplorer", BindingFlags.GetProperty, null, applicationObject, null);
                oCommandBars = (office.CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, oActiveExplorer, null);
            }
        }