xref: /reactos/dll/win32/shell32/CShellLink.h (revision 49b2b1da)
1 /*
2  *
3  *      Copyright 1997  Marcus Meissner
4  *      Copyright 1998  Juergen Schmied
5  *      Copyright 2005  Mike McCormack
6  *      Copyright 2009  Andrew Hill
7  *      Copyright 2017  Hermes Belusca-Maito
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  *
23  */
24 
25 #ifndef _SHELLLINK_H_
26 #define _SHELLLINK_H_
27 
28 class CShellLink :
29     public CComCoClass<CShellLink, &CLSID_ShellLink>,
30     public CComObjectRootEx<CComMultiThreadModelNoCS>,
31     public IShellLinkA,
32     public IShellLinkW,
33     public IPersistStream,
34     public IPersistFile,
35     public IShellExtInit,
36     public IContextMenu, // Technically it should be IContextMenu3 (inherits from IContextMenu2 and IContextMenu)
37     public IDropTarget,
38 //  public IQueryInfo,
39     public IShellLinkDataList,
40     public IExtractIconA,
41     public IExtractIconW,
42 //  public IExtractImage2, // Inherits from IExtractImage
43 //  public IPersistPropertyBag,
44 //  public IServiceProvider,
45 //  public IFilter,
46     public IObjectWithSite,
47 //  public ICustomizeInfoTip,
48     public IShellPropSheetExt
49 {
50 public:
51     /* Link file formats */
52 
53     #include "pshpack1.h"
54     struct volume_info
55     {
56         DWORD type;
57         DWORD serial;
58         WCHAR label[12];  /* assume 8.3 */
59     };
60     #include "poppack.h"
61 
62     enum IDCMD
63     {
64         IDCMD_OPEN = 0,
65         IDCMD_OPENFILELOCATION
66     };
67 
68 private:
69     /* Cached link header */
70     SHELL_LINK_HEADER m_Header;
71 
72     /* Cached data set according to m_Header.dwFlags (SHELL_LINK_DATA_FLAGS) */
73 
74     LPITEMIDLIST  m_pPidl;
75 
76     /* Link tracker information */
77     LPWSTR        m_sPath;
78     volume_info   volume;
79 
80     LPWSTR        m_sDescription;
81     LPWSTR        m_sPathRel;
82     LPWSTR        m_sWorkDir;
83     LPWSTR        m_sArgs;
84     LPWSTR        m_sIcoPath;
85     BOOL          m_bRunAs;
86     BOOL          m_bDirty;
87     LPDBLIST      m_pDBList; /* Optional data block list (in the extra data section) */
88     BOOL          m_bInInit;    // in initialization or not
89     HICON         m_hIcon;
90     UINT          m_idCmdFirst;
91 
92     /* Pointers to strings inside Logo3/Darwin info blocks, cached for debug info purposes only */
93     LPWSTR sProduct;
94     LPWSTR sComponent;
95 
96     LPWSTR        m_sLinkPath;
97 
98     CComPtr<IUnknown>    m_site;
99     CComPtr<IDropTarget> m_DropTarget;
100 
101     VOID Reset();
102 
103     HRESULT GetAdvertiseInfo(LPWSTR *str, DWORD dwSig);
104     HRESULT SetAdvertiseInfo(LPCWSTR str);
105     HRESULT WriteAdvertiseInfo(LPCWSTR string, DWORD dwSig);
106     HRESULT SetTargetFromPIDLOrPath(LPCITEMIDLIST pidl, LPCWSTR pszFile);
107     HICON CreateShortcutIcon(LPCWSTR wszIconPath, INT IconIndex);
108 
109     HRESULT DoOpen(LPCMINVOKECOMMANDINFO lpici);
110     HRESULT DoOpenFileLocation();
111 
112 public:
113     CShellLink();
114     ~CShellLink();
115     static INT_PTR CALLBACK SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
116 
117     BOOL OnInitDialog(HWND hwndDlg, HWND hwndFocus, LPARAM lParam);
118     void OnCommand(HWND hwndDlg, int id, HWND hwndCtl, UINT codeNotify);
119     LRESULT OnNotify(HWND hwndDlg, int idFrom, LPNMHDR pnmhdr);
120     void OnDestroy(HWND hwndDlg);
121 
122     // IPersistFile
123     STDMETHOD(GetClassID)(CLSID *pclsid) override;
124     STDMETHOD(IsDirty)() override;
125     STDMETHOD(Load)(LPCOLESTR pszFileName, DWORD dwMode) override;
126     STDMETHOD(Save)(LPCOLESTR pszFileName, BOOL fRemember) override;
127     STDMETHOD(SaveCompleted)(LPCOLESTR pszFileName) override;
128     STDMETHOD(GetCurFile)(LPOLESTR *ppszFileName) override;
129 
130     // IPersistStream
131     // STDMETHOD(GetClassID)(CLSID *pclsid) override;
132     // STDMETHOD(IsDirty)() override;
133     STDMETHOD(Load)(IStream *stm) override;
134     STDMETHOD(Save)(IStream *stm, BOOL fClearDirty) override;
135     STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) override;
136 
137     // IShellLinkA
138     STDMETHOD(GetPath)(LPSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags) override;
139     STDMETHOD(GetIDList)(PIDLIST_ABSOLUTE *ppidl) override;
140     STDMETHOD(SetIDList)(PCIDLIST_ABSOLUTE pidl) override;
141     STDMETHOD(GetDescription)(LPSTR pszName, INT cchMaxName) override;
142     STDMETHOD(SetDescription)(LPCSTR pszName) override;
143     STDMETHOD(GetWorkingDirectory)(LPSTR pszDir, INT cchMaxPath) override;
144     STDMETHOD(SetWorkingDirectory)(LPCSTR pszDir) override;
145     STDMETHOD(GetArguments)(LPSTR pszArgs, INT cchMaxPath) override;
146     STDMETHOD(SetArguments)(LPCSTR pszArgs) override;
147     STDMETHOD(GetHotkey)(WORD *pwHotkey) override;
148     STDMETHOD(SetHotkey)(WORD wHotkey) override;
149     STDMETHOD(GetShowCmd)(INT *piShowCmd) override;
150     STDMETHOD(SetShowCmd)(INT iShowCmd) override;
151     STDMETHOD(GetIconLocation)(LPSTR pszIconPath, INT cchIconPath, INT *piIcon) override;
152     STDMETHOD(SetIconLocation)(LPCSTR pszIconPath, INT iIcon) override;
153     STDMETHOD(SetRelativePath)(LPCSTR pszPathRel, DWORD dwReserved) override;
154     STDMETHOD(Resolve)(HWND hwnd, DWORD fFlags) override;
155     STDMETHOD(SetPath)(LPCSTR pszFile) override;
156 
157     // IShellLinkW
158     STDMETHOD(GetPath)(LPWSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags) override;
159     // STDMETHOD(GetIDList)(PIDLIST_ABSOLUTE *ppidl) override;
160     // STDMETHOD(SetIDList)(PCIDLIST_ABSOLUTE pidl) override;
161     STDMETHOD(GetDescription)(LPWSTR pszName, INT cchMaxName) override;
162     STDMETHOD(SetDescription)(LPCWSTR pszName) override;
163     STDMETHOD(GetWorkingDirectory)(LPWSTR pszDir, INT cchMaxPath) override;
164     STDMETHOD(SetWorkingDirectory)(LPCWSTR pszDir) override;
165     STDMETHOD(GetArguments)(LPWSTR pszArgs, INT cchMaxPath) override;
166     STDMETHOD(SetArguments)(LPCWSTR pszArgs) override;
167     // STDMETHOD(GetHotkey)(WORD *pwHotkey) override;
168     // STDMETHOD(SetHotkey)(WORD wHotkey) override;
169     // STDMETHOD(GetShowCmd)(INT *piShowCmd) override;
170     // STDMETHOD(SetShowCmd)(INT iShowCmd) override;
171     STDMETHOD(GetIconLocation)(LPWSTR pszIconPath, INT cchIconPath, INT *piIcon) override;
172     STDMETHOD(SetIconLocation)(LPCWSTR pszIconPath, INT iIcon) override;
173     STDMETHOD(SetRelativePath)(LPCWSTR pszPathRel, DWORD dwReserved) override;
174     // STDMETHOD(Resolve)(HWND hwnd, DWORD fFlags) override;
175     STDMETHOD(SetPath)(LPCWSTR pszFile) override;
176 
177     // IShellLinkDataList
178     STDMETHOD(AddDataBlock)(void *pDataBlock) override;
179     STDMETHOD(CopyDataBlock)(DWORD dwSig, void **ppDataBlock) override;
180     STDMETHOD(RemoveDataBlock)(DWORD dwSig) override;
181     STDMETHOD(GetFlags)(DWORD *pdwFlags) override;
182     STDMETHOD(SetFlags)(DWORD dwFlags) override;
183 
184     // IExtractIconA
185     STDMETHOD(Extract)(PCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize) override;
186     STDMETHOD(GetIconLocation)(UINT uFlags, PSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags) override;
187 
188     // IExtractIconW
189     STDMETHOD(Extract)(PCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize) override;
190     STDMETHOD(GetIconLocation)(UINT uFlags, PWSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags) override;
191 
192     // IShellExtInit
193     STDMETHOD(Initialize)(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID) override;
194 
195     // IContextMenu
196     STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) override;
197     STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici) override;
198     STDMETHOD(GetCommandString)(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax) override;
199 
200     // IShellPropSheetExt
201     STDMETHOD(AddPages)(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam) override;
202     STDMETHOD(ReplacePage)(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam) override;
203 
204     // IObjectWithSite
205     STDMETHOD(SetSite)(IUnknown *punk) override;
206     STDMETHOD(GetSite)(REFIID iid, void **ppvSite) override;
207 
208     // IDropTarget
209     STDMETHOD(DragEnter)(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect) override;
210     STDMETHOD(DragOver)(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect) override;
211     STDMETHOD(DragLeave)() override;
212     STDMETHOD(Drop)(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect) override;
213 
214 DECLARE_REGISTRY_RESOURCEID(IDR_SHELLLINK)
215 DECLARE_NOT_AGGREGATABLE(CShellLink)
216 
217 DECLARE_PROTECT_FINAL_CONSTRUCT()
218 
219 BEGIN_COM_MAP(CShellLink)
220     COM_INTERFACE_ENTRY_IID(IID_IShellLinkA, IShellLinkA)
221     COM_INTERFACE_ENTRY_IID(IID_IShellLinkW, IShellLinkW)
222     COM_INTERFACE_ENTRY2_IID(IID_IPersist, IPersist, IPersistFile)
223     COM_INTERFACE_ENTRY_IID(IID_IPersistFile, IPersistFile)
224     COM_INTERFACE_ENTRY_IID(IID_IPersistStream, IPersistStream)
225     COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit)
226     COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu) // Technically it should be IContextMenu3
227     COM_INTERFACE_ENTRY_IID(IID_IDropTarget, IDropTarget)
228 //  COM_INTERFACE_ENTRY_IID(IID_IQueryInfo, IQueryInfo)
229     COM_INTERFACE_ENTRY_IID(IID_IShellLinkDataList, IShellLinkDataList)
230     COM_INTERFACE_ENTRY_IID(IID_IExtractIconA, IExtractIconA)
231     COM_INTERFACE_ENTRY_IID(IID_IExtractIconW, IExtractIconW)
232 //  COM_INTERFACE_ENTRY_IID(IID_IExtractImage2, IExtractImage2)
233 //  COM_INTERFACE_ENTRY_IID(IID_IPersistPropertyBag, IPersistPropertyBag)
234 //  COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
235 //  COM_INTERFACE_ENTRY_IID(IID_IFilter, IFilter)
236     COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite)
237 //  COM_INTERFACE_ENTRY_IID(IID_ICustomizeInfoTip, ICustomizeInfoTip)
238     COM_INTERFACE_ENTRY_IID(IID_IShellPropSheetExt, IShellPropSheetExt)
239 END_COM_MAP()
240 };
241 
242 #endif /* _SHELLLINK_H_ */
243