Introduction
In Win2K you can see two new tool bar buttons in Windows Explorer: Copy To & Move To. Yet Microsoft hasn't realized to include these two entries in files/folders context menu. I wish for these entries in context menu because every time for copying or moving files/folders, I have to change the folders or have to push those new tool bar buttons in Win2K.
Following example will create those two entries in context menu.
I assume that you are familiar of creating shell extensions, COM, clipboard operation and Shell APIs. (Esposito Dino's book is very handy for any beginner shell programmer).
Follow all steps that are required to create a shell extension.
Following keys in registry will tell shell that, you are extending the files/folders context menu. Those are:
#define SZ_DIRCONTEXTMENUEXT
_T("Directory\\shellex\\ContextMenuHandlers\\Mumtaz")
#define SZ_FILECONTEXTMENUEXT
_T("*\\shellex\\ContextMenuHandlers\\Mumtaz")
#define SZ_FOLDERCONTEXTMENUEXT
_T("Folder\\shellex\\ContextMenuHandlers\\Mumtaz")
Don't be confused with text Mumtaz
; that's my Name.
When user views the context menu of file/folders, shell starts the game of looking for any one who is extending the shell. That will include the difficult words like DllGetClassObject
, IClassFactory
, DllMain
...
My concern is to tell you about IContextMenu
, not all of it but Intialize
and InvokeCommand
.
First Initialize
, it has the following prototype:
IContextMenu::Initialize (LPCITEMIDLIST pidlFolder,
LPDATAOBJECT lpdobj, HKEY hKeyProgID);
Our concern is the LPDATAOBJECT
. We can retrieve the list of files/folders being selected through this data object pointer. This includes FORMATETC
for clipboard format and STGMEDIUM
for storage medium. You can study these two structures in detail on MSDN. We put the files/folders being selected, in a class member m_pszSource
.
In Invoke
command, we do the rest of the operation, yes, copying or moving. SHBrowseForFolder()
help us for selecting destination, that will be a PIDL. We must convert it to a string for passing it to SHFileOperation
as a destination path.
That's all.
I haven't included any details for creating shell extension, because you can read much about it on MSDN. For clipboard format and data object search try "Handling Shell Data Transfer Scenarios" on MSDN.