Click here to Skip to main content
15,892,161 members
Articles / Desktop Programming / ATL

Copy Path Context Menu Extension

Rate me:
Please Sign up or sign in to vote.
4.88/5 (14 votes)
9 May 2000 188.2K   2.7K   54  
A context menu shell extension that allows you to copy full file paths to the clipboard.
// CopyPathContextMenu.h : Declaration of the CCopyPathContextMenu

#ifndef __COPYPATHCONTEXTMENU_H_
#define __COPYPATHCONTEXTMENU_H_

#pragma warning(disable:4786)

#include "resource.h"       // main symbols
#include <shlguid.h>
#include <comdef.h>
#include <shlobj.h>
#include <list>
#include <string>

#define ID_COPY_PATH	0

/////////////////////////////////////////////////////////////////////////////
// CCopyPathContextMenu
class ATL_NO_VTABLE CCopyPathContextMenu : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CCopyPathContextMenu, &CLSID_CopyPathContextMenu>,
	public IContextMenu3,
	public IShellExtInit
{
public:
	CCopyPathContextMenu()
	{
	}

	// IContextMenu interface
    STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
    STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici);
    STDMETHOD(GetCommandString)(UINT idCmd, UINT  uType, UINT *pwReserved, LPSTR pszName, UINT cchMax);   
    
	// IContextMenu2 interface
	STDMETHOD(HandleMenuMsg)(UINT uMsg, WPARAM wParam, LPARAM lParam);    
    
	// IContextMenu3 interface
	STDMETHOD(HandleMenuMsg2)(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plResult);
    
	// IShellExtInit interface
	STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY hkeyProgID);

DECLARE_REGISTRY_RESOURCEID(IDR_COPYPATHCONTEXTMENU)
DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CCopyPathContextMenu)
	COM_INTERFACE_ENTRY(IContextMenu3)
	COM_INTERFACE_ENTRY(IContextMenu2)
	COM_INTERFACE_ENTRY(IContextMenu)
	COM_INTERFACE_ENTRY(IShellExtInit)
END_COM_MAP()

private:
	typedef std::basic_string<_TCHAR>		string;	
	std::list<string>						m_listFileNames;
};

#endif //__COPYPATHCONTEXTMENU_H_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
<A HREF=http://www.unc.edu/~carrutt>Nicks's Web Page - My wild and crazy home on the web.

Read the new issue of Modern Advances in Medicine (MAIM)!

<A HREF=http://www.unc.edu/~carrutt/hearts_of_gold/>Hearts of Gold - Check out a silly game I wrote for the Macintosh (boo hiss) back in the winter of 1995.

Comments and Discussions