source: trunk/eraser/Eraser.Shell/CtxMenu.h @ 2119

Revision 2119, 3.9 KB checked in by lowjoel, 5 years ago (diff)

Implemented initialisation code for Secure Paste. Addresses #60: Eraser Secure Cut.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev
Line 
1/*
2 * $Id$
3 * Copyright 2008-2010 The Eraser Project
4 * Original Author: Kasra Nassiri <cjax@users.sourceforge.net>
5 * Modified By: Joel Low <lowjoel@users.sourceforge.net>
6 *
7 * This file is part of Eraser.
8 *
9 * Eraser is free software: you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * A copy of the GNU General Public License can be found at
19 * <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "resource.h"
25#include "ShellExt_i.h"
26
27#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
28#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."
29#endif
30
31#include <list>
32#include <vector>
33#include <string>
34
35namespace Eraser
36{
37    class ATL_NO_VTABLE CCtxMenu :
38        public CComObjectRootEx<CComSingleThreadModel>,
39        public CComCoClass<CCtxMenu, &CLSID_CtxMenu>,
40        public IShellExtInit,
41        public IContextMenu3
42    {
43    public:
44        CCtxMenu()
45        {
46        }
47
48        /// The place where the context menu extension was invoked.
49        enum InvokeReasons
50        {
51            INVOKEREASON_FILEFOLDER,
52            INVOKEREASON_DIRECTORY_BACKGROUND,
53            INVOKEREASON_DRAGDROP,
54            INVOKEREASON_RECYCLEBIN
55        };
56
57        /// This has the equivalent in Eraser.Program.ShellActions
58        enum Actions
59        {
60            ACTION_ERASE                = 1 << 0,
61            ACTION_ERASE_ON_RESTART     = 1 << 1,
62            ACTION_ERASE_UNUSED_SPACE   = 1 << 2,
63            ACTION_SEPERATOR_1,
64            ACTION_SECURE_MOVE          = 1 << 3,
65            ACTION_SECURE_PASTE         = 1 << 4
66        };
67
68    public:
69        //IShellExtInit
70        STDMETHOD(Initialize)(LPCITEMIDLIST, LPDATAOBJECT, HKEY);
71
72        //IContextMenu3
73        STDMETHOD(GetCommandString)(UINT_PTR, UINT, UINT*, LPSTR, UINT);
74        STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO);
75        STDMETHOD(QueryContextMenu)(HMENU, UINT, UINT, UINT, UINT);
76        STDMETHOD(HandleMenuMsg)(UINT, WPARAM, LPARAM);
77        STDMETHOD(HandleMenuMsg2)(UINT, WPARAM, LPARAM, LRESULT*);
78
79    protected:
80        bool OnMeasureItem(UINT& itemWidth, UINT& itemHeight);
81        bool OnDrawItem(HDC hdc, RECT rect, UINT action, UINT state);
82
83        Actions GetApplicableActions();
84
85        static std::wstring LoadString(UINT stringID);
86        static std::wstring FormatString(const std::wstring& formatString, ...);
87        static std::wstring FormatError(DWORD lastError = static_cast<DWORD>(-1));
88        static std::wstring GetHKeyPath(HKEY handle);
89
90        static bool IsUserAdmin();
91        static void RunEraser(Actions action, const std::wstring& parameters,
92            bool elevated, HWND parent, int show);
93
94        static void InsertSeparator(HMENU menu);
95        static HICON GetMenuIcon();
96        static HBITMAP GetMenuBitmapFromIcon(HICON icon);
97        static HBITMAP CreateDIB(LONG width, LONG height, char** bitmapBits);
98
99    protected:
100        wchar_t*                    MenuTitle;
101        InvokeReasons               InvokeReason;
102        std::wstring                DragDropDestinationDirectory;
103        std::list<std::wstring>     SelectedFiles;
104        std::vector<Actions>        VerbMenuIndices;
105        UINT                        MenuID;
106
107    public:
108        DECLARE_REGISTRY_RESOURCEID(IDR_ERASERSHELLEXT)
109        DECLARE_NOT_AGGREGATABLE(CCtxMenu)
110        BEGIN_COM_MAP(CCtxMenu)
111            COM_INTERFACE_ENTRY(IShellExtInit)
112            COM_INTERFACE_ENTRY(IContextMenu)
113            COM_INTERFACE_ENTRY(IContextMenu2)
114            COM_INTERFACE_ENTRY(IContextMenu3)
115        END_COM_MAP()
116
117        DECLARE_PROTECT_FINAL_CONSTRUCT()
118        HRESULT FinalConstruct();
119        HRESULT FinalRelease();
120    };
121
122    OBJECT_ENTRY_AUTO(__uuidof(CtxMenu), CCtxMenu)
123}
Note: See TracBrowser for help on using the repository browser.