KarthikOnIT 0 Newbie Poster

I'm (trying to) program an addin in VC++ (VS 2005) for Outlook 2003

How do I catch the event when the user clicks a button within the menu? Is
there a way to DispEventAdvise for the Office::CommandBarControls or the
Office::CommandBarPopup which "owns" the menu items?

My addin has a toolbar, which has a menu (Office::msoControlPopup).
I am able to listen to events when the user clicks on a button in my toolbar, but not when we clicks on a menu item(Office::msoControlPopup) in the toolbar
what should i do to listen to that event when user clicks on a menu in my toolbar.

Here is my sample code:
I have created a CEventWrapper class which implements IDispEventSimpleImpl Interface.

CEventWrapper.h

//Implemented a class from IDispEventSimpleImpl

class CEventWrapper :public IDispEventSimpleImpl<1,CEventWrapper ,&__uuidof( Office::_CommandBarButtonEvents)> 
{

  public:
  CEventWrapper (void);
  CEventWrapper ( Outlook::_ExplorerPtr spExplrPtr, Office::_CommandBarButtonPtr spCmdBrBtnPtr);
  CEventWrapper (void); 


  Office::_CommandBarButtonPtr m_spCmdBrBtnPtr;

}

typedef IDispEventSimpleImpl< CEventWrapper.h&__uuidof(Office::_CommandBarButtonEvents)> CmdBarBtnEvnts;


//Implemented Sink map.
BEGIN_SINK_MAP CEventWrapper 
  SINK_ENTRY_INFO(1, __uuidof(Office::_CommandBarButtonEvents),0x1, OnButtonClick , &OnButtonClickInfo)
END_SINK_MAP()

HRESULT __stdcall OnButtonClick(LPDISPATCH lpBtnDisp, VARIANT_BOOL *vbCancelDefault)
{
   //Event Handler

}

CEventWrapper.cpp

_ATL_FUNC_INFO OnButtonClickInfo ={CC_STDCALL,VT_EMPTY,2,{VT_DISPATCH,VT_BOOL}};

CEventWrapper ( Outlook::_ExplorerPtr spExplrPtr, Office::_CommandBarButtonPtr spCmdBrBtnPtr)
{
    CmdBarBtnEvnts::DispEventAdvise((IDispatch*)m_spCmdBrBtnPtr); //Attaching to the event source.
}


HRESULT __stdcall CButtonWrapper::OnButtonClick(LPDISPATCH lpBtnDisp, VARIANT_BOOL *vbCancelDefault)
{
  //B. Logic.
}


Adding "Office::msoControlPopup" to the toolbar.
{

   //Added from a different class in "OnConnection".. 

   Office::CommandBarControlPtr spCmdBrCtrlPtr;
   Office::CommandBarControlsPtr spCmdBrCtrlsPtr 


  spCmdBrCtrlPtr = spCmdBrCtrlsPtr->Add( vCtrlTyp, vMissng,vMissng,vMissng,vIsTempry);


  HRESULT hr = spCmdBrCtrlPtr->QueryInterface( __uuidof( Office::CommandBarPopup), 
            (void**)&m_spCmdBrPopupPtr);

   spCmdBrCtrlPtr = m_spCmdBrPopupPtr->Controls->Add(vCtrlTypBtn, vMissng, vMissng, vMissng, vIsTempry); 

   CmdBarBtnEvnts::DispEventAdvise( (LPDISPATCH)m_spCmdBrBtnPtr ); 
}

Thanks in Advance.