Group:  Microsoft Outlook ยป microsoft.public.outlook.program_addins
Thread: Creating a command bar on an Inspector

Geek News

Creating a command bar on an Inspector
bstrum 6/12/2007 10:06:01 PM
I am trying to create a command bar in the NewInspector event. The code
seems to be working fine on Office 2003 and 2007 but throws an exception in
Office XP when I access the CommandBars.Add function. Any ideas why?

Other things I am noticing are
- CommandBar.FindControl always seems to return null.

- Under office xp, adding controls to an already existing command bar (such
as Standard) persists even when restarting outlook. This is not the case
under 2003 and 2007 as the buttons need to be recreated each time. Any
workarounds for this?

Thank you,

Benjamin Strum
ThinkTron Corp.
Re: Creating a command bar on an Inspector
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 6/13/2007 2:16:00 PM
NewInspector provides a weak object reference and should not be used for
creating UI. Wait for the first Activate event. In fact in Outlook 2007 this
is even more important than in earlier versions.

Always add any UI with the Temporary argument set to true. When you get the
Inspector.Close (or Item.Close since one or the other may not fire depending
on how the item is closed) also delete your UI.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"bstrum" <bstrum[ at ]discussions.microsoft.com> wrote in message
news:6078BF6A-0D97-44F5-9249-540A30B23F65[ at ]microsoft.com...
[Quoted Text]
>I am trying to create a command bar in the NewInspector event. The code
> seems to be working fine on Office 2003 and 2007 but throws an exception
> in
> Office XP when I access the CommandBars.Add function. Any ideas why?
>
> Other things I am noticing are
> - CommandBar.FindControl always seems to return null.
>
> - Under office xp, adding controls to an already existing command bar
> (such
> as Standard) persists even when restarting outlook. This is not the case
> under 2003 and 2007 as the buttons need to be recreated each time. Any
> workarounds for this?
>
> Thank you,
>
> Benjamin Strum
> ThinkTron Corp.

Re: Creating a command bar on an Inspector
bstrum 6/13/2007 6:25:02 PM
Couple questions:

1) Should I use InspectorEvents or InspectorEvents_10? I.e., which one
ensures maximum compatiblity?

2) What are the dispids for Activate, Deactivate and Closed?

3) Does Activate get called multiple times for a specific mailitem?

Thank you,

Benjamin Strum
ThinkTron Corporation

"Ken Slovak - [MVP - Outlook]" wrote:

[Quoted Text]
> NewInspector provides a weak object reference and should not be used for
> creating UI. Wait for the first Activate event. In fact in Outlook 2007 this
> is even more important than in earlier versions.
>
> Always add any UI with the Temporary argument set to true. When you get the
> Inspector.Close (or Item.Close since one or the other may not fire depending
> on how the item is closed) also delete your UI.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "bstrum" <bstrum[ at ]discussions.microsoft.com> wrote in message
> news:6078BF6A-0D97-44F5-9249-540A30B23F65[ at ]microsoft.com...
> >I am trying to create a command bar in the NewInspector event. The code
> > seems to be working fine on Office 2003 and 2007 but throws an exception
> > in
> > Office XP when I access the CommandBars.Add function. Any ideas why?
> >
> > Other things I am noticing are
> > - CommandBar.FindControl always seems to return null.
> >
> > - Under office xp, adding controls to an already existing command bar
> > (such
> > as Standard) persists even when restarting outlook. This is not the case
> > under 2003 and 2007 as the buttons need to be recreated each time. Any
> > workarounds for this?
> >
> > Thank you,
> >
> > Benjamin Strum
> > ThinkTron Corp.
>
>
Re: Creating a command bar on an Inspector
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 6/14/2007 3:14:52 PM
I don't think there's a difference in compatibility unless you're supporting
Outlook 2000.

I have no idea what you mean by the dispid's for those events, or why you
would need that.

Activate gets called many times. It may fire 2 or 3 times the first time the
item is activated, and then each time the focus returns to that item. Just
use a flag to test for the first Activate or to test for the UI having been
created. Since there are also cases where that first Activate will not fire
you usually back that up with a check in a handler for OnSelectionChange,
which will fire in those cases and there you also check for the UI creation.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"bstrum" <bstrum[ at ]discussions.microsoft.com> wrote in message
news:29316196-5F9F-43FB-B0E3-F2F9DF8F546E[ at ]microsoft.com...
[Quoted Text]
> Couple questions:
>
> 1) Should I use InspectorEvents or InspectorEvents_10? I.e., which one
> ensures maximum compatiblity?
>
> 2) What are the dispids for Activate, Deactivate and Closed?
>
> 3) Does Activate get called multiple times for a specific mailitem?
>
> Thank you,
>
> Benjamin Strum
> ThinkTron Corporation

Re: Creating a command bar on an Inspector
bstrum 6/14/2007 9:05:01 PM
Sorry, "dispid's" are the dispatch ids that are exposed via IDispatch. I was
able to hack it by trying various values:
0xf001= Activated
0xf006 = Deactivated
0xf008 = Closed

I am making some progress on what should really be a trivial task: creating
controls on a toolbar. I am still encountering problems and of course they
vary from office version. Any assistance / insight on this is greatly
appreciated.

Note: All of the problems are occuring within the Inspector->Activated
event. Also, all my code uses late binding.

In Office XP, I am not able to access Inspector.CommandBars. I get an
exception, "Exception has been thrown by the target of an invocation.".

In Office 2003, I am unable to set the Picture property of a newly created
CommandBarControl.
MO.CommandBarControls ctls = <the controls of a newly created command bar>
MO.CommandBarControl ctl = ctls["Options"];
System.Drawing.Image img = CommonImages.logo;
ctl.Picture = StdOleUtils.GettIPictureDispFromPicture(img); // throws
exception

In Office 2007, the above code throws an exception on the first activate
event but not afterwards.

Benjamin Strum
ThinkTron Corporation

"Ken Slovak - [MVP - Outlook]" wrote:

[Quoted Text]
> I don't think there's a difference in compatibility unless you're supporting
> Outlook 2000.
>
> I have no idea what you mean by the dispid's for those events, or why you
> would need that.
>
> Activate gets called many times. It may fire 2 or 3 times the first time the
> item is activated, and then each time the focus returns to that item. Just
> use a flag to test for the first Activate or to test for the UI having been
> created. Since there are also cases where that first Activate will not fire
> you usually back that up with a check in a handler for OnSelectionChange,
> which will fire in those cases and there you also check for the UI creation.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "bstrum" <bstrum[ at ]discussions.microsoft.com> wrote in message
> news:29316196-5F9F-43FB-B0E3-F2F9DF8F546E[ at ]microsoft.com...
> > Couple questions:
> >
> > 1) Should I use InspectorEvents or InspectorEvents_10? I.e., which one
> > ensures maximum compatiblity?
> >
> > 2) What are the dispids for Activate, Deactivate and Closed?
> >
> > 3) Does Activate get called multiple times for a specific mailitem?
> >
> > Thank you,
> >
> > Benjamin Strum
> > ThinkTron Corporation
>
>
Re: Creating a command bar on an Inspector
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 6/15/2007 1:52:25 PM
I really don't understand why you're using late binding. You can subscribe
to the events such as Activate using early binding and that works on all
versions. I have no experience with how you're doing things so I can't
really help. I use early binding on the various events and never have
version problems with Activate.

When using early binding you reference the earliest tlb you want to use and
that just works with later versions. It's not so cut and dried with managed
code, there the signatures of things have changed and unless you use the
Outlook 2003 PIA's that support both that version and Outlook 2007 you need
separate addins for earlier versions.

I never use IDispatch to handle events, so there I can't help you.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"bstrum" <bstrum[ at ]discussions.microsoft.com> wrote in message
news:609637F3-E263-4EAF-A291-9DEF0F0F2675[ at ]microsoft.com...
[Quoted Text]
> Sorry, "dispid's" are the dispatch ids that are exposed via IDispatch. I
> was
> able to hack it by trying various values:
> 0xf001= Activated
> 0xf006 = Deactivated
> 0xf008 = Closed
>
> I am making some progress on what should really be a trivial task:
> creating
> controls on a toolbar. I am still encountering problems and of course
> they
> vary from office version. Any assistance / insight on this is greatly
> appreciated.
>
> Note: All of the problems are occuring within the Inspector->Activated
> event. Also, all my code uses late binding.
>
> In Office XP, I am not able to access Inspector.CommandBars. I get an
> exception, "Exception has been thrown by the target of an invocation.".
>
> In Office 2003, I am unable to set the Picture property of a newly created
> CommandBarControl.
> MO.CommandBarControls ctls = <the controls of a newly created command
> bar>
> MO.CommandBarControl ctl = ctls["Options"];
> System.Drawing.Image img = CommonImages.logo;
> ctl.Picture = StdOleUtils.GettIPictureDispFromPicture(img); // throws
> exception
>
> In Office 2007, the above code throws an exception on the first activate
> event but not afterwards.
>
> Benjamin Strum
> ThinkTron Corporation

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net