6

I have an Outlook 2010 Add-in coded in .NET 4.0/VS.NET 2010, C#. The Add-in extends the Ribbon => it adds a RibbonTab with 4 RibbonButtons to (RibbonType Property is set to) Microsoft.Outlook.Explorer and Microsoft.Outlook.Mail.Read.

Now, if the user clicks on one of the RibbonButtons, how can i determine if the user clicked on the button which is added to the Microsoft.Outlook.Explorer OR Microsoft.Outlook.Mail.Read?

4

2 回答 2

8

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);
            }

也许这对其他人有帮助......

于 2013-04-22T09:23:46.833 回答
6

一种选择是创建 (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
 }
于 2013-04-18T16:23:06.913 回答