Search code examples
outlookvstooutlook-addinoffice-addinscom-interop

VSTO Outlook: Opening Outlook from a mailto link does not create custom task pane


I have an VSTO Outlook Addin which shows always an Outlook custom task pane in all windows, explorers and inspectors. This is working perfectly, I mean, custom task pane is always show, except one particular use case, e.g. when you open outlook by clicking in a mailto link in a web page for example. In this case no explorer is open, instead only one knspector window is open, in this case the reply/compose window. So I need to handle when outlook is open through a mailto link and show my custom task pane in the reply/compose window, so which event do i need to handle? It looks like in this case i am not calling the logic to show my custom task pane when there are 0 explorers opened. I want to handle that event , check if numbers of explorers opened are 0 and then in this case show my ctp. Any help please?


Solution

  • If you are using Inspectors.NewInspector event, it won't fire for the mailto links. What you can do, is create a timer (use the Timer object from the Form namespace - it fires on the same thread) that checks the Application.Inspectors collection periodically and verifies that your task pane has been added to that inspector. You can create an Inspector wrapper class that handles Inspector.Close to remove itself from the parent list maintained by your code as well as contains a pointer to your task pane. When looping through the Outlook's inspectors collection, you can match OOM's Inspector object to your wrapper by comparing the HWND of an Inspector object to that stored by your wrapper. The window handle (HWND) can be retrieved using the IOleWindow interface - cast the Inspector object to IOleWindow and call IOleWindow.GetWindow