zoukankan      html  css  js  c++  java
  • 1、VS2005(c/c++)外壳扩展编程之windows右键菜单(1)

    第一部分 SHELL基本概念

        Windows外壳扩展(Windows Shell Extension),是一类特殊的COM对象,在这类COM对象中用户可以加入自己的特殊功能,而Windows外壳扩展最终都会被Windows Explorer所引用[1]

        A shell extension is a COM object that adds some kind of functionality to the Windows shell (Explorer).

        There are two parts in the term "shell extension." Shell refers to Explorer, and extension refers to code you write that gets run by Explorer when a predetermined event happens (e.g., a right-click on a .DOC file). So a shell extension is a COM object that adds features to Explorer.[7]

        A shell extension is an in-process server that implements some interfaces that handle the communication with Explorer. ATL is the easiest way to get an extension up and running quickly, since without it you'd be stuck writing QueryInterface() and AddRef() code over and over. It is also much easier to debug extensions on Windows NT-based OSes, as I will explain later.

        “Shell 扩展从字面上分两个部分:Shell ExtensionShell Windows Explorer,而Extension 则指由你编写的当某一预先约定好的事件(如在以. doc 为后缀的文件图标上单击右键)发生时由 Explorer调用执行的代码。因此一个“Shell 扩展就是一个为 Explorer 添加功能的 COM 对象。

        动态库必须注册才能使用。除了使用 regasm 来注册 DLL 以外,还应该在代码中增加 RegisterServer UnregisterServer 方法,以指导 DLL 注册时,在 Windows 注册表中增加什么键。关于具体键以下做简单说明:

        1) 注册DLLShell Extensions。具体位置是 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved,增加以 GUID 为名称的键,值则是动态库说明。(此位置里面全是 Shell 扩展的动态库注册,许多相关软件就是从里面获取信息,例如 ShexView

        2) 关联文件。Shell扩展一般是针对文件或者文件夹的,因此必须关联;许多人都熟知“HKEY_CLASSES_ROOT\*”的作用,就是用来关联所有文件。而文件夹则是“HKEY_CLASSES_ROOT\Folder”[3]

        我们所看到的资源管理器以及整个桌面,都是一个 Shell。在win32中是以外壳名字空间的形式来组织文件系统的,在外壳名字空间里的每一个对象()都实现了一个IShellFolder的接口,通过这个接口我们可以直接查询或间接得到其他相关的接口。

        (注:这里的对象指的是外壳名字空间中的一个节点,对象有可能是一个文件夹,有可能是一个文件,也有可能是一个虚拟文件夹,例如:我的电脑,网上邻居,控制面板等)[4]

        A shell extension is an in-process server that implements some interfaces that handle the communication with Explorer. ATL is the easiest way to get an extension up and running quickly, since without it you'd be stuck writing QueryInterface() and AddRef() code over and over. It is also much easier to debug extensions on Windows NT-based OSes[7]

        在外壳编程中,要使用 PIDL 路径代替普通路径桌面是最顶级的文件夹,外壳名字空间中其他各项都可以用从桌面开始的 PIDL 加以表示。

    通过API SHGetDesktopFolder获取桌面PIDL 和其 IShellFolder 接口。

    通过桌面,来获取“C:\”这个路径的 PIDL IShellFolder 接口,可以通过 IShellFolder ParseDisplayName BindToObject 函数。

  • 相关阅读:
    分布式系统的架构思路
    Dubbo分布式服务框架的简单理解
    Java Worker 设计模式
    进程和线程
    alibaba-Java开发手册心得-一编程规约-6并发处理
    swagger的简单了解
    alibaba-Java开发手册心得-一编程规约-5集合处理
    serialVersionUID的简单理解
    java序列化对象简单理解
    最简单的调用freetype库实现在控制台输出文字显示
  • 原文地址:https://www.cnblogs.com/mydomain/p/1895044.html
Copyright © 2011-2022 走看看