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

本文是小编为大家收集整理的关于打开具有特定扩展名的文件的api是什么?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

您好,我知道一个使用默认 windows 程序打开文件的 api.
例如,如果在我的 Windows 中 PDF 将由 acrobat 打开,api 将指向该程序,你能记住 api 名称吗?

推荐答案

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

另请参见 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 类似于:
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上有一篇优秀的文章:


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

正如 SAKryukov 所说,您可以使用 ShellExecute,请务必初始化 COM.

本文地址:https://www.itbaoku.cn/post/1395121.html

问题描述

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?

推荐答案

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

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


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[^]

As SAKryukov said you can use ShellExecute, Make sure to initialize COM.