source: branches/eraser6/ShellExt/CtxMenu.h @ 722

Revision 722, 3.6 KB checked in by lowjoel, 6 years ago (diff)

Instead of hardcoding strings, I'm going to use resources to embed the different localisations, and calling LoadString? to retrieve the strings. This allows for internationalisation/localisation of the Shell extension text as well.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev
Line 
1/*
2 * $Id$
3 * Copyright 2008 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    typedef std::wstring                string_type;
38    typedef std::list<string_type>      string_list;
39
40    class ATL_NO_VTABLE CCtxMenu :
41        public CComObjectRootEx<CComSingleThreadModel>,
42        public CComCoClass<CCtxMenu, &CLSID_CtxMenu>,
43        public IShellExtInit,
44        public IContextMenu3
45    {
46    public:
47        CCtxMenu()
48        {
49        }
50
51        /// The place where the context menu extension was invoked.
52        enum InvokeReasons
53        {
54            INVOKEREASON_FILEFOLDER,
55            INVOKEREASON_DRAGDROP,
56            INVOKEREASON_RECYCLEBIN
57        };
58
59        enum Actions
60        {
61            ACTION_ERASE                = 1 << 0,
62            ACTION_ERASE_ON_RESTART     = 1 << 1,
63            ACTION_ERASE_UNUSED_SPACE   = 1 << 2,
64            ACTION_SEPERATOR_1,
65            ACTION_SECURE_MOVE          = 1 << 3,
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 GetHKeyPath(HKEY handle);
87        static MENUITEMINFO* GetSeparator();
88        static HICON GetMenuIcon();
89        static HBITMAP GetMenuBitmap();
90        static HBITMAP CreateDIB(LONG width, LONG height, char** bitmapBits);
91
92    protected:
93        static const wchar_t*       MenuTitle;
94
95        InvokeReasons               InvokeReason;
96        UINT                        MenuID;
97        std::wstring                DragDropDestinationDirectory;
98        std::list<std::wstring>     SelectedFiles;
99        std::vector<Actions>        VerbMenuIndices;
100
101    public:
102        DECLARE_REGISTRY_RESOURCEID(IDR_ERASERSHELLEXT)
103        DECLARE_NOT_AGGREGATABLE(CCtxMenu)
104        BEGIN_COM_MAP(CCtxMenu)
105            COM_INTERFACE_ENTRY(IShellExtInit)
106            COM_INTERFACE_ENTRY(IContextMenu)
107            COM_INTERFACE_ENTRY(IContextMenu2)
108            COM_INTERFACE_ENTRY(IContextMenu3)
109        END_COM_MAP()
110
111        DECLARE_PROTECT_FINAL_CONSTRUCT()
112        HRESULT FinalConstruct()
113        {
114            return S_OK;
115        }
116    };
117
118    OBJECT_ENTRY_AUTO(__uuidof(CtxMenu), CCtxMenu)
119}
Note: See TracBrowser for help on using the repository browser.