Click here to Skip to main content
15,891,431 members
Articles / Desktop Programming / Win32

Shell Extension with Keyboard Hook

Rate me:
Please Sign up or sign in to vote.
3.83/5 (5 votes)
31 Aug 2008CPOL9 min read 51.2K   882   36  
Shell Extension with Keyboard Hook
// ShellExtension.h : Declaration of the CShellExtension

#pragma once
#include "resource.h"       // main symbols

#include "ATLSmartMove_i.h"
#include <shlobj.h>

#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

const int NEWFOLDERKEY = VK_F12;
const TCHAR GRAPHICFILES[49] = TEXT("*.png;*.bmp;*.jpg;*.gif;*.jpeg;*.pcd;*.pcx;*.svg");
const TCHAR VIDEOFILES[87] = TEXT("*.avi;*.mpeg;*.mpg;*.flv;*.swf;*.fla;*.wmv;*.3gp;*.divx;*.rm;*.rmvb;*.srt;*.xvid;*.vid");
const TCHAR MUSICFILES[124] = TEXT("*.aac;*.aif;*.aiff;*.aud;*.m3u;*.mid;*.midi;*.mp1;*.mp2;*.mp3;*.mpa;*.mpga;;*.ogg;*.omf;*.omg;*.ra;*.r1m;*.wav;*.wave;*.wma");

// CShellExtension

class ATL_NO_VTABLE CShellExtension :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CShellExtension, &CLSID_ShellExtension>,
	public IObjectWithSiteImpl<CShellExtension>,
	public IShellExtension
{
public:
	CShellExtension();
	~CShellExtension();

DECLARE_REGISTRY_RESOURCEID(IDR_SHELLEXTENSION)

DECLARE_NOT_AGGREGATABLE(CShellExtension)

BEGIN_COM_MAP(CShellExtension)
	COM_INTERFACE_ENTRY(IShellExtension)
	COM_INTERFACE_ENTRY(IObjectWithSite)
END_COM_MAP()



	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

public:
	STDMETHOD(SubclassExplorer) (bool SubClass);
	STDMETHOD(SetSite) (IUnknown *pUnkSite);

private:
	bool m_Subclassed;

	static BOOL CALLBACK WndEnumProc(HWND, LPARAM);
	static LRESULT CALLBACK KeyboardProc(int, WPARAM, LPARAM);

	static VOID MoveSelectedFiles(bool);
	static BOOL FindIShellView(HWND, IShellView**);

	static void AddFileToArray(LPCWSTR, LPWSTR, IFileOperation*, bool);
};

OBJECT_ENTRY_AUTO(__uuidof(ShellExtension), CShellExtension)

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Independent
Argentina Argentina
I have been working as a developer for 15 years now, starting with gwbasic, moving to C and VB and then to VB.Net and later C#. I've used many languages, as languages is what I really like.

Comments and Discussions