/ src / modules / imageresizer / dll / ContextMenuHandler.h
ContextMenuHandler.h
 1  #pragma once
 2  
 3  #define ID_RESIZE_PICTURES 0
 4  #define RESIZE_PICTURES_VERBW L"resize"
 5  #include "pch.h"
 6  #include "Generated Files/resource.h"
 7  #include "ImageResizerExt_i.h"
 8  #include <common/Telemetry/EtwTrace/EtwTrace.h>
 9  
10  #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
11  #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 its 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."
12  #endif
13  
14  using namespace ATL;
15  
16  class ATL_NO_VTABLE __declspec(uuid("51B4D7E5-7568-4234-B4BB-47FB3C016A69")) CContextMenuHandler :
17      public CComObjectRootEx<CComSingleThreadModel>,
18      public CComCoClass<CContextMenuHandler, &CLSID_ContextMenuHandler>,
19      public IShellExtInit,
20      public IContextMenu,
21      public IExplorerCommand
22  {
23      BEGIN_COM_MAP(CContextMenuHandler)
24      COM_INTERFACE_ENTRY(IShellExtInit)
25      COM_INTERFACE_ENTRY(IContextMenu)
26      COM_INTERFACE_ENTRY(IExplorerCommand)
27      END_COM_MAP()
28      DECLARE_REGISTRY_RESOURCEID(IDR_CONTEXTMENUHANDLER)
29      DECLARE_NOT_AGGREGATABLE(CContextMenuHandler)
30  
31  public:
32      CContextMenuHandler();
33      ~CContextMenuHandler();
34      HRESULT STDMETHODCALLTYPE Initialize(_In_opt_ PCIDLIST_ABSOLUTE pidlFolder, _In_opt_ IDataObject* pdtobj, _In_opt_ HKEY hkeyProgID);
35      HRESULT STDMETHODCALLTYPE QueryContextMenu(_In_ HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
36      HRESULT STDMETHODCALLTYPE GetCommandString(UINT_PTR idCmd, UINT uType, _In_ UINT* pReserved, LPSTR pszName, UINT cchMax);
37      HRESULT STDMETHODCALLTYPE InvokeCommand(_In_ CMINVOKECOMMANDINFO* pici);
38  
39      // Inherited via IExplorerCommand
40      virtual HRESULT __stdcall GetTitle(IShellItemArray* psiItemArray, LPWSTR* ppszName) override;
41      virtual HRESULT __stdcall GetIcon(IShellItemArray* psiItemArray, LPWSTR* ppszIcon) override;
42      virtual HRESULT __stdcall GetToolTip(IShellItemArray* psiItemArray, LPWSTR* ppszInfotip) override;
43      virtual HRESULT __stdcall GetCanonicalName(GUID* pguidCommandName) override;
44      virtual HRESULT __stdcall GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState) override;
45      virtual HRESULT __stdcall Invoke(IShellItemArray* psiItemArray, IBindCtx* pbc) override;
46      virtual HRESULT __stdcall GetFlags(EXPCMDFLAGS* pFlags) override;
47      virtual HRESULT __stdcall EnumSubCommands(IEnumExplorerCommand** ppEnum) override;
48  
49  private:
50      void Uninitialize();
51      HRESULT ResizePictures(CMINVOKECOMMANDINFO* pici, IShellItemArray* psiItemArray);
52      PCIDLIST_ABSOLUTE m_pidlFolder;
53      IDataObject* m_pdtobj;
54      HBITMAP m_hbmpIcon = nullptr;
55      std::wstring context_menu_caption;
56      std::wstring context_menu_caption_here;
57      Shared::Trace::ETWTrace m_etwTrace{ L"ImageResizerExt" };
58  };
59  
60  OBJECT_ENTRY_AUTO(__uuidof(ContextMenuHandler), CContextMenuHandler)