|
5 | 5 | using System.Text; |
6 | 6 | using Windows.Win32; |
7 | 7 | using Windows.Win32.Foundation; |
| 8 | +using Windows.Win32.System.Com; |
8 | 9 | using Windows.Win32.System.SystemServices; |
9 | 10 | using Windows.Win32.UI.Shell; |
10 | 11 | using Windows.Win32.UI.Shell.PropertiesSystem; |
@@ -136,13 +137,65 @@ public unsafe static HRESULT TryGetShellTooltip(this IWindowsStorable storable, |
136 | 137 | return HRESULT.S_OK; |
137 | 138 | } |
138 | 139 |
|
139 | | - public unsafe static HRESULT TryPinFolderToQuickAccess() |
| 140 | + public unsafe static HRESULT TryPinFolderToQuickAccess(this IWindowsFolder @this) |
140 | 141 | { |
| 142 | + HRESULT hr = default; |
| 143 | + |
| 144 | + using ComPtr<IExecuteCommand> pExecuteCommand = default; |
| 145 | + using ComPtr<IObjectWithSelection> pObjectWithSelection = default; |
| 146 | + |
| 147 | + hr = PInvoke.CoCreateInstance(CLSID.CLSID_PinToFrequentExecute, null, CLSCTX.CLSCTX_INPROC_SERVER, IID.IID_IExecuteCommand, (void**)pExecuteCommand.GetAddressOf()); |
| 148 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 149 | + return hr; |
| 150 | + |
| 151 | + using ComPtr<IShellItemArray> pShellItemArray = default; |
| 152 | + hr = PInvoke.SHCreateShellItemArrayFromShellItem(@this.ThisPtr, IID.IID_IShellItemArray, (void**)pShellItemArray.GetAddressOf()); |
| 153 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 154 | + return hr; |
| 155 | + |
| 156 | + hr = pExecuteCommand.Get()->QueryInterface(IID.IID_IObjectWithSelection, (void**)pObjectWithSelection.GetAddressOf()); |
| 157 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 158 | + return hr; |
| 159 | + |
| 160 | + hr = pObjectWithSelection.Get()->SetSelection(pShellItemArray.Get()); |
| 161 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 162 | + return hr; |
| 163 | + |
| 164 | + hr = pExecuteCommand.Get()->Execute(); |
| 165 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 166 | + return hr; |
| 167 | + |
141 | 168 | return HRESULT.S_OK; |
142 | 169 | } |
143 | 170 |
|
144 | | - public unsafe static HRESULT TryUnpinFolderFromQuickAccess() |
| 171 | + public unsafe static HRESULT TryUnpinFolderFromQuickAccess(this IWindowsFolder @this) |
145 | 172 | { |
| 173 | + HRESULT hr = default; |
| 174 | + |
| 175 | + using ComPtr<IExecuteCommand> pExecuteCommand = default; |
| 176 | + using ComPtr<IObjectWithSelection> pObjectWithSelection = default; |
| 177 | + |
| 178 | + hr = PInvoke.CoCreateInstance(CLSID.CLSID_UnPinFromFrequentExecute, null, CLSCTX.CLSCTX_INPROC_SERVER, IID.IID_IExecuteCommand, (void**)pExecuteCommand.GetAddressOf()); |
| 179 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 180 | + return hr; |
| 181 | + |
| 182 | + using ComPtr<IShellItemArray> pShellItemArray = default; |
| 183 | + hr = PInvoke.SHCreateShellItemArrayFromShellItem(@this.ThisPtr, IID.IID_IShellItemArray, (void**)pShellItemArray.GetAddressOf()); |
| 184 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 185 | + return hr; |
| 186 | + |
| 187 | + hr = pExecuteCommand.Get()->QueryInterface(IID.IID_IObjectWithSelection, (void**)pObjectWithSelection.GetAddressOf()); |
| 188 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 189 | + return hr; |
| 190 | + |
| 191 | + hr = pObjectWithSelection.Get()->SetSelection(pShellItemArray.Get()); |
| 192 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 193 | + return hr; |
| 194 | + |
| 195 | + hr = pExecuteCommand.Get()->Execute(); |
| 196 | + if (hr.ThrowIfFailedOnDebug().Failed) |
| 197 | + return hr; |
| 198 | + |
146 | 199 | return HRESULT.S_OK; |
147 | 200 | } |
148 | 201 | } |
|
0 commit comments