473,383 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Outlook - CommandBars

Hi
I am creating a outlook addins and in that OnConnection i am creating
a toolbar(Commandbars). the code is working fine..

But the problem is when i access a custom form on the click of a
commandbarbutton, other buttons handlers are not working.. Where am i
doing mistake??

Note:If i dont access a form, CommandBarButton works fine for repeated
clicks.
The entire code is in c#.

Pls let me know immediately
Anushya
Nov 15 '05 #1
4 3718
How exactly do you access a custom form? How do you add the buttons?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Anushya" <v_*******@hotmail.com> wrote in message
news:80**************************@posting.google.c om...
Hi
I am creating a outlook addins and in that OnConnection i am creating
a toolbar(Commandbars). the code is working fine..

But the problem is when i access a custom form on the click of a
commandbarbutton, other buttons handlers are not working.. Where am i
doing mistake??

Note:If i dont access a form, CommandBarButton works fine for repeated
clicks.
The entire code is in c#.

Pls let me know immediately
Anushya

Nov 15 '05 #2
Hi Dmitry

First of all THANKS for your reply.

Hi this is the code i am using.

Here when i click My_Bu any no. of times, it works. But if i go and
click other buttons after clicking My_Bu, other buttons didnt work.

If i start a fresh instance of outlook and if i go and click other
buttons it works fine even for multiple times.. If i click that My_Bu,
My_Bu works, then after other buttons didnt work.

Note: MyAn_Click displays frmView1 only for a single time.. Even if i
click next time it didnt work. frmView1 is an ordinary form without any
code or properties changed. Just had some controls.

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
string strTemp;
strTemp =
CreateToolBar((Microsoft.Office.Interop.Outlook.Ap plication)application)
;

}
//declare forms(developed in c#.net)
//frmInbox1 is displayed in MyBu_Click
//frmView1 is displayed in MyAn_Click
public View frmView1 = new View();
public frmInbox frmInbox1 = new frmInbox();

public string CreateToolBar(Microsoft.Office.Interop.Outlook.App lication
Application)
{
Microsoft.Office.Core.CommandBars oCommandBars;
Microsoft.Office.Core.CommandBar oStandardBar;

Microsoft.Office.Core.CommandBarButton MyBu;
Microsoft.Office.Core.CommandBarButton MyCo;
Microsoft.Office.Core.CommandBarButton MyAn;
Microsoft.Office.Core.CommandBarButton MyRe;
Microsoft.Office.Core.CommandBarButton MyOr;

try
{
oCommandBars =
(Microsoft.Office.Core.CommandBars)applicationObje ct.GetType().InvokeMem
ber("CommandBars", System.Reflection.BindingFlags.GetProperty , null,
applicationObject ,null);
}
catch(Exception)
{
// Outlook has the CommandBars collection on the Explorer object.
object oActiveExplorer;
oActiveExplorer=
applicationObject.GetType().InvokeMember("ActiveEx plorer",System.Reflect
ion.BindingFlags.GetProperty,null,applicationObjec t,null);
oCommandBars=
(Microsoft.Office.Core.CommandBars)oActiveExplorer .GetType().InvokeMembe
r("CommandBars",System.Reflection.BindingFlags.Get Property,null,oActiveE
xplorer,null);
}

try
{
oStandardBar =
oCommandBars.Add("Bar",Microsoft.Office.Core.MsoBa rPosition.msoBarTop
,null,false);

}
catch(Exception)
{
oStandardBar = oCommandBars["Database"];
}

// In case the button was not deleted, use the existing one.
try
{
MyBu =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["but1"];
MyCo =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyCo"];
MyAn =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyAn"];
MyRe =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyRe"];
MyOr =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyOr"];
}

catch(Exception)
{
object omissing = System.Reflection.Missing.Value ;
MyBu = (Microsoft.Office.Core.CommandBarButton)
oStandardBar.Controls.Add(1, omissing , omissing , omissing , omissing);
MyBu.Caption = "Button1";
MyBu.Style =
Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon AndCaption;
PrepareImage (strLookPath + @"res\1.ico");
MyBu.PasteFace ();

//similarly for all the buttons
}

try
{
MyBu.Tag = "Button1";
//similarly for all the buttons
MyBu.OnAction = "!<MyCOMAddin.Connect>";
//similarly for all the buttons
MyBu.Visible = true;
MyBu.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(this.MyB
u_Click);
//similarly for all the buttons

object oName =
applicationObject.GetType().InvokeMember("Name",Sy stem.Reflection.Bindin
gFlags.GetProperty,null,applicationObject,null);
oStandardBar = null;
oCommandBars = null;
return "success";

}
catch(System.Exception e)
{
return e.Message ;
}
}
private void MyBu_Click(Microsoft.Office.Core.CommandBarButton
cmdBarbutton,ref bool cancel)
{
//showing a form - In this form am getting some inputs from client
frmSelection1.application = PubapplicationObject;

frmeSelection1.Top = 250;
frmeSelection1.Left = 250;

frmeSelection1.InitialStart();

frmSelection1.strSelectedName = "";
frmSelection1.ShowDialog ();

strName = frmSelection1.strSelectedName.ToString();

if (strName.Trim().ToString().Length > 0)
{
string strTmp = GetSelectedItem(PubapplicationObject);
}

try
{
if (SetUserWindowPosition() > 0)
{
//show another form - frmInbox, this form replaces the outlook
//listvew(where mails are listed in outlook)
frmInbox1.InitialStart();
frmInbox1.BringToFront();
frmInbox1.Show();
}
}
catch (System.Exception e)
{
System.Windows.Forms.MessageBox.Show ("Error: " + e.Message.ToString
());
}

}
private void MyAn_Click(Microsoft.Office.Core.CommandBarButton
cmdBarbutton,ref bool cancel)
{
frmView1.ShowDialog();
}
private void MyCo_Click(Microsoft.Office.Core.CommandBarButton
cmdBarbutton,ref bool cancel)
{
System.Windows.Forms.MessageBox.Show("Co Clicked");

}

Anushya


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
Hi Dmitry

First of all THANKS for your reply.

Hi this is the code i am using.

Here when i click My_Bu any no. of times, it works. But if i go and
click other buttons after clicking My_Bu, other buttons didnt work.

If i start a fresh instance of outlook and if i go and click other
buttons it works fine even for multiple times.. If i click that My_Bu,
My_Bu works, then after other buttons didnt work.

Note: MyAn_Click displays frmView1 only for a single time.. Even if i
click next time it didnt work. frmView1 is an ordinary form without any
code or properties changed. Just had some controls.

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
string strTemp;
strTemp =
CreateToolBar((Microsoft.Office.Interop.Outlook.Ap plication)application)
;

}
//declare forms(developed in c#.net)
//frmInbox1 is displayed in MyBu_Click
//frmView1 is displayed in MyAn_Click
public View frmView1 = new View();
public frmInbox frmInbox1 = new frmInbox();

public string CreateToolBar(Microsoft.Office.Interop.Outlook.App lication
Application)
{
Microsoft.Office.Core.CommandBars oCommandBars;
Microsoft.Office.Core.CommandBar oStandardBar;

Microsoft.Office.Core.CommandBarButton MyBu;
Microsoft.Office.Core.CommandBarButton MyCo;
Microsoft.Office.Core.CommandBarButton MyAn;
Microsoft.Office.Core.CommandBarButton MyRe;
Microsoft.Office.Core.CommandBarButton MyOr;

try
{
oCommandBars =
(Microsoft.Office.Core.CommandBars)applicationObje ct.GetType().InvokeMem
ber("CommandBars", System.Reflection.BindingFlags.GetProperty , null,
applicationObject ,null);
}
catch(Exception)
{
// Outlook has the CommandBars collection on the Explorer object.
object oActiveExplorer;
oActiveExplorer=
applicationObject.GetType().InvokeMember("ActiveEx plorer",System.Reflect
ion.BindingFlags.GetProperty,null,applicationObjec t,null);
oCommandBars=
(Microsoft.Office.Core.CommandBars)oActiveExplorer .GetType().InvokeMembe
r("CommandBars",System.Reflection.BindingFlags.Get Property,null,oActiveE
xplorer,null);
}

try
{
oStandardBar =
oCommandBars.Add("Bar",Microsoft.Office.Core.MsoBa rPosition.msoBarTop
,null,false);

}
catch(Exception)
{
oStandardBar = oCommandBars["Database"];
}

// In case the button was not deleted, use the existing one.
try
{
MyBu =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["but1"];
MyCo =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyCo"];
MyAn =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyAn"];
MyRe =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyRe"];
MyOr =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyOr"];
}

catch(Exception)
{
object omissing = System.Reflection.Missing.Value ;
MyBu = (Microsoft.Office.Core.CommandBarButton)
oStandardBar.Controls.Add(1, omissing , omissing , omissing , omissing);
MyBu.Caption = "Button1";
MyBu.Style =
Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon AndCaption;
PrepareImage (strLookPath + @"res\1.ico");
MyBu.PasteFace ();

//similarly for all the buttons
}

try
{
MyBu.Tag = "Button1";
//similarly for all the buttons
MyBu.OnAction = "!<MyCOMAddin.Connect>";
//similarly for all the buttons
MyBu.Visible = true;
MyBu.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(this.MyB
u_Click);
//similarly for all the buttons

object oName =
applicationObject.GetType().InvokeMember("Name",Sy stem.Reflection.Bindin
gFlags.GetProperty,null,applicationObject,null);
oStandardBar = null;
oCommandBars = null;
return "success";

}
catch(System.Exception e)
{
return e.Message ;
}
}
private void MyBu_Click(Microsoft.Office.Core.CommandBarButton
cmdBarbutton,ref bool cancel)
{
//showing a form - In this form am getting some inputs from client
frmSelection1.application = PubapplicationObject;

frmeSelection1.Top = 250;
frmeSelection1.Left = 250;

frmeSelection1.InitialStart();

frmSelection1.strSelectedName = "";
frmSelection1.ShowDialog ();

strName = frmSelection1.strSelectedName.ToString();

if (strName.Trim().ToString().Length > 0)
{
string strTmp = GetSelectedItem(PubapplicationObject);
}

try
{
if (SetUserWindowPosition() > 0)
{
//show another form - frmInbox, this form replaces the outlook
//listvew(where mails are listed in outlook)
frmInbox1.InitialStart();
frmInbox1.BringToFront();
frmInbox1.Show();
}
}
catch (System.Exception e)
{
System.Windows.Forms.MessageBox.Show ("Error: " + e.Message.ToString
());
}

}
private void MyAn_Click(Microsoft.Office.Core.CommandBarButton
cmdBarbutton,ref bool cancel)
{
frmView1.ShowDialog();
}
private void MyCo_Click(Microsoft.Office.Core.CommandBarButton
cmdBarbutton,ref bool cancel)
{
System.Windows.Forms.MessageBox.Show("Co Clicked");

}

Anushya


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4

Hi Dmitry

just removed the declaration part of CommandBars and pasted as private
variables in the main class. It worked fine.. I think it's bcoz b4 its
garbage collected? Am i right?

If so even if i create a add-ins will .net take care of garbage
collection.. I remember read somewhre that in case of add-ins .net
doesnot handle garbage collection?? Wot exactly??

Anushya

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Anushya | last post by:
Hi I am creating a outlook addins and in that OnConnection i am creating a toolbar(Commandbars). the code is working fine.. But the problem is whenever i restart outlook, it is creating a new...
8
by: John | last post by:
Hi I am using the latest redemption. I am using the below code in vb.net to send mail in html format. The problem is that text does not get sent as html and html tags appear as they are in the...
4
by: damian | last post by:
Help! I created a COM addin using vb.net based on the KB article 302896 (http://support.microsoft.com/default.aspx?scid=kb;en-us;302896). The problem is Outlook remains in memory when after it. I...
1
by: Himselff | last post by:
Hi guys, Im developing a lil add-in that is goiing to allow the user by a button click to auto print PDF doc which are attach to hes emails, i think the things is to simple cause its not working...
26
by: Tom Becker | last post by:
Is there a way, from Access, to programmatically click the Send and Receive button in Outlook?
0
by: guilligan.geo | last post by:
Hello, I'm trying to create an addin for Outlook 2002 using the one provided in the demo of win32com as a starting point. I've been able to do my addin and test it if I go the "standard" way...
1
by: Phil Stanton | last post by:
I have a Yacht Club Db with names addresse phone nos, emails etc. I want to export them to Outlook. No problem in getting them into the contact folder. My problem is I have a folder within the...
1
by: arnott | last post by:
hi all, I am writing a add-in for Outlook 2007 using C# and VSTO ( Visual Studio 2008). When the user clicks on each mailitem in the inbox (or any folder) in the active explorer window, the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.