Proper place to add buttons to inspector

J

Jayme.Pechan

I'm trying to figure out the proper place to add buttons to an inspector in
2003. Here is what I've tried and the results:

1. I tried adding the buttons in the OnNewInspector function but it crashes
on some machines. On most it works great.
2. I then tried storing the inspector interface from the OnNewInspector but
didn't add the buttons until the Activate event but this simply stops
executing on the call to get_CommandBars call (no exception, just stops
running).
3. If I call get_CommandBars in the OnNewInspector then in the Activate
event, I call the methods to add the buttons, it simply crashes Outlook
altogether.

I've noticed several people in the group say that it should be done in the
Activate but how do you get the Inspector reference? I'm really confused
why it's so flaky at this point.

BTW, I'm using ATL and C++.

Thanks.
 
K

Ken Slovak - [MVP - Outlook]

NewInspector isn't the place, the weak object reference you get in that
event handler is really only good for checking
Inspector.CurrentItem.MessageClass or CurrentItem.Class. In most cases the
CommandBars collection of the Inspector isn't initialized in NewInspector.
The first Activate event is definitely the way to go.

What many of us do is to define a class that is stored in a list or
collection of some sort to keep the class alive. That class, an Inspector
wrapper class holds a reference to the Inspector, possibly the item in the
Inspector and a Key value. Each new item added to the collection increments
the Key value so the correct member of the list or collection can be easily
retrieved when needed and disposed of when appropriate.

The class handles all events for the Inspector and the item displayed in the
Inspector, so that's where your Activate handler would be. When you create
the UI make sure to assign each object a unique Tag property so a Click
event only fires in that one Inspector class. I usually use a GUID plus the
Key value to create unique Tag values.

An alternative is just to have a module level Inspector object defined to
keep it alive and to assign that object in NewInspector. However, that
doesn't give you the possibility of having unique settings per Inspector or
handling events from more than one open Inspector.
 

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