commandbar - getting started

J

Jan Agermose

Im trying to get started on this comaddin programming in outlook 2003. Im
using c# and created a solution in visual studio and created an example
using information from a microsoft example. It compiles and it does load
(using the installer created by the wizard).

The onstartup is posted below - look for "this fails" comments. It seams
commandBars["Standard"] returns a null pointer exception. Altså trying to
iterate the commandBars collections fails?

Any ideas? Does anyone have a all in one class example that simply adds a
button on the toolbar that pops up a messagebox if pressed?

Best regards
Jan Agermose


public void OnStartupComplete(ref System.Array custom)

{



CommandBars commandBars =

applicationObject.ActiveExplorer().CommandBars;

applicationObject.

IEnumerator ie = null;

try

{

// If our button is already

// on the Standard CommandBar, use it.

btnGetEMailStats = (CommandBarButton)

commandBars["Standard"].Controls["Statistics"];

}

catch

{

// OOPS! Our button is not there, so

// we need to make a new instance.

// Note that the Add() method was

// defined to take optional parameters,

// which are not supported in C#.

// Thus we must specify Missing.Value.

try

{

MessageBox.Show(commandBars.GetType().ToString());

// this fails:

MessageBox.Show(commandBars.ActiveMenuBar.Name);

// this fails (if the above line is delete of cause :)

btnGetEMailStats = (CommandBarButton)

commandBars["Standard"].Controls.Add(1,

System.Reflection.Missing.Value,

System.Reflection.Missing.Value,

System.Reflection.Missing.Value,

System.Reflection.Missing.Value);

btnGetEMailStats.Caption = "Statistics";

btnGetEMailStats.Style = MsoButtonStyle.msoButtonCaption;

}

catch (System.Exception e)

{

MessageBox.Show("fejl: "+e.ToString());

}

MessageBox.Show("Kører2!");

}

// Setting the Tag property is not required, but can be used

// to quickly reterive your button.

btnGetEMailStats.Tag = "Statistics";

// Setting OnAction is also optional, however if you specify

// the ProgID of the Add-in, the host will automatically

// load the Add-in if the user clicks on the CommandBarButton when

// the Add-in is not loaded. After this point, the Click

// event handler is called.

btnGetEMailStats.OnAction = "!<EMailStatsAddIn.Connect>";

btnGetEMailStats.Visible = true;

// Rig-up the Click event for the new CommandBarButton type.

btnGetEMailStats.Click += new

_CommandBarButtonEvents_ClickEventHandler(

btnGetEMailStats_Click);

}
 

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