|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionAdding an Event Handler for the Button created in previous tutorialIn the previous tutorials, we have seen how to add a toolbar and thus create a button in Microsoft Outlook. Now, in this tutorial, we will see how to invoke an event handler for the button, or in terms of COM, how to advise the Button event!. The idea behind this tutorial is simple, we need to display a message box saying, "Button Clicked", when we click on the button created. For this, we have to capture the Button Click Event, i.e., CommandBar Events. The disp interface responsible for this is IDispEventSimpleImpl<>So, here we have to create a connection point between our button and interface in simple words. The class ATL_NO_VTABLE CAddin :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CAddin, &CLSID_Addin>,
public IDispatchImpl<IAddin, &IID_IAddin, &LIBID_OUTLOOKADDINLib>,
public IDispatchImpl<_IDTExtensibility2,
&IID__IDTExtensibility2, &LIBID_AddInDesignerObjects>,
//the derivation is done here
public IDispEventSimpleImpl<1,CAddin,
&__uuidof(Office::_CommandBarButtonEvents)>
Parameters:
A Simple Shortcut:Now, we do a simple shortcut to make our job easier. We add this code before the constructor in our file: public: //the added code is here typedef IDispEventSimpleImpl</*nID =*/ 1, CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandButton1Events; CAddin() { } As we can see, this can help in advising our sink since we are doing Sink Entry:In order to move with sinks, we have to have entries for our event notifications to be handled by their proper functions as we have for Messages in MFC and Win32. So, we need to enter the SINK ENTRY as follows after BEGIN_SINK_MAP(CAddin) SINK_ENTRY_INFO(1, __uuidof(Office::_CommandBarButtonEvents),0x01, OnClickButton, &OnClickButtonInfo) END_SINK_MAP() in SINK_ENTRY_INFO We have specified our unique identifier, IID identifying the dispatch interface, dispid identifying the specified event, name of the event handler function, and the last parameter corresponds to type information. This is provided in the form of _ATL_FUNC_INFO OnClickButtonInfo =
{CC_STDCALL,VT_EMPTY,2,{VT_DISPATCH,VT_BYREF | VT_BOOL}};
Setting up our CallBack:
That's it....we have completed our second tutorial of getting a message box when we press the button...hmm...it looks so simple and sure it is. Since this is my first step in writing tutorials, please do feel free to send your reviews to chakkaradeepcc@yahoo.com. Credits:
A small request to Amit Dey....any contact number or address or mail-id?
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||