Hi,
I do a slight variation on the above in that I maintain list of the open inspectors (I wrap the inspector an keep that in the list ).
Adding them on the new inspector event and removing them on a wired up close event close.
In my ribbon code I have a static method FindOutlookInspector that finds the inspector using the control.context of the ribbon.
Something along these lines ..
OutlookInspector is my wrapped inspector class but you may not need that etc.
Also I only care about Mail Items
void _inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
OutlookItem olItem = null;
try
{
object newitem = Inspector.CurrentItem;
olItem = new OutlookItem(newitem);
if (olItem.Class == Outlook.OlObjectClass.olMail && olItem.MessageClass == "IPM.Note")
{
OutlookInspector existingWindow = FindOutlookInspector(Inspector);
if (existingWindow == null)
{
OutlookInspector window = new OutlookInspector(Inspector);
window.Close += new EventHandler(WrappedWindow_Close);
_windows.Add(window);
}
}
catch (Exception ex)
{
throw ex;
}
}
void WrappedWindow_Close(object sender, EventArgs e)
{
OutlookInspector window = (OutlookInspector)sender;
window.Close -= WrappedWindow_Close;
_windows.Remove(window);
}
internal static OutlookInspector FindOutlookInspector(object window)
{
foreach (OutlookInspector inspector in _windows)
{
if (inspector.Window == window)
{
return inspector;
}
}
return null;
}
Then in the ribbon code i can call FindOutlookInspector to get the wrapped inspector
OutlookInspector window = ThisAddIn.FindOutlookInspector(control.Context);