-
Notifications
You must be signed in to change notification settings - Fork 9
/
FileContextMenuExt.h
76 lines (59 loc) · 2.75 KB
/
FileContextMenuExt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/****************************** Module Header ******************************\
Module Name: FileContextMenuExt.h
Project: CppShellExtContextMenuHandler
Copyright (c) Microsoft Corporation.
The code sample demonstrates creating a Shell context menu handler with C++.
A context menu handler is a shell extension handler that adds commands to an
existing context menu. Context menu handlers are associated with a particular
file class and are called any time a context menu is displayed for a member
of the class. While you can add items to a file class context menu with the
registry, the items will be the same for all members of the class. By
implementing and registering such a handler, you can dynamically add items to
an object's context menu, customized for the particular object.
The example context menu handler adds the menu item "Display File Name (C++)"
to the context menu when you right-click a .cpp file in the Windows Explorer.
Clicking the menu item brings up a message box that displays the full path
of the .cpp file.
This source is subject to the Microsoft Public License.
See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
All other rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
#pragma once
#include <windows.h>
#include <shlobj.h> // For IShellExtInit and IContextMenu
#include <vector>
class FileContextMenuExt : public IShellExtInit, public IContextMenu
{
public:
// IUnknown
IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv);
IFACEMETHODIMP_(ULONG) AddRef();
IFACEMETHODIMP_(ULONG) Release();
// IShellExtInit
IFACEMETHODIMP Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hKeyProgID);
// IContextMenu
IFACEMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
IFACEMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO pici);
IFACEMETHODIMP GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT *pwReserved, LPSTR pszName, UINT cchMax);
FileContextMenuExt(void);
protected:
~FileContextMenuExt(void);
private:
// Reference count of component.
long m_cRef;
// The name of the selected files.
std::vector<std::wstring> m_vSelectedFiles;
// The method that handles the "display" verb.
void OnVerbDisplayFileName(HWND hWnd);
PWSTR m_pszMenuText;
HANDLE m_hMenuBmp;
PCSTR m_pszVerb;
PCWSTR m_pwszVerb;
PCSTR m_pszVerbCanonicalName;
PCWSTR m_pwszVerbCanonicalName;
PCSTR m_pszVerbHelpText;
PCWSTR m_pwszVerbHelpText;
};