使用Windows API获取文件关联 [英] Getting File Associations using Windows API

查看:585
本文介绍了使用Windows API获取文件关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个基于控制台的文件浏览器的Windows C ++和我有困难,一起上下文菜单,列出与文件相关联的操作和调用命令。现在最大的问题是获取与文件类型绑定的操作。



我知道在HKEY_CLASSES_ROOT中打开和调整注册表项的进程,但我找不到



注册表中这些关联的一般结构是:


HKEY_CLASSES_ROOT\(扩展名)\(默认) - 文件类型

HKEY_CLASSES_ROOT\filetype\的文件类型

HKEY_CLASSES_ROOT\filetype\shell\action\(默认) - 操作的描述

HKEY_CLASSES_ROOT\filetype\ shell\action\command \(default) - 在文件上调用命令


我想知道是否有一种方法(希望使用Windows API)我可以获得与文件类型相关联的所有操作。至少我可以检查这些动作在注册表中的命令...



此外,这种方法似乎不适用于一些常见的文件类型)在我的系统上,默认键为空白,另一个键(PercievedType)设置为音频...如何获得这样的操作?



<最后,如果有一个更好的方式来做这一般,我很想听到它,我一般讨厌处理注册表。我更愿意有一个简单的windows调用,它会让我的行动和命令...

解决方案

考虑使用 IContextMenu 。 IContextMenu是Windows资源管理器如何访问文件和项目的上下文菜单。



文章 by Raymond Chen有一个示例代码,用于如何访问给定文件路径的IContextMenu,并使用它为一个HMENU填充一组可用的命令。这是一系列文章中的第一个,提供了一个体面的概述以及示例代码。


I'm working on a console based file browser for Windows in C++ and am having difficulties getting together a context menu that lists actions associated with a file and calls commands on them. The biggest issue right now is getting the actions tied to the file types.

I know of the process to open and tweak the registry keys in HKEY_CLASSES_ROOT but I can't find a way to actually get the actions and their commands so I can build a context menu out of it.

The general structure of these associations in the registry is:

HKEY_CLASSES_ROOT\(extension)\(default) - filetype
HKEY_CLASSES_ROOT\filetype\(default) - description of the filetype
HKEY_CLASSES_ROOT\filetype\shell\action\(default) - description of the action
HKEY_CLASSES_ROOT\filetype\shell\action\command\(default) - command called on file

I'm wondering if there is a way (hopefully using the Windows API) that I can get all of the actions associated with a file type. At least then I can check those actions for their commands in the registry...

Also, this approach doesn't seem to work with some common file types (e.g. mp3) on my system as the default key is left blank and another key ("PercievedType") is set to audio... How can I get the actions for something like this?

Lastly, if there is a better way to do this in general I would love to hear it, I generally hate dealing with the registry. I would much rather have a simple windows call that would get me the actions and commands...

解决方案

Consider using IContextMenu. IContextMenu is how Windows Explorer accesses the context menu for files and items.

This article by Raymond Chen has sample code for how to access IContextMenu for a given file path and use it to fill an HMENU with the set of available commands. It's the first of a series of articles that give a decent overview along with sample code.

这篇关于使用Windows API获取文件关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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