简体   繁体   English

Outlook 加载项 VSTO - 挂钩点击现有按钮

[英]Outlook Add-In VSTO - Hook into click of existing button

I'm currently trying to develop an Outlook Add-In that extends an already existing function. To get it work, I need to hook into the On-Click-Event of an existing button (I have the IdMso of it), and execute additional code.我目前正在尝试开发一个 Outlook 插件,它扩展了一个已经存在的 function。为了让它工作,我需要连接到一个现有按钮的 On-Click-Event(我有它的 IdMso),然后执行附加代码。 Is that possible, and if so, how?这可能吗?如果可能的话,怎么做? I'm using C# as programming language.我使用 C# 作为编程语言。

Yes, it is possible to repurpose built-in controls.是的,可以重新调整内置控件的用途。 The commands element in the ribbon XML can do the trick, for example:功能区 XML 中的commands元素可以解决这个问题,例如:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
   onLoad="OnLoad" > 
   <commands> 
     <command idMso="FileSave" onAction="mySave" /> 
   </commands> 
   <ribbon startFromScratch="false"> 
     <tabs> 
       <tab id="tab1" label="Repurpose Command Demo" > 
         <group id="group1" label="Demo Group"> 
           <toggleButton id="togglebutton1"  
             imageMso="AcceptInvitation"  
             size="large"  
             label="Alter Built-ins"  
             onAction="changeRepurpose" /> 
         </group> 
       </tab> 
     </tabs> 
   </ribbon> 
</customUI>

This sample creates a reference to the save file functionality in Microsoft Office by using the command element.此示例使用 command 元素创建对 Microsoft Office 中保存文件功能的引用。 You can determine that this component includes a reference functionality built into Microsoft Office through its use of the idMso attribute.通过使用 idMso 属性,您可以确定此组件包含内置于 Microsoft Office 中的引用功能。

For ribbon buttons the callback looks like that:对于功能区按钮,回调看起来像这样:

C#: void OnAction(IRibbonControl control, ref bool CancelDefault)

VBA: Sub OnAction(control As IRibbonControl, byRef CancelDefault)

C++: HRESULT OnAction([in] IRibbonControl *pControl, [in,out] VARIANT _BOOL *fCancelDefault)

Visual Basic: Sub OnAction(control As IRibbonControl, byRef CancelDefault)

And for the toggleButton control:对于toggleButton控件:

C#: void OnAction(IRibbonControl control, bool pressed, ref bool cancelDefault)

VBA: Sub OnAction(control As IRibbonControl, pressed As Boolean, byRef cancelDefault)

C++: HRESULT OnAction([in] IRibbonControl *pControl, [in] VARIANT_BOOL *pvarfPressed, [in,out] VARIANT _BOOL *fCancelDefault)

Visual Basic: Sub OnAction(control As IRibbonControl, pressed As Boolean, byRef CancelDefault)

See Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.有关详细信息,请参阅临时重新利用 Office Fluent 功能区上的命令


By default, if a VSTO Add-in attempts to manipulate the Microsoft Office user interface (UI) and fails, no error message is displayed.默认情况下,如果 VSTO 外接程序尝试操作 Microsoft Office 用户界面 (UI) 但失败,则不会显示任何错误消息。 However, you can configure Microsoft Office applications to display messages for errors that relate to the UI.但是,您可以将 Microsoft Office 应用程序配置为显示与 UI 相关的错误消息。 You can use these messages to help determine why a custom ribbon does not appear, or why a ribbon appears but no controls appear.您可以使用这些消息来帮助确定自定义功能区未出现的原因,或者显示功能区但未显示控件的原因。 See How to: Show Add-in user interface errors for more information.有关详细信息,请参阅如何:显示加载项用户界面错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM