SHGetDesktopFolder的使用

第一部分 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 函数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值