2

我有一个功能区 xml,在单击按钮时,我必须为各个按钮打开两个不同的窗口窗体,但我无法在同一个文件中定义两个不同的按钮单击功能。
xml:我有两个按钮,代码是

STDMETHOD(ButtonClicked)(IDispatch* ribbon)
    {//MessageBoxW(NULL,L"Button Clicked!",L"NativeAddin",MB_OK);
        NativeAddIn::ApplicationConfiguration ^appConfigurationform = gcnew NativeAddIn::ApplicationConfiguration();
        appConfigurationform->ShowDialog();
        return S_OK;
    }
STDMETHOD(ButtonClicked)(IDispatch* ribbon)
    {
        //MessageBoxW(NULL,L"Button Clicked!",L"NativeAddin",MB_OK);
        NativeAddIn::Helpme ^helpmeobj = gcnew NativeAddIn::Helpme();
        helpmeobj->ShowDialog();
        return S_OK;
    } 

我如何在按钮单击时编写两个函数。在执行上面的代码时,错误来了:

HRESULT CConnect::ButtonClicked(IDispatch *)' : 成员函数已定义或声明。

<button id="GoToAppConfiguration" size="large" label="Application Configuration" imageMso="AutoArchiveSettings" onAction="ButtonClicked"/> 
<button id="GoToAppHelp" size="large" label="Help" imageMso="CreateReportFromWizard" onAction="ButtonClicked"/>

请帮忙....

4

1 回答 1

2

ButtonClicked您可以在“帮助”按钮中使用不同的名称。

<button id="GoToAppHelp" size="large" label="Help" imageMso="CreateReportFromWizard" onAction="ButtonHelpClicked"/>
STDMETHOD(ButtonHelpClicked)(IDispatch* ribbon)
{
    //MessageBoxW(NULL,L"Button Clicked!",L"NativeAddin",MB_OK);
    NativeAddIn::Helpme ^helpmeobj = gcnew NativeAddIn::Helpme();
    helpmeobj->ShowDialog();
    return S_OK;
} 

对此的替代方法是使用IRibbonControl上下文(ribbon参数)并请求控件 ID 来触发 switch 语句。您将只有一个ButtonClicked方法来处理所有按钮点击。

STDMETHOD(ButtonClicked)(IDispatch* ribbon)
{
    switch (ribbon.Id)
    {
     case "GoToAppConfiguration" : 
        //MessageBoxW(NULL,L"Button Clicked!",L"NativeAddin",MB_OK);
         NativeAddIn::ApplicationConfiguration ^appConfigurationform = gcnew   NativeAddIn::ApplicationConfiguration();
         appConfigurationform->ShowDialog();
         return S_OK;
     case "GoToAppHelp" : 
        //MessageBoxW(NULL,L"Button Clicked!",L"NativeAddin",MB_OK);
        NativeAddIn::Helpme ^helpmeobj = gcnew NativeAddIn::Helpme();
        helpmeobj->ShowDialog();
        return S_OK;
    }   
} 
于 2012-04-26T14:47:29.390 回答