|
|
Hi,
I have a COM add-in that is a toolbar for outlook and has some controls on it - buttons and combo boxes. I am able to successfully register event handlers for them. However, when I have more than 1 button, I don't receive the callback for the second button.
Is there something that needs to be done to receive callbacks for the 2nd button? I thought the handler has an input param, IDispatch* which we can be used for verifying which button was clicked. However, I fail to receive callbacks for both the buttons. I get for either of them at any point of time depending on which button I used to register.
Thanks,
|
|
Use unique Tag properties for each of your controls.
-- 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
"Exchnerd" <sanjuraja[ at ]gmail.com> wrote in message news:8fe15d82-3c85-4154-b627-541e2077f9e2[ at ]v13g2000pro.googlegroups.com...
[Quoted Text] > Hi, > > I have a COM add-in that is a toolbar for outlook and has some > controls on it - buttons and combo boxes. I am able to successfully > register event handlers for them. However, when I have more than 1 > button, I don't receive the callback for the second button. > > Is there something that needs to be done to receive callbacks for the > 2nd button? I thought the handler has an input param, IDispatch* which > we can be used for verifying which button was clicked. However, I fail > to receive callbacks for both the buttons. I get for either of them at > any point of time depending on which button I used to register. > > Thanks,
|
|
On Nov 14, 11:35 am, "Ken Slovak - [MVP - Outlook]" <kenslo...[ at ]mvps.org> wrote:
[Quoted Text] > Use unique Tag properties for each of your controls. > > -- > 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> > "Exchnerd" <sanjur...[ at ]gmail.com> wrote in message > > news:8fe15d82-3c85-4154-b627-541e2077f9e2[ at ]v13g2000pro.googlegroups.com... > > > Hi, > > > I have a COM add-in that is a toolbar for outlook and has some > > controls on it - buttons and combo boxes. I am able to successfully > > register event handlers for them. However, when I have more than 1 > > button, I don't receive the callback for the second button. > > > Is there something that needs to be done to receive callbacks for the > > 2nd button? I thought the handler has an input param, IDispatch* which > > we can be used for verifying which button was clicked. However, I fail > > to receive callbacks for both the buttons. I get for either of them at > > any point of time depending on which button I used to register. > > > Thanks, If you are referring to using the put_Tag method, I have already done that and each of them have unique strings. My 2nd registration attempt fails and I understand that you cannot have 2 handlers for the same component. Am I right if I say that the unique tags would suffice to have a single DispEventAdvice for buttons and I will receive callbacks for both the buttons?
|
|
Each button is a different object and needs its own click event handler.
-- 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
"Exchnerd" <sanjuraja[ at ]gmail.com> wrote in message news:a15183a3-bc46-44e6-8737-d75816c2d31f[ at ]o4g2000pra.googlegroups.com... <snip> If you are referring to using the put_Tag method, I have already done that and each of them have unique strings. My 2nd registration attempt fails and I understand that you cannot have 2 handlers for the same component. Am I right if I say that the unique tags would suffice to have a single DispEventAdvice for buttons and I will receive callbacks for both the buttons?
|
|
On Nov 14, 1:45 pm, "Ken Slovak - [MVP - Outlook]" <kenslo...[ at ]mvps.org> wrote:
[Quoted Text] > Each button is a different object and needs its own click event handler. > > -- > 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> > "Exchnerd" <sanjur...[ at ]gmail.com> wrote in message > > news:a15183a3-bc46-44e6-8737-d75816c2d31f[ at ]o4g2000pra.googlegroups.com... > <snip> > If you are referring to using the put_Tag method, I have already done > that and each of them have unique strings. > My 2nd registration attempt fails and I understand that you cannot > have 2 handlers for the same component. Am I right if I say that the > unique tags would suffice to have a single DispEventAdvice for buttons > and I will receive callbacks for both the buttons? Can you be more clear? Do I need to register twice? - meaning call DispEventAdvise for each button? The second call fails for me. How do I map the event handlers for the buttons?
|
|
I don't do C++ but in any other language I'd just add one separate click event procedure for each button and I'd hook up those handlers to their corresponding button's Click events. This is what I'd do in C#:
button1.Click += new Office._CommandBarButtonEvents_ClickEventHandler(button1Click); button2.Click += new Office._CommandBarButtonEvents_ClickEventHandler(button2Click); etc.
-- 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
"Exchnerd" <sanjuraja[ at ]gmail.com> wrote in message news:e3dfad5b-871a-4c48-80b0-50fb5bbb7f0b[ at ]s1g2000prg.googlegroups.com... <snip>Can you be more clear? Do I need to register twice? - meaning call DispEventAdvise for each button? The second call fails for me. How do I map the event handlers for the buttons?
|
|
On Nov 14, 2:34 pm, "Ken Slovak - [MVP - Outlook]" <kenslo...[ at ]mvps.org> wrote:
[Quoted Text] > I don't do C++ but in any other language I'd just add one separate click > event procedure for each button and I'd hook up those handlers to their > corresponding button's Click events. This is what I'd do in C#: > > button1.Click += new > Office._CommandBarButtonEvents_ClickEventHandler(button1Click); > button2.Click += new > Office._CommandBarButtonEvents_ClickEventHandler(button2Click); > etc. > > -- > 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> > "Exchnerd" <sanjur...[ at ]gmail.com> wrote in message > > news:e3dfad5b-871a-4c48-80b0-50fb5bbb7f0b[ at ]s1g2000prg.googlegroups.com... > <snip>Can you be more clear? > Do I need to register twice? - meaning call DispEventAdvise for each > button? The second call fails for me. > How do I map the event handlers for the buttons? that means I will have to give a new sink for every button and register/unregister for the events (for each button added)
|
|
Yes, that's what I've been telling you.
-- 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
"Exchnerd" <sanjuraja[ at ]gmail.com> wrote in message news:9ed2390b-2ae7-4bcd-9df1-2a4a4097c8bd[ at ]i20g2000prf.googlegroups.com... <snip> that means I will have to give a new sink for every button and register/unregister for the events (for each button added)
|
|
On Nov 14, 3:39 pm, "Ken Slovak - [MVP - Outlook]" <kenslo...[ at ]mvps.org> wrote:
[Quoted Text] > Yes, that's what I've been telling you. > > -- > 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> > "Exchnerd" <sanjur...[ at ]gmail.com> wrote in message > > news:9ed2390b-2ae7-4bcd-9df1-2a4a4097c8bd[ at ]i20g2000prf.googlegroups.com... > <snip> > that means I will have to give a new sink for every button and > register/unregister for the events (for each button added) Thanks! It works now with 2 entry for the SINK and 2 DispEventAdvise
|
|
On Nov 14, 4:07 pm, Exchnerd <sanjur...[ at ]gmail.com> wrote:
[Quoted Text] > On Nov 14, 3:39 pm, "Ken Slovak - [MVP - Outlook]" > > <kenslo...[ at ]mvps.org> wrote: > > Yes, that's what I've been telling you. > > > -- > > 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> > > "Exchnerd" <sanjur...[ at ]gmail.com> wrote in message > > >news:9ed2390b-2ae7-4bcd-9df1-2a4a4097c8bd[ at ]i20g2000prf.googlegroups.com.... > > <snip> > > that means I will have to give a new sink for every button and > > register/unregister for the events (for each button added) > > Thanks! It works now with 2 entry for the SINK and 2 DispEventAdvise You can use the same object for multiple sinks, like so:
class CButtonEventSink : public IDispEventSimpleImpl</*nID =*/ 1, CButtonEventSink, &__uuidof (Office::_CommandBarButtonEvents)>, public IDispEventSimpleImpl</*nID =*/ 2, CButtonEventSink, &__uuidof (Office::_CommandBarButtonEvents)>
And then: IDispEventSimpleImpl< 1, CButtonEventSink, &__uuidof (Outlook::CommandBarButtonEvents)>::DispEventAdvise( mButton1); IDispEventSimpleImpl< 2, CButtonEventSink, &__uuidof (Outlook::CommandBarButtonEvents)>::DispEventAdvise( mButton2);
However, while I've tried to be economical with regard to the number of objects, I usually find in the end that with ATL and Outlook add- ins that you're better off creating one sink object per OOM object.
P.S. Don't forget to override AddRef/Release, especially for your button event sinks.
|
|
On Nov 15, 12:21 am, cainran...[ at ]gmail.com wrote:
[Quoted Text] > On Nov 14, 4:07 pm, Exchnerd <sanjur...[ at ]gmail.com> wrote: > > > > > On Nov 14, 3:39 pm, "Ken Slovak - [MVP - Outlook]" > > > <kenslo...[ at ]mvps.org> wrote: > > > Yes, that's what I've been telling you. > > > > -- > > > 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> > > > "Exchnerd" <sanjur...[ at ]gmail.com> wrote in message > > > >news:9ed2390b-2ae7-4bcd-9df1-2a4a4097c8bd[ at ]i20g2000prf.googlegroups.com.... > > > <snip> > > > that means I will have to give a new sink for every button and > > > register/unregister for the events (for each button added) > > > Thanks! It works now with 2 entry for the SINK and 2 DispEventAdvise > > You can use the same object for multiple sinks, like so: > > class CButtonEventSink : > public IDispEventSimpleImpl</*nID =*/ 1, CButtonEventSink, &__uuidof > (Office::_CommandBarButtonEvents)>, > public IDispEventSimpleImpl</*nID =*/ 2, CButtonEventSink, &__uuidof > (Office::_CommandBarButtonEvents)> > > And then: > IDispEventSimpleImpl< 1, CButtonEventSink, &__uuidof > (Outlook::CommandBarButtonEvents)>::DispEventAdvise( mButton1); > IDispEventSimpleImpl< 2, CButtonEventSink, &__uuidof > (Outlook::CommandBarButtonEvents)>::DispEventAdvise( mButton2); > > However, while I've tried to be economical with regard to the number > of objects, I usually find in the end that with ATL and Outlook add- > ins that you're better off creating one sink object per OOM object. > > P.S. Don't forget to override AddRef/Release, especially for your > button event sinks. Yes, I had done the same. I was wondering if 1 sink was enough for all the buttons! Thanks for your help,
|
|
|