Shell Extension to Copy Full Filename Path(s)

There numerous times that I've wished I could simply right-click on a
file, and copy its full pathname in order to paste it into an e-mail or
a file open dialog. I finally decided to write it
myself and thought someone else might find it useful. The extension adds
a 'Copy Path' command to the context menu for a single file/folder
selection and a 'Copy All Paths' command for multi-file/folder selection.
For a single selection the complete pathname of the file is simply
placed on the clipboard. For a multi-file selection, all the paths of
the files are placed on the clipboard separated by <cr><lf>
pairs.

One unexpected 'feature' is that you can right-click on a shortcut and the
path of the target will be copied to the clipboard. Of course, the
shortcut can be anywhere, including shell menu items if the IE4
active desktop option is installed.

Some of the code was based on code written by Dino Esposito from his book,
Visual C++ Window Shell Programming (Wrox). This is an excellent
resource for shell programming. I've run across a few things that his
book didn't cover and found a bug related to a newer version of IE (I
think).

I started building this component by simply creating an ATL COM
project, and then adding a simple ATL object. I then added the necessary
interfaces and their implementations. A shell extension requires
implementation
of two interfaces, IShellExtInit and IContextMenu.

IShellExtInit has only one
method, Initialize which is used to get the name of the files that
have been selected (this extension only gets the name of the file
with the current focus, although it could be expanded to be disabled if
multiple files were selected, or to put all the paths on the clipboard.)

IContextMenu has three methods to implement, GetCommandString,
InvokeCommand, and QueryContextMenu.

QueryContextMenu is called when the extension is first loaded to
get the text and ID for the context menu item.

InvokeCommand is called when the user invokes the menu item.

GetCommandString can be called in different situations, but for this
example we only care
when it is called to get the help text associated with the command.

I had a bit of trouble getting this to work correctly and I think it
has to do with most recent IE installation. Following is the code
for GetCommandString:

Most examples simply test for the bits GCS_HELPTEXTA or GCS_HELPTEXTW,
but the value of GCS_HELPTEXTW is actually 5, not a single
bit value, which is also equal to GSC_HELPTEXTA|GCS_UNICODE. So, I
simply test for GCS_HELPTEXTA and then test for the GCS_UNICODE bit.
I also assume that if GetCommandString requests a Unicode string,
then the max length of the string is half of what it would normally
be. This may be incorrect, but it's a safe guess.

Future work

There are 'extended' commands for the shell that are displayed when
the user holds down the SHIFT key. For example, under NT, you'll get
the additional commands 'Compress', 'Uncompress', and 'Open With...'
(even if the file already has an association). I would like to add
extended commands that only copy the filename(s) not the path (fewer
keystrokes than F2, Ctrl-C, ESC). The documentation for
IContextMenu::QueryContextMenu
states that the CMF_EXTENDEDVERBS "...is set when the calling
application
wants extended verbs. Normal verbs are displayed when the user right-clicks
an object. To display extended verbs, the user must right-click while
pressing the SHIFT key." But, I could not get this to work nor find
any examples. Let me know if you know how to do this.

The bitmap for the icon gets XORed by the shell to make it look darker
than it should. I've read that IContextMenu3 needs to be implemented
to handle an ownerdraw menuitem in order to make the icons like
as nice as the 'Send To' icons. A fix for this would be nice.

Finally, I would like to put together an ATL Object wizard to help
jumpstart the creation of these shell extensions. I'll do it if someone
requests it.

Top White Papers and Webcasts

Live Event Date: March 19, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT
The 2015 Enterprise Mobile Application Survey asked 250 mobility professionals what their biggest mobile challenges are, how many employees they are equipping with mobile apps, and their methods for driving value with mobility.
Join Dan Woods, Editor and CTO of CITO Research, and Alan Murray, SVP of Products at Apperian, as they break down the results of this survey and discuss how enterprises are using mobile application management and private …

The mobile market is white hot. Building a well-crafted product development plan that addresses market research, strategy, design, and development will provide the greatest chance for success. Each phase of an app's lifecycle is critical to the its overall success and feeds into the next step of the process of product development for the app. This white paper examines the five key phases of mobile app creation, one by one, to understand how they work together to help create a successful mobile app.