Outlook Add-in, RibbonType Microsoft.Outlook.Explorer and Mi



我有一个。net 4.0/VS编写的Outlook 2010插件。Net 2010, c#。插件扩展丝带=>它添加了一个RibbonTab与4个丝带按钮(RibbonType属性设置为)Microsoft.Outlook.ExplorerMicrosoft.Outlook.Mail.Read

现在,如果用户单击其中一个RibbonButtons,我如何确定用户是否单击了添加到Microsoft.Outlook.ExplorerMicrosoft.Outlook.Mail.Read的按钮?

来自SilverNinja的建议给了我一个方向…最后我的代码是:

                // get active Window
            object activeWindow = Globals.ThisAddIn.Application.ActiveWindow();
            if (activeWindow is Microsoft.Office.Interop.Outlook.Explorer)
            {
                // its an explorer window
                Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
                Outlook.Selection selection = explorer.Selection;
                for (int i = 0; i < selection.Count; i++)
                {
                    if (selection[i + 1] is Outlook.MailItem)
                    {
                        Outlook.MailItem mailItem = selection[i + 1] as Outlook.MailItem;
                        CreateFormOrForm(mailItem);
                    }
                    else
                    {
                        Logging.Logging.Log.Debug("One or more of the selected items are not of type mail message..!");
                        System.Windows.Forms.MessageBox.Show("One or more of the selected items are not of type mail message..");
                    }
                }
            }
            if (activeWindow is Microsoft.Office.Interop.Outlook.Inspector)
            {
                // its an inspector window
                Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
                Outlook.MailItem mailItem = inspector.CurrentItem as Outlook.MailItem;
                CreateFormOrForm(mailItem);
            }

也许这对其他人有帮助…

一种选择是使用共享功能库创建(2)个功能区。在调用共享库时,可以传递单击哪个功能区操作的上下文。

更好的选择是检查应用程序的ActiveWindow属性,通过ThisAddin.Application.ActiveWindow()来确定用户处于哪个上下文。

 var windowType = Globals.ThisAddin.Application.ActiveWindow();
 if (windowType is Outlook.Explorer)
 {
     Outlook.Explorer exp = type as Outlook.Explorer;
     // you have an explorer context
 }
 else if (windowType is Outlook.Inspector)
 {
     Outlook.Inspector exp = type as Outlook.Inspector;
     // you have an inspector context
 }

最新更新