本文介绍了Office :: _ ClickBarButton的click事件在MS Outlook的新资源管理器窗口中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



您好


我正在为MS Outlook创建一个COM AddIn,它在命令栏中创建一个按钮MS Outlook;当MS Outlook正常打开时,MS Outlook命令栏中的按钮显示完美,按钮的点击事件也正常工作但是当用户在新窗口中打开另一个日历/邮件视图然后单击事件时,
命令栏中的按钮不起作用。


我已经实现了Outlook :: ExplorersEvents接口的OnNewExplorer事件;实现的源代码如下:


void __stdcall OnNewExplorer(IDispatch * pExplorer)

   {

        //开始

       但是CComPtr<展望:: _资源管理器> spExplorer((Outlook :: _ ExplorerPtr)pExplorer);

        // spExplorer = pExplorer;

        CComPtr<处:: _的CommandBars> spCmdBars;

        CComPtr<办公室::命令​​栏> spCmdBar;

        HRESULT hr = spExplorer-> get_CommandBars(& spCmdBars);

        if(FAILED(hr)){

           返回;

        }
        ATLASSERT(spCmdBars);

        spCmdBar = spCmdBars->项目[CComVariant(STANDARD_E)];

        VARIANT vtTag;

        vtTag.vt = VT_BSTR;

        vtTag.bstrVal = SysAllocString(_T(" Test2")));


        Office :: CommandBarControl * pButton = NULL;

        pButton = spCmdBar-> FindControl(vtMissing,vtMissing,vtTag,vtMissing,vtMissing);

        if(pButton == NULL){

            CComPtr<办公室:: CommandBarControls> spBarControls;

            spBarControls = spCmdBar-> GetControls();

            ATLASSERT(spBarControls);

            CComPtr<办公室::的CommandBarControl> spNewBar;&NBSP;


            CComVariant vToolBarType(1);

            //显示工具栏?

            CComVariant vShow(VARIANT_TRUE);

            CComVariant vEmpty(DISP_E_PARAMNOTFOUND,VT_ERROR);

            //添加第一个按钮

            spNewBar = spBarControls-> Add(vToolBarType,vEmpty,vEmpty,vEmpty,vShow);


            ATLASSERT(spNewBar);

            _bstr_t bstrNewCaption(CAPTION_J),bstrToolTip(TOOLTIP_J),
bstrTag(_T(" Test2") / * NAME_E * /);

   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; CComQIPtr<处:: _ CommandBarButton的> spCmdButton(spNewBar);

            ATLASSERT(spCmdButton);

            spCmdButton-> PutStyle(Office :: msoButtonCaption);

            spCmdButton-> PutVisible(VARIANT_TRUE);

            spCmdButton-> PutCaption(bstrNewCaption);

            spCmdButton-> PutEnabled(VARIANT_TRUE);

            spCmdButton-> PutTooltipText(bstrToolTip);

            spCmdButton-> PutTag(bstrTag);

            //但是CComPtr<办公:: _的CommandBarButton> spButton = spCmdButton;

            m_spButton1 = spCmdButton;

            //显示工具栏

            spCmdBar-> PutVisible(VARIANT_TRUE);

            hr = CommandButton1Events :: DispEventAdvise((IDispatch *)m_spButton1);

       


}


实现OnConnection的代码如下:


spCmdBar = spCmdBars->项目[CComVariant(STANDARD_E)];
$
        VARIANT vtTag;

        vtTag.vt = VT_BSTR;

        vtTag.bstrVal = SysAllocString(_T(" Test1"););


        Office :: CommandBarControl * pButton = NULL;

        pButton = spCmdBar->的FindControl(vtMissing,vtMissing,vtTag,vtMissing,vtMissing);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; if(pButton == NULL){

            CComPtr<办公室:: CommandBarControls> spBarControls;

            spBarControls = spCmdBar-> GetControls();

            ATLASSERT(spBarControls);

            CComPtr<办公室::的CommandBarControl> spNewBar;&NBSP;


            CComVariant vToolBarType(1);

            //显示工具栏?

            CComVariant vShow(VARIANT_TRUE);

            CComVariant vEmpty(DISP_E_PARAMNOTFOUND,VT_ERROR);

            //添加第一个按钮

            spNewBar = spBarControls-> Add(vToolBarType,vEmpty,vEmpty,vEmpty,vShow);


            ATLASSERT(spNewBar);

            _bstr_t bstrNewCaption(CAPTION_J),bstrToolTip(TOOLTIP_J)
bstrTag(_T(QUOT;测试1"));

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; CComQIPtr<处:: _ CommandBarButton的> spCmdButton(spNewBar);

            ATLASSERT(spCmdButton);

            spCmdButton-> PutStyle(Office :: msoButtonCaption);

            spCmdButton-> PutVisible(VARIANT_TRUE);

            spCmdButton-> PutCaption(bstrNewCaption);

            spCmdButton-> PutEnabled(VARIANT_TRUE);

            spCmdButton-> PutTooltipText(bstrToolTip);

            spCmdButton-> PutTag(bstrTag);

            m_spButton = spCmdButton;

            //显示工具栏

            spCmdBar-> PutVisible(VARIANT_TRUE);

            hr = CommandButton1Events :: DispEventAdvise((IDispatch *)m_spButton);

            if(FAILED(hr)){

               返回小时;

            }
        }


因此当MS Outlook正常打开时,我们的按钮将出现在MS Outlook的命令栏中,按钮的单击事件也正常工作;但是,当用户打开新窗口一个日历/邮件视图然后空隙__stdcall OnNewExplorer(IDispatch的*
pExplorer)将被调用,函数OnNewExplorer在下面的行获取崩溃:


HR = CommandButton1Events :: DispEventAdvise((IDispatch的*)m_spButton1); //在此行崩溃


当上面提到的行从OnNewExplorer函数中删除然后在新窗口中打开日历/邮件视图时,我们的按钮将出现在新的命令栏中创建窗口,但按钮的单击事件不起作用(未调用处理器
按钮单击事件)。


两个按钮的标记不同,在上面突出显示源代码。


请建议按钮的点击事件(在新的资源管理器窗口中)是如何工作的。


 


谢谢


Ashish

解决方案

Hi

I am creating a COM AddIn for MS Outlook which creates a button in the command bar of MS Outlook; when MS Outlook is opened normally then Button in the command bar of MS Outlook is displayed perfectly and click event for the button is also working fine but when user opens the another calendar/mail view in new window then click event for our button in command bar not works.

I have implemented the OnNewExplorer event of Outlook::ExplorersEvents interface; source code for the implementation is as follows:

void __stdcall OnNewExplorer(IDispatch* pExplorer)
   {
        //Start
        CComPtr<Outlook::_Explorer> spExplorer((Outlook::_ExplorerPtr)pExplorer);
        //spExplorer = pExplorer;
        CComPtr < Office::_CommandBars> spCmdBars;
        CComPtr < Office::CommandBar> spCmdBar;
        HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
        if(FAILED(hr)) {
            return ;
        }
        ATLASSERT(spCmdBars);
        spCmdBar = spCmdBars->Item[CComVariant(STANDARD_E)];
        VARIANT vtTag;
        vtTag.vt = VT_BSTR;
        vtTag.bstrVal = SysAllocString(_T("Test2"));
        Office::CommandBarControl *pButton = NULL;
        pButton = spCmdBar->FindControl(vtMissing, vtMissing, vtTag, vtMissing, vtMissing);
        if(pButton==NULL) {
            CComPtr < Office::CommandBarControls> spBarControls;
            spBarControls = spCmdBar->GetControls();
            ATLASSERT(spBarControls);
            CComPtr < Office::CommandBarControl> spNewBar; 
            CComVariant vToolBarType(1);
            //show the toolbar?
            CComVariant vShow(VARIANT_TRUE);
            CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
            // add first button
            spNewBar = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty, vShow);
            ATLASSERT(spNewBar);
            _bstr_t bstrNewCaption(CAPTION_J), bstrToolTip(TOOLTIP_J),bstrTag(_T("Test2") /*NAME_E*/);
            CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);
            ATLASSERT(spCmdButton);
            spCmdButton->PutStyle(Office::msoButtonCaption);
            spCmdButton->PutVisible(VARIANT_TRUE);
            spCmdButton->PutCaption(bstrNewCaption);
            spCmdButton->PutEnabled(VARIANT_TRUE);
            spCmdButton->PutTooltipText(bstrToolTip);
            spCmdButton->PutTag(bstrTag);
            //CComPtr<Office::_CommandBarButton> spButton = spCmdButton;
            m_spButton1 = spCmdButton;
            //show the toolband
            spCmdBar->PutVisible(VARIANT_TRUE);
            hr = CommandButton1Events::DispEventAdvise((IDispatch*)m_spButton1);
        }

}

code for implemntation of OnConnection is as follows:

spCmdBar = spCmdBars->Item[CComVariant(STANDARD_E)];
        VARIANT vtTag;
        vtTag.vt = VT_BSTR;
        vtTag.bstrVal = SysAllocString(_T("Test1"));
        Office::CommandBarControl *pButton = NULL;
        pButton = spCmdBar->FindControl(vtMissing, vtMissing, vtTag, vtMissing, vtMissing);
        if(pButton==NULL) {
            CComPtr < Office::CommandBarControls> spBarControls;
            spBarControls = spCmdBar->GetControls();
            ATLASSERT(spBarControls);
            CComPtr < Office::CommandBarControl> spNewBar; 
            CComVariant vToolBarType(1);
            //show the toolbar?
            CComVariant vShow(VARIANT_TRUE);
            CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
            // add first button
            spNewBar = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty, vShow);
            ATLASSERT(spNewBar);
            _bstr_t bstrNewCaption(CAPTION_J), bstrToolTip(TOOLTIP_J),bstrTag(_T("Test1")) ;
            CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);
            ATLASSERT(spCmdButton);
            spCmdButton->PutStyle(Office::msoButtonCaption);
            spCmdButton->PutVisible(VARIANT_TRUE);
            spCmdButton->PutCaption(bstrNewCaption);
            spCmdButton->PutEnabled(VARIANT_TRUE);
            spCmdButton->PutTooltipText(bstrToolTip);
            spCmdButton->PutTag(bstrTag);
            m_spButton = spCmdButton;
            //show the toolband
            spCmdBar->PutVisible(VARIANT_TRUE);
            hr = CommandButton1Events::DispEventAdvise((IDispatch*)m_spButton);
            if(FAILED(hr)) {
                return hr;
            }
        }

So when the MS Outlook opened normally then our button will be appeared in the command bar of MS Outlook and click event for the button is also working fine; but when user opens a calendar/Mail view in new window then void __stdcall OnNewExplorer(IDispatch* pExplorer) will be called and function OnNewExplorer gets crash at following line:

hr = CommandButton1Events::DispEventAdvise((IDispatch*)m_spButton1); //crash at this line

when above mentioned line is removed from the function OnNewExplorer then while opening the calendar/Mail view in new window then our button will be appeared in the command bar of newly created window but click event for the button is not works (handler of button click event is not called).

Tag for both the buttons are different which are highlighted in the above source code.

Please suggest how the click event for the button (in new explorer window) will be workable.

Thanks

Ashish

解决方案


这篇关于Office :: _ ClickBarButton的click事件在MS Outlook的新资源管理器窗口中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 17:49