但这是针对非常旧版本的Visual Studio的.我使用的是VS 2008,因此说明和界面似乎与我所看到的不符.我想使用C ++创建一个简单的shell扩展,它为扩展名为.GZ的文件创建一个上下文菜单.右键单击这些文件时,我应该能够单击上下文菜单项,并在代码中进行回调以对该文件执行某种操作.其他上下文菜单项将执行诸如生成无模式对话框之类的操作,以在执行某些操作之前接受用户输入.从我所见,ATL用于此目的,但我从未使用过ATL,因此所有对象类型和接口都令我感到困惑.如果我有合适的教程或文档可以阅读,那还不错.有人可以帮我吗?那里不是有没有10年历史的教程吗?解决方案我无法确切地告诉您如何编写Shell扩展,但是我将提供许多技巧.与更简单的仅注册"方法相比,编写Shell Extension具有一些明显的优势:使用Shell Extension,您可以动态创建与所选文件更相关的上下文菜单项(或子菜单).例如,如果您正在为zip文件编写Shell Extension,则可以在上下文菜单中创建一个子菜单,以显示zip的全部内容.您可以同时处理多个文件,这不仅对提高性能有好处,而且还可以使您根据整体选择来确定要做什么,而不仅仅是针对每个文件. Shell扩展的一些缺点是: 大大增加了复杂性.准备为此花费很多精力才能使其正常工作.在计算机旁边安装家用咖啡机和/或雇人为您煮咖啡. 大大增加了调试难度.关于咖啡也是如此.编写Shell扩展很困难,因为它们很难调试. Shell Extensions由explorer.exe进程加载,并且在没有特定的Explorer配置的情况下,您需要强制退出explorer.exe进程,以便可以安装更高版本的Shell Extension.有一种方法可以使资源管理器卸载不再使用的DLL,但是您只能在开发计算机上而不是在部署目标上执行此操作: 在RegEdit中,浏览到以下键: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer 添加一个名为"AlwaysUnloadDLL"的新DWORD密钥,并将其值设置为1. 重新启动浏览器.这在大多数情况下都是可行的,但是由于Shell Extension尚未卸载,因此有时仍然需要关闭资源管理器. 请记住,您的Shell扩展程序可能会被其他应用程序加载,例如,如果右键单击带有应用程序打开文件"对话框的文件,则您的Shell扩展程序将被加载到该应用程序中,而不是资源管理器. 如果您的Shell Extension导致运行时错误,则结果通常只是不显示您的上下文菜单项,很少会告诉您Shell Extension加载失败或导致运行时错误错误. 配置可能很困难,即使进行安装,也需要在多个位置创建注册表数据,并且根据您希望上下文菜单显示的位置,注册表的位置在不同版本的Windows之间可能有所不同.您需要做什么: Visual Studio提供了一些用于创建Shell扩展的快捷方式,但是基本上您需要创建一个COM DLL.上下文菜单项的外壳扩展必须必须同时实现 IContextMenu 界面和 IShellExtInit 接口.在IShellExtInit::Initialize()方法中,可以从IDataObject参数获取所选文件.从内存中,数据为"Drag-n-Drop"格式,因此您需要从IDataObject获取HDROP句柄并从那里查询文件(这是从内存中获取的,实际上可能与我在这里描述过,因此请谨慎操作.)一旦您的DLL准备好安装",您必须将其复制到某个地方,然后运行regsvr32以确保已注册.遵循本指南知道将注册表项放在哪里. 64位Windows可能存在 问题,如果您构建32位DLL,则可能无法在64位资源管理器中加载…因此请记住这一点,如果您在使用64位Windows时遇到问题位Windows.您的DLL实际上将具有与它们关联的两个 GUID.我记不清它是如何工作的,但是一个GUID指的是DLL本身,而另一个GUID指的是实际的Shell扩展.在需要GUID的注册表中创建密钥时,请确保使用实际Shell Extension的GUID.考虑了所有事物……(tl; dr)权衡一下Shell扩展是否值得的成本.如果要基于所选文件动态创建菜单项,则Shell扩展可能是唯一的方法.如果要同时处理所有文件,则可能还需要Shell扩展程序.上下文菜单方法的另一种选择是在用户的桌面上放置一个拖放目标.探索其他让用户将文件提交到应用程序的方法,因为Shell Extension往往要花很多功夫.我发现这很困难,我想其他人也都有.This seemed like a common question but after doing some searching, I wasn't really able to find my answers. There is an article on this here:http://www.codeproject.com/KB/shell/shellextguide1.aspxBut it's for a very old version of Visual Studio. I'm using VS 2008, so the instructions and interfaces don't seem to match what I'm seeing.I want to create a simple shell extension using C++ that creates a context menu for files with extension .GZ. When right clicking on these files, I should be able to click my context menu item and have a callback in code to do some sort of operation on that file.Other context menu items would do things like spawn modless dialogs to accept user input before executing some action.From what I've seen, ATL is used for this but I have never used ATL, so all of the object types and interfaces are very confusing to me. It wouldn't be so bad if I had a proper tutorial or documentation to read.Can anyone help me out? Isn't there some sort of tutorial out there that isn't 10 years old? 解决方案 I can't tell you exactly how to write a shell extension, but I will provide a number of tips. Writing a Shell Extension offers some significant advantages over the much simpler "registry-only" method:With a Shell Extension, you can dynamically create a context menu item (or submenu) that is more relevant to the selected file(s). For example, if you are writing a Shell Extension for zip files, it is possible to create a submenu within the context menu that shows the entire contents of the zip.You can handle multiple files simultaneously, which may be more beneficial not just for performance purposes but also so that you can work out what to do based on the selection as a whole rather than just for each file.Some of the downfalls to Shell Extensions are:Substantially increased complexity. Be prepared to spend a lot of effort on this to get it working. Have a home-espresso machine installed next to your computer and/or hire someone to make you coffee.Substantially increased difficulty in debugging. Ditto about coffee.It's difficult to write a Shell Extension because they can be very hard to debug.Shell Extensions are loaded by the explorer.exe process, and without specific configuration of Explorer, you need to force-quit the explorer.exe process so that you can install a newer version of your Shell Extension. There is a way to get Explorer to unload DLLs that it is no longer using, but you should only do this on a development machine and not on a deployment target:In RegEdit, browse to the following key:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ExplorerAdd a new DWORD key called "AlwaysUnloadDLL" and set its value to 1.Restart explorer.This works most of the time, but there may still be times where you need to close Explorer because the Shell Extension was not unloaded.Keep in mind that your Shell Extension may be loaded by other applications, for example, if you right-click on a file with an applications "open file" dialog, then your Shell Extension will be loaded into that application, and not Explorer.If your Shell Extension causes a runtime error, quite often the result will simply be that your context menu item does not show, very rarely will you be told that your Shell Extension failed to load or that it caused a runtime error.Configuration can be hard, even with an installation, registry data needs to be created in several places, and depending where you want your context menu to show, the places in the registry may differ between different versions of Windows.What you'll need to do:Visual Studio offers some shortcuts to creating Shell Extensions, but basically you'll need to create a COM DLL. A Shell Extension for context menu items must implement both the IContextMenu interface and the IShellExtInit interface.In the IShellExtInit::Initialize() method, you can obtain the selected files from the IDataObject parameter. From memory, the data is in "Drag-n-Drop" format, so you need to get an HDROP handle from the IDataObject and query the files from there (this is from memory, it may actually be different than as I described here, so proceed with caution).Once your DLL is ready to be "installed", you must copy it somewhere, and then run regsvr32 to make sure it is registered.Follow this guide to know where to put registry keys.There may be issues with 64-bit Windows, if you build a 32-bit DLL it may not load in 64-bit Explorer… so keep this in mind if you are having trouble with 64-bit Windows.Your DLL will actually have two GUIDs associated with it. I can't remember exactly how it works, but one GUID refers to the DLL itself and the other refers to the actual Shell Extension. Make sure you use the GUID of the actual Shell Extension when creating keys in the registry where a GUID is required.All things considered… (tl;dr)Weigh up the costs of whether a Shell Extension is worth it. If you want to create menu items dynamically based on the selected files, then a Shell Extension may be the only way. If you want to handle all files simultaneously then you'll probably need a Shell Extension as well.An alternative to the context menu method, could be to have a drag-n-drop target on the user's desktop or something. Explore other ways that you could have the user submit your files to your application, because a Shell Extension is often far more effort than it is worth. I found this out the hard way and I think everyone else has too. 这篇关于如何用C ++编写Shell扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 01:57