xref: /reactos/dll/win32/shell32/CShellLink.h (revision 50cf16b3)
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 
55     struct volume_info
56     {
57         DWORD type;
58         DWORD serial;
59         WCHAR label[12];  /* assume 8.3 */
60     };
61 
62     #include "poppack.h"
63 
64 private:
65     /* Cached link header */
66     SHELL_LINK_HEADER m_Header;
67 
68     /* Cached data set according to m_Header.dwFlags (SHELL_LINK_DATA_FLAGS) */
69 
70     LPITEMIDLIST  m_pPidl;
71 
72     /* Link tracker information */
73     LPWSTR        m_sPath;
74     volume_info   volume;
75 
76     LPWSTR        m_sDescription;
77     LPWSTR        m_sPathRel;
78     LPWSTR        m_sWorkDir;
79     LPWSTR        m_sArgs;
80     LPWSTR        m_sIcoPath;
81     BOOL          m_bRunAs;
82     BOOL          m_bDirty;
83     LPDBLIST      m_pDBList; /* Optional data block list (in the extra data section) */
84     BOOL          m_bInInit;    // in initialization or not
85     HICON         m_hIcon;
86 
87     /* Pointers to strings inside Logo3/Darwin info blocks, cached for debug info purposes only */
88     LPWSTR sProduct;
89     LPWSTR sComponent;
90 
91     LPWSTR        m_sLinkPath;
92     INT           m_iIdOpen;     /* ID of the "Open" entry in the context menu */
93 
94     CComPtr<IUnknown>    m_site;
95     CComPtr<IDropTarget> m_DropTarget;
96 
97     VOID Reset();
98 
99     HRESULT GetAdvertiseInfo(LPWSTR *str, DWORD dwSig);
100     HRESULT SetAdvertiseInfo(LPCWSTR str);
101     HRESULT WriteAdvertiseInfo(LPCWSTR string, DWORD dwSig);
102     HRESULT SetTargetFromPIDLOrPath(LPCITEMIDLIST pidl, LPCWSTR pszFile);
103     HICON CreateShortcutIcon(LPCWSTR wszIconPath, INT IconIndex);
104 
105 public:
106     CShellLink();
107     ~CShellLink();
108     static INT_PTR CALLBACK SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
109 
110     BOOL OnInitDialog(HWND hwndDlg, HWND hwndFocus, LPARAM lParam);
111     void OnCommand(HWND hwndDlg, int id, HWND hwndCtl, UINT codeNotify);
112     LRESULT OnNotify(HWND hwndDlg, int idFrom, LPNMHDR pnmhdr);
113     void OnDestroy(HWND hwndDlg);
114 
115     // IPersistFile
116     virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pclsid);
117     virtual HRESULT STDMETHODCALLTYPE IsDirty();
118     virtual HRESULT STDMETHODCALLTYPE Load(LPCOLESTR pszFileName, DWORD dwMode);
119     virtual HRESULT STDMETHODCALLTYPE Save(LPCOLESTR pszFileName, BOOL fRemember);
120     virtual HRESULT STDMETHODCALLTYPE SaveCompleted(LPCOLESTR pszFileName);
121     virtual HRESULT STDMETHODCALLTYPE GetCurFile(LPOLESTR *ppszFileName);
122 
123     // IPersistStream
124     // virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pclsid);
125     // virtual HRESULT STDMETHODCALLTYPE IsDirty();
126     virtual HRESULT STDMETHODCALLTYPE Load(IStream *stm);
127     virtual HRESULT STDMETHODCALLTYPE Save(IStream *stm, BOOL fClearDirty);
128     virtual HRESULT STDMETHODCALLTYPE GetSizeMax(ULARGE_INTEGER *pcbSize);
129 
130     // IShellLinkA
131     virtual HRESULT STDMETHODCALLTYPE GetPath(LPSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags);
132     virtual HRESULT STDMETHODCALLTYPE GetIDList(LPITEMIDLIST *ppidl);
133     virtual HRESULT STDMETHODCALLTYPE SetIDList(LPCITEMIDLIST pidl);
134     virtual HRESULT STDMETHODCALLTYPE GetDescription(LPSTR pszName, INT cchMaxName);
135     virtual HRESULT STDMETHODCALLTYPE SetDescription(LPCSTR pszName);
136     virtual HRESULT STDMETHODCALLTYPE GetWorkingDirectory(LPSTR pszDir, INT cchMaxPath);
137     virtual HRESULT STDMETHODCALLTYPE SetWorkingDirectory(LPCSTR pszDir);
138     virtual HRESULT STDMETHODCALLTYPE GetArguments(LPSTR pszArgs, INT cchMaxPath);
139     virtual HRESULT STDMETHODCALLTYPE SetArguments(LPCSTR pszArgs);
140     virtual HRESULT STDMETHODCALLTYPE GetHotkey(WORD *pwHotkey);
141     virtual HRESULT STDMETHODCALLTYPE SetHotkey(WORD wHotkey);
142     virtual HRESULT STDMETHODCALLTYPE GetShowCmd(INT *piShowCmd);
143     virtual HRESULT STDMETHODCALLTYPE SetShowCmd(INT iShowCmd);
144     virtual HRESULT STDMETHODCALLTYPE GetIconLocation(LPSTR pszIconPath, INT cchIconPath, INT *piIcon);
145     virtual HRESULT STDMETHODCALLTYPE SetIconLocation(LPCSTR pszIconPath, INT iIcon);
146     virtual HRESULT STDMETHODCALLTYPE SetRelativePath(LPCSTR pszPathRel, DWORD dwReserved);
147     virtual HRESULT STDMETHODCALLTYPE Resolve(HWND hwnd, DWORD fFlags);
148     virtual HRESULT STDMETHODCALLTYPE SetPath(LPCSTR pszFile);
149 
150     // IShellLinkW
151     virtual HRESULT STDMETHODCALLTYPE GetPath(LPWSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags);
152     // virtual HRESULT STDMETHODCALLTYPE GetIDList(LPITEMIDLIST *ppidl);
153     // virtual HRESULT STDMETHODCALLTYPE SetIDList(LPCITEMIDLIST pidl);
154     virtual HRESULT STDMETHODCALLTYPE GetDescription(LPWSTR pszName, INT cchMaxName);
155     virtual HRESULT STDMETHODCALLTYPE SetDescription(LPCWSTR pszName);
156     virtual HRESULT STDMETHODCALLTYPE GetWorkingDirectory(LPWSTR pszDir, INT cchMaxPath);
157     virtual HRESULT STDMETHODCALLTYPE SetWorkingDirectory(LPCWSTR pszDir);
158     virtual HRESULT STDMETHODCALLTYPE GetArguments(LPWSTR pszArgs, INT cchMaxPath);
159     virtual HRESULT STDMETHODCALLTYPE SetArguments(LPCWSTR pszArgs);
160     // virtual HRESULT STDMETHODCALLTYPE GetHotkey(WORD *pwHotkey);
161     // virtual HRESULT STDMETHODCALLTYPE SetHotkey(WORD wHotkey);
162     // virtual HRESULT STDMETHODCALLTYPE GetShowCmd(INT *piShowCmd);
163     // virtual HRESULT STDMETHODCALLTYPE SetShowCmd(INT iShowCmd);
164     virtual HRESULT STDMETHODCALLTYPE GetIconLocation(LPWSTR pszIconPath, INT cchIconPath, INT *piIcon);
165     virtual HRESULT STDMETHODCALLTYPE SetIconLocation(LPCWSTR pszIconPath, INT iIcon);
166     virtual HRESULT STDMETHODCALLTYPE SetRelativePath(LPCWSTR pszPathRel, DWORD dwReserved);
167     // virtual HRESULT STDMETHODCALLTYPE Resolve(HWND hwnd, DWORD fFlags);
168     virtual HRESULT STDMETHODCALLTYPE SetPath(LPCWSTR pszFile);
169 
170     // IShellLinkDataList
171     virtual HRESULT STDMETHODCALLTYPE AddDataBlock(void *pDataBlock);
172     virtual HRESULT STDMETHODCALLTYPE CopyDataBlock(DWORD dwSig, void **ppDataBlock);
173     virtual HRESULT STDMETHODCALLTYPE RemoveDataBlock(DWORD dwSig);
174     virtual HRESULT STDMETHODCALLTYPE GetFlags(DWORD *pdwFlags);
175     virtual HRESULT STDMETHODCALLTYPE SetFlags(DWORD dwFlags);
176 
177     // IExtractIconA
178     virtual HRESULT STDMETHODCALLTYPE Extract(PCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize);
179     virtual HRESULT STDMETHODCALLTYPE GetIconLocation(UINT uFlags, PSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags);
180 
181     // IExtractIconW
182     virtual HRESULT STDMETHODCALLTYPE Extract(PCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize);
183     virtual HRESULT STDMETHODCALLTYPE GetIconLocation(UINT uFlags, PWSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags);
184 
185     // IShellExtInit
186     virtual HRESULT STDMETHODCALLTYPE Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID);
187 
188     // IContextMenu
189     virtual HRESULT STDMETHODCALLTYPE QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
190     virtual HRESULT STDMETHODCALLTYPE InvokeCommand(LPCMINVOKECOMMANDINFO lpici);
191     virtual HRESULT STDMETHODCALLTYPE GetCommandString(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax);
192 
193     // IShellPropSheetExt
194     virtual HRESULT STDMETHODCALLTYPE AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam);
195     virtual HRESULT STDMETHODCALLTYPE ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam);
196 
197     // IObjectWithSite
198     virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown *punk);
199     virtual HRESULT STDMETHODCALLTYPE GetSite(REFIID iid, void **ppvSite);
200 
201     // IDropTarget
202     virtual HRESULT STDMETHODCALLTYPE DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect);
203     virtual HRESULT STDMETHODCALLTYPE DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect);
204     virtual HRESULT STDMETHODCALLTYPE DragLeave();
205     virtual HRESULT STDMETHODCALLTYPE Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect);
206 
207 DECLARE_REGISTRY_RESOURCEID(IDR_SHELLLINK)
208 DECLARE_NOT_AGGREGATABLE(CShellLink)
209 
210 DECLARE_PROTECT_FINAL_CONSTRUCT()
211 
212 BEGIN_COM_MAP(CShellLink)
213     COM_INTERFACE_ENTRY_IID(IID_IShellLinkA, IShellLinkA)
214     COM_INTERFACE_ENTRY_IID(IID_IShellLinkW, IShellLinkW)
215     COM_INTERFACE_ENTRY2_IID(IID_IPersist, IPersist, IPersistFile)
216     COM_INTERFACE_ENTRY_IID(IID_IPersistFile, IPersistFile)
217     COM_INTERFACE_ENTRY_IID(IID_IPersistStream, IPersistStream)
218     COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit)
219     COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu) // Technically it should be IContextMenu3
220     COM_INTERFACE_ENTRY_IID(IID_IDropTarget, IDropTarget)
221 //  COM_INTERFACE_ENTRY_IID(IID_IQueryInfo, IQueryInfo)
222     COM_INTERFACE_ENTRY_IID(IID_IShellLinkDataList, IShellLinkDataList)
223     COM_INTERFACE_ENTRY_IID(IID_IExtractIconA, IExtractIconA)
224     COM_INTERFACE_ENTRY_IID(IID_IExtractIconW, IExtractIconW)
225 //  COM_INTERFACE_ENTRY_IID(IID_IExtractImage2, IExtractImage2)
226 //  COM_INTERFACE_ENTRY_IID(IID_IPersistPropertyBag, IPersistPropertyBag)
227 //  COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
228 //  COM_INTERFACE_ENTRY_IID(IID_IFilter, IFilter)
229     COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite)
230 //  COM_INTERFACE_ENTRY_IID(IID_ICustomizeInfoTip, ICustomizeInfoTip)
231     COM_INTERFACE_ENTRY_IID(IID_IShellPropSheetExt, IShellPropSheetExt)
232 END_COM_MAP()
233 };
234 
235 #endif /* _SHELLLINK_H_ */
236