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 HICON m_hIconFolder, m_hIconLink; 63 64 SHELLNEW_ITEM *LoadItem(LPCWSTR pwszExt); 65 void UnloadItem(SHELLNEW_ITEM *pItem); 66 void UnloadAllItems(); 67 BOOL CacheItems(); 68 BOOL LoadCachedItems(); 69 BOOL LoadAllItems(); 70 UINT InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu); 71 SHELLNEW_ITEM *FindItemFromIdOffset(UINT IdOffset); 72 HRESULT CreateNewFolder(LPCMINVOKECOMMANDINFO lpici); 73 HRESULT CreateNewItem(SHELLNEW_ITEM *pItem, LPCMINVOKECOMMANDINFO lpcmi); 74 HRESULT SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename); 75 HRESULT NewItemByCommand(SHELLNEW_ITEM *pItem, LPCWSTR wszPath); 76 HRESULT NewItemByNonCommand(SHELLNEW_ITEM *pItem, LPWSTR wszName, 77 DWORD cchNameMax, LPCWSTR wszPath); 78 79 public: 80 CNewMenu(); 81 ~CNewMenu(); 82 83 // IObjectWithSite 84 virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown *pUnkSite); 85 virtual HRESULT STDMETHODCALLTYPE GetSite(REFIID riid, void **ppvSite); 86 87 // IContextMenu 88 virtual HRESULT WINAPI QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags); 89 virtual HRESULT WINAPI InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi); 90 virtual HRESULT WINAPI GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen); 91 92 // IContextMenu3 93 virtual HRESULT WINAPI HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult); 94 95 // IContextMenu2 96 virtual HRESULT WINAPI HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam); 97 98 // IShellExtInit 99 virtual HRESULT STDMETHODCALLTYPE Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID); 100 101 DECLARE_REGISTRY_RESOURCEID(IDR_NEWMENU) 102 DECLARE_NOT_AGGREGATABLE(CNewMenu) 103 104 DECLARE_PROTECT_FINAL_CONSTRUCT() 105 106 BEGIN_COM_MAP(CNewMenu) 107 COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite) 108 COM_INTERFACE_ENTRY_IID(IID_IContextMenu3, IContextMenu3) 109 COM_INTERFACE_ENTRY_IID(IID_IContextMenu2, IContextMenu2) 110 COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu) 111 COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit) 112 END_COM_MAP() 113 }; 114 115 #endif /* _SHV_ITEM_NEW_H_ */ 116