Outlook COM addin-creating controls on NewExplorer event.

C

Chris Bardon

I've been working on an Outlook COM addin for a while now, and thanks
to the great post here (http://blogs.msdn.com/eric_carter/archive/
2004/10/10/240568.aspx) I've managed to implement a listener on the
event interface for explorer creation. The problem I'm still running
into though, is that the custom controls I create as temporary aren't
being created if Outlook is already loaded by another application in
the background (as a COM object).

My event listener looks for new explorer events, and then installs an
activation handler on the explorer. When the explorer is activated, I
create my controls. The problem here is that when I launched Outlook,
the explorer was created, but not activated right away (I'd have to
click out of Outlook, and then back to trigger the activation event).
My solution to this problem was to force the newly created explorer to
activate when I detected its creation, which works when Outlook is
launched normally, but if Outlook.exe is already running in the
background, it looks like a new explorer is created that can't be
activated right away (i.e. its associated application is null). I can
still install a handler on it, but my controls aren't installed until
the explorer is manually activated by switching applications from and
back to Outlook.

What I'm trying to figure out at this point is, can I force a new
explorer to be created as active? If the main Outlook GUI is the
Explorer object, then I can't figure out why it could be created and
not be active (or at least, activatable). Even if I continue with the
explorer object, attempting to access the command bars object on it
using:

oCommandBars =
(CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars",
BindingFlags.GetProperty, null, oActiveExplorer, null);

I get an exception. Why is it that an explorer is created without a
command bars object? Is there a better way to create temporary
controls on the command bars of an explorer rather than monitoring the
activation/creation events?

I'm kind of confused here, and I'd appreciate an assist on this one.

Thanks,

Chris
 
K

Ken Slovak - [MVP - Outlook]

If Outlook has been started using automation with no Explorers or other
visible UI you can test for that in your OnConnection handler.
Application.Explorers.Count will then return 0.

In that case what I do is to instantiate an Explorers collection object that
handles the NewExplorer event. That will fire when an Explorer is shown or
the user starts Outlook, which adds an Explorer to the existing Outlook
session.

I then add that Explorer to my Explorer wrapper collection. I set up UI for
the Explorer in:
Activate
SelectionChange
BeforeFolderSwitch

I handle all those events and if one fires and my class level Boolean
uiCreated is false I then call to create my UI. The reason to do this is
that depending on Outlook version and how Outlook is started the first
Activate event may not fire unless the user selects a different window and
then selects the Outlook Explorer window. One of the 3 events will fire no
matter what and no matter how the Explorer was opened.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top