CommandBarControl.Copy

M

Mikael Alhadeff

Hello,

I'm trying to add a button to both the Outlook Explorer toolbar and
the Inspectors toolbar.

As i need to get the event Click for this button, i would like to
create one CommandBarButton object and add it to the different
toolbars.

To do this, in the OnConnection Method, i create the CommandBarButton
and add it to the Explorer Standard Toolbar (if it was already on the
toolbar, i retrieve the existing one).

Then, in the Inspectors.New event handler, i try to add the existing
button using the CommandBarControl.Copy method.

The code to do this is the following :

CommandBar commandBar = Inspector.CommandBars["Standard"];
theButton.Copy(commandBar,System.Reflection.Missing.Value);
theButton.SetFocus();

When i run that code, i always get an "Invalid Parameter Exception".

If i use the following instruction :

theButton.Copy(System.Reflection.Missing.Value,System.Reflection.Missing.Value);

The button is successfully copied to the same toolbar it is already
located in (the Standard toolbar in the current explorer).

It sounds like a cast problem, but i really don't know what type of
object is the Copy method expecting for the bar parameter.

In the Outlook Object Model documentation, they say the method expect
a Variant for the CommandBar object, but as you may have noticed i'm
currently programming my addin in C#.

If someone could tell me how to cast this commandbar to avoid that
exception from being thrown, or either if there is a better way to add
the same button to both an explorer toolbar and every inspector
toolbars, it would help me a lot !

Thanks in advance,

Mikael Alhadeff

ASK sa
 
M

Mikael Alhadeff

What is the Copy Method for then ?????

What i'm trying to do is to avoid the headache implied by
creating/destroying event handlers for "temporary buttons"...

There is no way to add the same button object to different toolbars ??

Mikael Alhadeff

ASK sa

Dmitry Streblechenko said:
You must add a new button to each Explorer or Inspector that you want to
handle.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Mikael Alhadeff said:
Hello,

I'm trying to add a button to both the Outlook Explorer toolbar and
the Inspectors toolbar.

As i need to get the event Click for this button, i would like to
create one CommandBarButton object and add it to the different
toolbars.

To do this, in the OnConnection Method, i create the CommandBarButton
and add it to the Explorer Standard Toolbar (if it was already on the
toolbar, i retrieve the existing one).

Then, in the Inspectors.New event handler, i try to add the existing
button using the CommandBarControl.Copy method.

The code to do this is the following :

CommandBar commandBar = Inspector.CommandBars["Standard"];
theButton.Copy(commandBar,System.Reflection.Missing.Value);
theButton.SetFocus();

When i run that code, i always get an "Invalid Parameter Exception".

If i use the following instruction :

theButton.Copy(System.Reflection.Missing.Value,System.Reflection.Missing.Val
ue);

The button is successfully copied to the same toolbar it is already
located in (the Standard toolbar in the current explorer).

It sounds like a cast problem, but i really don't know what type of
object is the Copy method expecting for the bar parameter.

In the Outlook Object Model documentation, they say the method expect
a Variant for the CommandBar object, but as you may have noticed i'm
currently programming my addin in C#.

If someone could tell me how to cast this commandbar to avoid that
exception from being thrown, or either if there is a better way to add
the same button to both an explorer toolbar and every inspector
toolbars, it would help me a lot !

Thanks in advance,

Mikael Alhadeff

ASK sa
 
D

Dmitry Streblechenko

I don't see how you can simplify your code by using a single button - you
need to add a button at least once, so you have to have code that creates a
button. Whether the code runs once for the first button only or for each new
inspector/explorer does not simplify your code. You end up having more code
as now you have to figure out when you need to create a button and when to
copy an existing one.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Mikael Alhadeff said:
What is the Copy Method for then ?????

What i'm trying to do is to avoid the headache implied by
creating/destroying event handlers for "temporary buttons"...

There is no way to add the same button object to different toolbars ??

Mikael Alhadeff

ASK sa

"Dmitry Streblechenko" <[email protected]> wrote in message
You must add a new button to each Explorer or Inspector that you want to
handle.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Mikael Alhadeff said:
Hello,

I'm trying to add a button to both the Outlook Explorer toolbar and
the Inspectors toolbar.

As i need to get the event Click for this button, i would like to
create one CommandBarButton object and add it to the different
toolbars.

To do this, in the OnConnection Method, i create the CommandBarButton
and add it to the Explorer Standard Toolbar (if it was already on the
toolbar, i retrieve the existing one).

Then, in the Inspectors.New event handler, i try to add the existing
button using the CommandBarControl.Copy method.

The code to do this is the following :

CommandBar commandBar = Inspector.CommandBars["Standard"];
theButton.Copy(commandBar,System.Reflection.Missing.Value);
theButton.SetFocus();

When i run that code, i always get an "Invalid Parameter Exception".

If i use the following instruction :
theButton.Copy(System.Reflection.Missing.Value,System.Reflection.Missing.Val
ue);
The button is successfully copied to the same toolbar it is already
located in (the Standard toolbar in the current explorer).

It sounds like a cast problem, but i really don't know what type of
object is the Copy method expecting for the bar parameter.

In the Outlook Object Model documentation, they say the method expect
a Variant for the CommandBar object, but as you may have noticed i'm
currently programming my addin in C#.

If someone could tell me how to cast this commandbar to avoid that
exception from being thrown, or either if there is a better way to add
the same button to both an explorer toolbar and every inspector
toolbars, it would help me a lot !

Thanks in advance,

Mikael Alhadeff

ASK sa
 

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