打开具有特定扩展名的文件的API是什么? [英] What is the api to open files with specific extension?

查看:114
本文介绍了打开具有特定扩展名的文件的API是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用默认的Windows程序打开文件的api.
例如,如果我的Windows PDF将由acrobat打开,则api将指向该程序,可以重新命名api的名称吗?

Hi i know about an api to open files, with default windows program.
For istance if in my Windows PDF will be open by acrobat the api will be point to that program, can you rembmer the api name?

推荐答案

这是ShellExecute http://msdn.microsoft.com/en -us/library/windows/desktop/bb762153%28v = vs.85%29.aspx [ http://msdn. microsoft.com/en-us/library/windows/desktop/bb762154%28v=vs.85%29.aspx [
This is ShellExecute, http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx[^].

See also ShellExecuteEx, http://msdn.microsoft.com/en-us/library/windows/desktop/bb762154%28v=vs.85%29.aspx[^].

—SA


如果要使用程序(或任何其他文件)打开文件扩展名,则必须在注册表中添加条目.

如果使用的是MFC,请在向导的文档模板属性",文件扩展名"中添加扩展名(例如"zzz"),然后它会自行生成代码.

在注册表中,shell打开操作在HKEY_CLASSES_ROOT/.zzz中进行.

如果您有MFC项目,则注册会在CWinApp :: RegisterShellFileTypes中进行.

MFC生成的.reg类似于:
If you want the file extension to be opened with your program (or any other), you must add entries in the registry.

If you''re using MFC, in the wizard, in "Document Template Properties", "File Extension", you add the extension (for example "zzz") and it generates the code itself.

In the registry, the shell open operations go in HKEY_CLASSES_ROOT/.zzz.

If you have an MFC project, the registration occurs in CWinApp::RegisterShellFileTypes.

The .reg the MFC generates looks something like:
REGEDIT
; This .REG file may be used by your SETUP program.
;   If a SETUP program is not available, the entries below will be
;   registered in your InitInstance automatically with a call to
;   CWinApp::RegisterShellFileTypes and COleObjectFactory::UpdateRegistryAll.

HKEY_CLASSES_ROOT\.zzz = DDZ.Document
HKEY_CLASSES_ROOT\DDZ.Document\shell\open\command = DDZ.EXE %1
HKEY_CLASSES_ROOT\DDZ.Document\shell\open\ddeexec = [open("%1")]
HKEY_CLASSES_ROOT\DDZ.Document\shell\open\ddeexec\application = DDZ
    ; note: the application is optional
    ;  (it defaults to the app name in "command")

HKEY_CLASSES_ROOT\DDZ.Document = DDZ.Document



如果您确实需要非常复杂的文件扩展名管理,则应创建一个shell扩展dll.在CodeProject上有一篇很棒的文章:


编写外壳扩展的完整白痴指南-索引 [ ^ ]



If you really want really complex file extension management, you should create a shell extension dll. There is an excelent article on CodeProject:


The Complete Idiot''s Guide to Writing Shell Extensions - Index[^]


正如SAKryukov所说的,您可以使用ShellExecute,请确保初始化COM.
As SAKryukov said you can use ShellExecute, Make sure to initialize COM.


这篇关于打开具有特定扩展名的文件的API是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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