我有一个功能区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"/>
请帮忙......
答案 0 :(得分: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;
}
}