它是一个 COM 对象。您只需要创建它,并将其传递给它的接口(背后有足够的实现)它就可以工作。
Explorer(即您)将要求外壳扩展将项目添加到不同的 HMENU。然后资源管理器(即您)调用一个菜单项以响应用户。
幸运的是,shell 中的所有东西都是一个接口——所以你可以假装成你想要的任何东西。您只需要从另一端阅读 SDK 合同。
请记住:Shell 扩展不必托管在 Explorer中。许多不是。CommCtrl 的“另存为”对话框中有很多内容。
在您的情况下,它甚至更简单。
- 创建 COM 对象
- 查询其
IShellExtInit
接口,并调用.Initialize
.
- 查询其
IContextMenu
接口
- 调用
IContextMenu.QueryContextMenu
,允许它添加项目到HMENU
- 称呼
IContextMenu.Invoke
再次,从另一方阅读合同的案例。
一些伪代码:
var
ClassID: TGUID;
unk: IUnknown;
shellext: IShellExtInit;
dataObject: IDataObject;
hkeyProgID: HKEY;
contextMenu: IContextMenu;
commandInfo: CMINVOKECOMMANDINFO;
begin
ClassID := ProgIDToClassID('PDFTransformer3.PDFTContextMenu');
unk := CreateComObject(ClassID);
shellExt := unk as IShellExtInit;
{
For shortcut menu extensions,
pdtobj identifies the selected file objects,
hkeyProgID identifies the file type of the object with focus, and
pidlFolder is either NULL (for file objects) or specifies the folder
for which the shortcut menu is being requested
(for folder background shortcut menus).
}
shellExt.Initialize(
nil, //pidlFolder, null for file objects
dataObject, //IDataObject of the selected file
hkeyProgID); //HKEY of the file type of the object with focus
contextMenu := unk as IContextMenu;
contextMenu.QueryContextMenu(
menuHandle, //HMENU, A handle to the shortcut menu. The handler should specify this handle when adding menu items.
0, //integer, The zero-based position at which to insert the first new menu item.
100, //The minimum value that the handler can specify for a menu item identifier.
200, //The maximum value that the handler can specify for a menu item identifier.
CMF_NORMAL); //optional flags
contextMenu.InvokeCommand(commandInfo);
这是我从阅读文档和猜测该怎么做中得到的。现在我要尿尿,然后回家玩传送门 2