1 /* 2 * provides new shell item service 3 * 4 * Copyright 2007 Johannes Anderwald (johannes.anderwald@reactos.org) 5 * Copyright 2009 Andrew Hill 6 * Copyright 2012 Rafal Harabien 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 21 */ 22 23 #ifndef _SHV_ITEM_NEW_H_ 24 #define _SHV_ITEM_NEW_H_ 25 26 const WCHAR ShellNewKey[] = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Discardable\\PostSetup\\ShellNew"; 27 28 class CNewMenu : 29 public CComCoClass<CNewMenu, &CLSID_NewMenu>, 30 public CComObjectRootEx<CComMultiThreadModelNoCS>, 31 public IObjectWithSite, 32 public IContextMenu3, 33 public IShellExtInit 34 { 35 private: 36 enum SHELLNEW_TYPE 37 { 38 SHELLNEW_TYPE_INVALID = -1, 39 SHELLNEW_TYPE_COMMAND = 1, 40 SHELLNEW_TYPE_DATA = 2, 41 SHELLNEW_TYPE_FILENAME = 4, 42 SHELLNEW_TYPE_NULLFILE = 8 43 }; 44 45 struct SHELLNEW_ITEM 46 { 47 SHELLNEW_TYPE Type; 48 LPWSTR pwszExt; 49 PBYTE pData; 50 ULONG cbData; 51 LPWSTR pwszDesc; 52 HICON hIcon; 53 SHELLNEW_ITEM *pNext; 54 }; 55 56 LPITEMIDLIST m_pidlFolder; 57 SHELLNEW_ITEM *m_pItems; 58 SHELLNEW_ITEM *m_pLinkItem; // Points to the link handler item in the m_pItems list. 59 CComPtr<IUnknown> m_pSite; 60 HMENU m_hSubMenu; 61 UINT m_idCmdFirst, m_idCmdFolder, m_idCmdLink; 62 BOOL m_bCustomIconFolder, m_bCustomIconLink; 63 HICON m_hIconFolder, m_hIconLink; 64 65 SHELLNEW_ITEM *LoadItem(LPCWSTR pwszExt); 66 void UnloadItem(SHELLNEW_ITEM *pItem); 67 void UnloadAllItems(); 68 BOOL CacheItems(); 69 BOOL LoadCachedItems(); 70 BOOL LoadAllItems(); 71 UINT InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu); 72 SHELLNEW_ITEM *FindItemFromIdOffset(UINT IdOffset); 73 HRESULT CreateNewFolder(LPCMINVOKECOMMANDINFO lpici); 74 HRESULT CreateNewItem(SHELLNEW_ITEM *pItem, LPCMINVOKECOMMANDINFO lpcmi); 75 HRESULT SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename); 76 HRESULT NewItemByCommand(SHELLNEW_ITEM *pItem, LPCWSTR wszPath); 77 HRESULT NewItemByNonCommand(SHELLNEW_ITEM *pItem, LPWSTR wszName, 78 DWORD cchNameMax, LPCWSTR wszPath); 79 80 public: 81 CNewMenu(); 82 ~CNewMenu(); 83 84 // IObjectWithSite 85 STDMETHOD(SetSite)(IUnknown *pUnkSite) override; 86 STDMETHOD(GetSite)(REFIID riid, void **ppvSite) override; 87 88 // IContextMenu 89 STDMETHOD(QueryContextMenu)(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) override; 90 STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpcmi) override; 91 STDMETHOD(GetCommandString)(UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen) override; 92 93 // IContextMenu3 94 STDMETHOD(HandleMenuMsg2)(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult) override; 95 96 // IContextMenu2 97 STDMETHOD(HandleMenuMsg)(UINT uMsg, WPARAM wParam, LPARAM lParam) override; 98 99 // IShellExtInit 100 STDMETHOD(Initialize)(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID) override; 101 102 DECLARE_REGISTRY_RESOURCEID(IDR_NEWMENU) 103 DECLARE_NOT_AGGREGATABLE(CNewMenu) 104 105 DECLARE_PROTECT_FINAL_CONSTRUCT() 106 107 BEGIN_COM_MAP(CNewMenu) 108 COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite) 109 COM_INTERFACE_ENTRY_IID(IID_IContextMenu3, IContextMenu3) 110 COM_INTERFACE_ENTRY_IID(IID_IContextMenu2, IContextMenu2) 111 COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu) 112 COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit) 113 END_COM_MAP() 114 }; 115 116 #endif /* _SHV_ITEM_NEW_H_ */ 117