替换COM加载项中的Word的打开文件对话框 [英] Replacing Word's Open File Dialog in a COM Add-in

查看:378
本文介绍了替换COM加载项中的Word的打开文件对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个Word COM加载项,取代Open&用我自己保存对话框。

I'm writing a Word COM Add-in that replaces the Open & Save dialogs with my own.

对于保存对话框,我处理来自应用程序事件的documentBeforeSave事件。这工作正常。

For the save dialog, I'm handling the documentBeforeSave event from the application events. This works fine.

对于打开的对话框,没有这样的事件,所以我目前正在处理Open ...菜单项的onClick,取消默认处理。如果用户确实使用这个菜单项,这个工作确定,但是如果用户按CTRL-O代替他们仍然得到原始的对话框。

For the open dialog, there is no such event, so I'm currently handling the onClick of the Open... menu item, canceling the default handling. This works ok if the user indeed uses this menu item, but if the user presses CTRL-O in stead they still get the original dialog.

有更好的方法hook到这个对话框中?如果没有,有没有办法优雅地处理这种按键,或者我应该解决键盘钩子?

Is there a better way to hook into this dialog? And if there isn't, is there a way to elegantly handle this keypress, or should I resolve to keyboard hooks?

注意:加载项应该最终在Office 2003,2007和2010上工作,但是在不同目标上使用不同的代码路径当然是完美的。我对任何版本的任何解决方案感兴趣。

Note: The add-in should eventually work on Office 2003, 2007 and 2010, but using different code-paths on different targets is of course perfectly fine. I am interested in any solutions on any version.

推荐答案

在Word 2007+中,实现起来非常简单。只需通过功能区XML

In Word 2007+, this turns out to be incredibly simple to implement. Simply repurpose the FileOpen command through the ribbon XML

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <commands>
    <command idMso="FileOpen" onAction="doOpen" />
  </commands>
  ...

doOpen方法有两个参数,第二个是in /

The doOpen method then has two parameters, the second being an in/out parameter allowing you to cancel the event.

对于以前版本的Office,我从未实现完全防弹的解决方案。

For previous version of Office, I've never implemented a fully bulletproof solution.

这篇关于替换COM加载项中的Word的打开文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆