本文介绍了如何将Windows应用程序与特定文件类型关联,但与其他应用程序共享该关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个新应用程序,并且与特定计算机上的.xml文件扩展名相关联,则当某人双击.xml文件时,它将启动我的应用程序并将该文件作为参数传递.但是Windows似乎知道还有哪些其他文件可以使用该文件类型.如何设置?

If I create a new app, and associate with, say, the .xml file extension on a particular computer, when someone double clicks the .xml file, it will launch my app and pass the file as parameter. But Windows seems to know what other files have the ability to work with that file type. How is that set up?

此外,当我将Microsoft Word文件另存为.xml文件,然后稍后双击该文件时,即使.xml文件类型与其他内容(例如Internet Explorer)相关联,它也会启动Microsoft Word. .似乎可能存在与.xml文件类型相关联的存根,该存根在被调用时会查看内容并启动适当的应用程序.

Also, when I save a Microsoft Word file as an .xml file, then later double-click on the file, it will launch Microsoft Word, even though the .xml file type is associated with something else, such as Internet Explorer. Seems like there may be a stub associated with .xml file type which when invoked looks at the content and launches the appropriate app.

是否有Windows API或某种标准的方法?

Is there a Windows API, or some kind of a standard way to do that?

我想要创建一个应用程序以完全执行Word的功能-即以.xml格式保存文件,但是双击后启动我的应用程序而不是Internet Explorer.

What I wanted to create an app to do exactly what Word is doing -- i.e. save file in the .xml format, but when double-clicked, launches the my app instead of Internet Explorer.

推荐答案

打开Office .xml文档的机制

对于以XML保存并具有.xml扩展名的Word文档,Microsoft实现了一个特殊的处理程序来在相应的应用程序中打开这些文件(此机制不仅用于Word文档,还用于Excel电子表格,InfoPath表单和某些其他格式).

Mechanism for opening Office .xml Documents

For Word documents saved in XML and having an .xml extensions Microsoft implemented a special handler to open these files in the corresponding application (This mechanism is not only used for Word documents, but also Excel spreadsheets, InfoPath forms and some other formats).

如果您检查注册表,您将看到扩展名为.xml的文件的文件类型设置为xmlfile:

If you check the Registry you will see that the file type for files with a .xml extension is set to xmlfile:

HKEY_CLASSES_ROOT\.xml (Default) = "xmlfile"

打开此文件类型时执行的命令在

The command that is executed when this file type is opened is specified under

HKEY_CLASSES_ROOT\xmlfile\shell\open\command = ""C:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSOXMLED.EXE" /verb open "%1""

因此,当在资源管理器中双击XML文件时,Windows将启动MSOXMLED.EXE.该应用程序现在正在XML文件中查找并搜索XML处理指令.此名为 mso-application 的处理指令可以指定ProgId:

So when an XML file is double-clicked in Explorer, Windows will launch MSOXMLED.EXE. This application is now looking inside the XML file and searches for an XML processing instruction. This processing instruction named mso-application can specify a ProgId:

<?mso-application progid="Word.Document"?>

如果找到此处理指令,并且ProgId是受支持的值之一,则MSOXMLED.EXE在注册表中搜索为该ProgId指定的打开命令.对于 Word.Document ,实际上实际上还有另一个重定向到 Word.Document12 (如果安装了Office 2007),它使用Word.Document的CurVer子项,因此最终得到: /p>

If this processing instruction is found and the ProgId is one of the supported values MSOXMLED.EXE searches the Registry for the open command specified for that ProgId. For Word.Document there is actually another redirect to Word.Document12 (if Office 2007 is installed) using the CurVer subkey of Word.Document, so we end up with:

HKEY_CLASSES_ROOT\Word.Document.12\shell\Open\command = ""C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /n /dde"

因此,最终,MSOXMLED.EXE将启动相应的Office应用程序或启动在以下指定的默认XML应用程序中

So finally MSOXMLED.EXE will start the appropriate Office application or launch the default XML application which is specified under

HKEY_CLASSES_ROOT\XEV.GenericApp\shell\open\command

您实际上可以通过从命令行调用MSOXMLED.EXE来进行尝试:

You can actually try this out by calling MSOXMLED.EXE from the command line:

MSOXMLED.EXE /verb OPEN "SampleWordMLDocument.xml"

如果要实现相同的行为,则必须实现MSOXMLED.EXE之类的处理程序,该处理程序在文件内部查找预定义的处理指令,然后将文档路由到适当的应用程序.

If you would like to implement the same behavior you would have to implement a handler like MSOXMLED.EXE which looks inside the file for a pre-defined processing instruction and then routes the document to the appropriate application.

以上我们介绍了如何处理文档打开和编辑的方式.另一种机制负责根据XML文档中的处理指令显示特定的图标: 图标处理程序 .

Above we looked at the way how document opening and editing is handled. Another mechanism is responsible for displaying a specific icon depending on the processing instruction inside the XML document: an icon handler.

图标处理程序是一种Explorer Shell扩展,它们是进程内COM对象,可以与某些文件类型关联.用于XML文件的文件在注册表中的

Icon handlers are a type of Explorer Shell extensions which are in-process COM objects which can be associated with certain file types. The one used for XML files is specified in the Registry under

HKEY_CLASSES_ROOT\xmlfile\ShellEx\IconHandler = "{AB968F1E-E20B-403A-9EB8-72EB0EB6797E}"

此GUID引用了MSOXEV.dll,它将类似于MSOXMLEX.EXE,检查XML文件中的ProgId,然后提供正确的图标.

This GUID is refering to the MSOXEV.dll which will - similarly to MSOXMLEX.EXE inspect the XML file for the ProgId and then provide the correct icon.

由于所有这是一个相当复杂的机制,因此如果要采用这种方式,则应仔细考虑.我认为注册一个新的唯一文件扩展名要简单得多.它也受到限制,因为它仅适用于允许您在文件头中包含一些自定义信息(例如ProgId)的文件类型.

As all this is a rather complicated mechanism you should consider carefully if you want to go this way. In my opinion it is far simpler to register a new unique file extension. It is also limited as it will only work with file types that allow you to include some custom information (as the ProgId) in the header of file.

Microsoft不再使用此方法,而是使用文件扩展名代替其新的OpenXML格式(请参阅为什么Office".xml"文件的行为与其他".xml"文件不同?).

Microsoft does not use this method anymore and uses file extensions instead for their new OpenXML formats (see Why do Office ".xml" files behave differently from other ".xml" files?).

这篇关于如何将Windows应用程序与特定文件类型关联,但与其他应用程序共享该关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:13
查看更多