A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Commandbar Button Click Handler



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 7th 07, 08:19 PM posted to microsoft.public.outlook.program_addins
saturn
external usenet poster
 
Posts: 3
Default Commandbar Button Click Handler

Hi,

I am creating Outlook plug-in using ATL. I have to add a commandbar
(with a button) to only new mail items page. And on the click of that
button I have to execute certain set of code.

For this I have Advised for Outlook::InspectorsEvents on OnConnection.
When the corresponding function is called with new inspector, I checks
if the current item is new mail item.

If item is new mail item then I adds a commandbar and button to the
inspector and sets a bool variable so that I don't need to create it
again in the current session and I removes the commandbar on call to
OnDisconnect. At the same time, i Advise for click of this button
using Office::_CommandBarButtonEvents.

Now my commandbar and is visible whenever I open any new mail item.

All the thinks works fine if there is only one such open mail item and
any click on my button calls the corresponding function.

But if two or more such windows are open simultaneously then none
except the first opened inspector button clicks calls the correponding
function.

Have anyone else have faced any similar problem? What I am doing wrong
here? Any pointers on this will be of great help.

Regards,
Pradeep

Ads
  #2  
Old August 7th 07, 10:39 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Commandbar Button Click Handler

I don't do C++ so I can't be specific on this for you, but you need to
handle 2 things to get this to work correctly for multiple open Inspectors.

First, create a class that is used to wrap each open Inspector and handle
events for it. Add an instance of the class to a collection or list of some
sort to keep it alive and remove it from the collection when Inspector.Close
fires. Each button you add is then added only to that Inspector. Create the
button using the Temporary = true argument setting.

Second, create a unique Tag property for each button as it's created. That
prevents a click from firing in every open Inspector or firing once for each
open Inspector, the click will then only fire in the correct Inspector and
no other.

I usually create my Tags using a GUID string plus a key value that's
incremented each time a new Inspector is opened. That guarantees a unique
Tag.

As a belt and suspenders approach you also should be explicitly deleting the
button in Inspector.Close so it doesn't persist in the outcmd.dat file if by
some chance Outlook crashes or doesn't shut down correctly to allow the
Temporary setting to take effect.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"saturn" wrote in message
oups.com...
Hi,

I am creating Outlook plug-in using ATL. I have to add a commandbar
(with a button) to only new mail items page. And on the click of that
button I have to execute certain set of code.

For this I have Advised for Outlook::InspectorsEvents on OnConnection.
When the corresponding function is called with new inspector, I checks
if the current item is new mail item.

If item is new mail item then I adds a commandbar and button to the
inspector and sets a bool variable so that I don't need to create it
again in the current session and I removes the commandbar on call to
OnDisconnect. At the same time, i Advise for click of this button
using Office::_CommandBarButtonEvents.

Now my commandbar and is visible whenever I open any new mail item.

All the thinks works fine if there is only one such open mail item and
any click on my button calls the corresponding function.

But if two or more such windows are open simultaneously then none
except the first opened inspector button clicks calls the correponding
function.

Have anyone else have faced any similar problem? What I am doing wrong
here? Any pointers on this will be of great help.

Regards,
Pradeep


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding image to Outlook commandbar button saturn Add-ins for Outlook 3 August 3rd 07 03:13 PM
An event raise twice when click the button. David Add-ins for Outlook 0 July 16th 06 01:25 PM
click a button on the toolbar (via VBA?) Dan Outlook and VBA 7 May 2nd 06 10:35 AM
click a button on the toolbar (via VBA?) Dan Outlook - General Queries 2 May 1st 06 02:39 PM
how to add a custom button on the explorer "standard" commandbar Herve cadieu Outlook and VBA 1 March 17th 06 04:33 PM


All times are GMT +1. The time now is 01:20 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.