I
Irfan Ahmed
I have inserted a menu is MS Word in Tools menu the position is 2nd last.
Below is the code that is adding menu in the Tools menu and the function
which should be called when user clicks my menu.
button handler code to attach my menu in Tools menu.
CComPtr <CommandBarControl> spCmdBarCtrl1;
CComQIPtr<_CommandBarButton>spNewMenu;
int controls;
spCmdBarCtrlsm->get_Count (&controls);
CComVariant ind = controls ;
//spCmdBarCtrls->get_Item(ind, &spCmdBarCtrl);
spCmdBarCtrlsm->get_Item(CComVariant(mszSDD), &spCmdBarCtrl1);
// spCmdBarCtrls->get_Item(CComVariant(misz1), &spCmdBarCtrl2);
// BSTR pbstronact;
/* int hi;
spCmdBarCtrl1->get_Index (&hi);
*/
//spCmdBarCtrl2->get_TooltipText (&pbstronact);
//MessageBox(NULL,pbstronact,L"ok",TRUE);
//spCmdBarCtrl->get_Caption (&cpbst);
if(spCmdBarCtrl1){
// MessageBox(NULL,"option here","Ok",TRUE);
spNewMenu=spCmdBarCtrl1;
}
else
{
// now create the actual menu item and add it
//spCmdBarCtrls->Add (/*CComVariant(msoControlButton)*/vMenuType,
// CComVariant(1), cvEmpty, CComVariant(1), cvEmpty, ind,
vMenuTemp,&spCmdBarCtrl1);
//spCmdBarCtrl1=
spCmdBarCtrl1 = spCmdBarCtrlsm->Add (vMenuType, vMenuEmpty, vMenuEmpty,
ind, vMenuTemp);
// spCmdBarCtrl1=spCmdBarCtrls->Add (CComVariant(msoControlButton),
// CComVariant(1), cvEmpty, CComVariant(1), vMenuTemp);
// MessageBox(NULL,"option here if else","Ok",TRUE);
spNewMenu=spCmdBarCtrl1;
spNewMenu->put_Caption (L"Save Document DataBase");
//spNewMenu->put_Caption (CComBSTR(wszButton));
spNewMenu->put_Enabled (VARIANT_TRUE);
spNewMenu->put_Visible (VARIANT_TRUE);
}
// create click sink and advise button
CComObject<CButtonHandler>* pButtonHandler = 0;
HR(pButtonHandler->CreateInstance(&pButtonHandler));
HR(pButtonHandler->QueryInterface(IID_IUnknown,
(void**)&m_spUnkButtonHandler));
pButtonHandler->pIDispatchd = pIDispatchd;
DWORD m_dwSinkCookie;
spNewMenu.QueryInterface(&m_spUnkButton);
HR(AtlAdvise(m_spUnkButton, m_spUnkButtonHandler,
DIID__CommandBarButtonEvents, &m_dwSinkCookie));
This code is used for invoke function of button handler like given below
STDMETHODIMP CButtonHandler::Invoke(DISPID dispidMember, REFIID riid,
LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
EXCEPINFO* pexcepinfo, UINT* puArgErr){
................................
.....................
................
}
The problem is when user clicks my menu it does not call the "Invoke"
function.
Any help in the above code.
Irfan
Below is the code that is adding menu in the Tools menu and the function
which should be called when user clicks my menu.
button handler code to attach my menu in Tools menu.
CComPtr <CommandBarControl> spCmdBarCtrl1;
CComQIPtr<_CommandBarButton>spNewMenu;
int controls;
spCmdBarCtrlsm->get_Count (&controls);
CComVariant ind = controls ;
//spCmdBarCtrls->get_Item(ind, &spCmdBarCtrl);
spCmdBarCtrlsm->get_Item(CComVariant(mszSDD), &spCmdBarCtrl1);
// spCmdBarCtrls->get_Item(CComVariant(misz1), &spCmdBarCtrl2);
// BSTR pbstronact;
/* int hi;
spCmdBarCtrl1->get_Index (&hi);
*/
//spCmdBarCtrl2->get_TooltipText (&pbstronact);
//MessageBox(NULL,pbstronact,L"ok",TRUE);
//spCmdBarCtrl->get_Caption (&cpbst);
if(spCmdBarCtrl1){
// MessageBox(NULL,"option here","Ok",TRUE);
spNewMenu=spCmdBarCtrl1;
}
else
{
// now create the actual menu item and add it
//spCmdBarCtrls->Add (/*CComVariant(msoControlButton)*/vMenuType,
// CComVariant(1), cvEmpty, CComVariant(1), cvEmpty, ind,
vMenuTemp,&spCmdBarCtrl1);
//spCmdBarCtrl1=
spCmdBarCtrl1 = spCmdBarCtrlsm->Add (vMenuType, vMenuEmpty, vMenuEmpty,
ind, vMenuTemp);
// spCmdBarCtrl1=spCmdBarCtrls->Add (CComVariant(msoControlButton),
// CComVariant(1), cvEmpty, CComVariant(1), vMenuTemp);
// MessageBox(NULL,"option here if else","Ok",TRUE);
spNewMenu=spCmdBarCtrl1;
spNewMenu->put_Caption (L"Save Document DataBase");
//spNewMenu->put_Caption (CComBSTR(wszButton));
spNewMenu->put_Enabled (VARIANT_TRUE);
spNewMenu->put_Visible (VARIANT_TRUE);
}
// create click sink and advise button
CComObject<CButtonHandler>* pButtonHandler = 0;
HR(pButtonHandler->CreateInstance(&pButtonHandler));
HR(pButtonHandler->QueryInterface(IID_IUnknown,
(void**)&m_spUnkButtonHandler));
pButtonHandler->pIDispatchd = pIDispatchd;
DWORD m_dwSinkCookie;
spNewMenu.QueryInterface(&m_spUnkButton);
HR(AtlAdvise(m_spUnkButton, m_spUnkButtonHandler,
DIID__CommandBarButtonEvents, &m_dwSinkCookie));
This code is used for invoke function of button handler like given below
STDMETHODIMP CButtonHandler::Invoke(DISPID dispidMember, REFIID riid,
LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
EXCEPINFO* pexcepinfo, UINT* puArgErr){
................................
.....................
................
}
The problem is when user clicks my menu it does not call the "Invoke"
function.
Any help in the above code.
Irfan