MS Word插件,添加一个右键单击所选文本时弹出的按钮

我正在为MS Word 2007创建一个共享插件。我想添加一个按钮,当右键单击选定的文本时弹出该按钮。附件快照应该清楚说明。 目前,用户必须选择文本,然后单击自定义控件上的按钮。如果在选择文本后,他/她可以右键单击它并按下弹出窗口中的相关按钮将会容易得多。     
已邀请:
您需要扩展正确的上下文菜单。以下链接用文字描述(无源代码)如何实现: 使用Word共享插件 也许这个链接可能对编码有所帮助。我自己没有试过,但它可能指向正确的方向。 祝好运! :) 编辑: 它必须是功能区样式上下文菜单还是普通上下文菜单中的按钮就足够了? 如果普通菜单没问题,你可以用这种方式(C#):
 Microsoft.Office.Core.CommandBar cb = this.Application.CommandBars["Text"];

 Office.CommandBarControl newButton = cb.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);  
 newButton.Caption = "Test";
 newButton.Visible = true;
 newButton.Enabled = true;
您可以使用VSTO执行此操作,我不太确定它是否与共享的插件技术完全相同,但它可能确实有帮助;)     
以下是如何做到这一点......
Microsoft.Office.Core.CommandBar cellbar = diff.CommandBars["Text"];
Microsoft.Office.Core.CommandBarButton button = (Microsoft.Office.Core.CommandBarButton)cellbar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, 0, "MYRIGHTCLICKMENU", Missing.Value, Missing.Value);
if (button == null)
{
   // add the button
   button = (Microsoft.Office.Core.CommandBarButton)cellbar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Missing.Value, Missing.Value, cellbar.Controls.Count + 1, true);
   button.Caption = "My Right Click Menu Item";
   button.BeginGroup = true;
   button.Tag = "MYRIGHTCLICKMENU";
   button.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(MyButton_Click);
}
    
来自MSDN -   您无法以编程方式修改Mini工具栏。 在医生的一半左右。在迷你工具栏上搜索。 编辑: 您在上图中圈出的弹出窗口不会出现右键单击,它会突出显示。上下文菜单(在所选文本下方)可以具有您的自定义功能,但不在迷你工具栏中。     
http://groups.google.com/group/microsoft.public.word.docmanagement/browse_thread/thread/cf55d996b3f51a06/65b2bad22e2a3583?lnk=st&q=Removing+Items+from+Word+2007是如何在VBA中完成的。使用COM非常相似,可能会创建一个单词加载项(虽然我没试过)你基本上需要找到上下文菜单控件并向其中添加一个项目(你的函数)。     

要回复问题请先登录注册