ShellProvider.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. /**************************************************************************\
  11. Copyright Microsoft Corporation. All Rights Reserved.
  12. \**************************************************************************/
  13. namespace Standard
  14. {
  15. using System;
  16. using System.Runtime.InteropServices;
  17. using System.Runtime.InteropServices.ComTypes;
  18. using System.Text;
  19. using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
  20. #region Enums and Static Property Classes
  21. /// <summary>ShellItem attribute flags. SIATTRIBFLAGS_*</summary>
  22. internal enum SIATTRIBFLAGS
  23. {
  24. AND = 0x00000001,
  25. OR = 0x00000002,
  26. APPCOMPAT = 0x00000003,
  27. }
  28. internal enum APPDOCLISTTYPE
  29. {
  30. ADLT_RECENT = 0, // The recently used documents list
  31. ADLT_FREQUENT, // The frequently used documents list
  32. }
  33. /// <summary>
  34. /// Flags for SetTabProperties. STPF_*
  35. /// </summary>
  36. /// <remarks>The native enum was called STPFLAG.</remarks>
  37. [Flags]
  38. internal enum STPF
  39. {
  40. NONE = 0x00000000,
  41. USEAPPTHUMBNAILALWAYS = 0x00000001,
  42. USEAPPTHUMBNAILWHENACTIVE = 0x00000002,
  43. USEAPPPEEKALWAYS = 0x00000004,
  44. USEAPPPEEKWHENACTIVE = 0x00000008,
  45. }
  46. /// <summary>
  47. /// Flags for Setting Taskbar Progress state. TBPF_*
  48. /// </summary>
  49. /// <remarks>
  50. /// The native enum was called TBPFLAG.
  51. /// </remarks>
  52. internal enum TBPF
  53. {
  54. NOPROGRESS = 0x00000000,
  55. INDETERMINATE = 0x00000001,
  56. NORMAL = 0x00000002,
  57. ERROR = 0x00000004,
  58. PAUSED = 0x00000008,
  59. }
  60. /// <summary>
  61. /// THUMBBUTTON mask. THB_*
  62. /// </summary>
  63. [Flags]
  64. internal enum THB : uint
  65. {
  66. BITMAP = 0x0001,
  67. ICON = 0x0002,
  68. TOOLTIP = 0x0004,
  69. FLAGS = 0x0008,
  70. }
  71. /// <summary>
  72. /// THUMBBUTTON flags. THBF_*
  73. /// </summary>
  74. [Flags]
  75. internal enum THBF : uint
  76. {
  77. ENABLED = 0x0000,
  78. DISABLED = 0x0001,
  79. DISMISSONCLICK = 0x0002,
  80. NOBACKGROUND = 0x0004,
  81. HIDDEN = 0x0008,
  82. // Added post-beta
  83. NONINTERACTIVE = 0x0010,
  84. }
  85. /// <summary>
  86. /// GetPropertyStoreFlags. GPS_*.
  87. /// </summary>
  88. /// <remarks>
  89. /// These are new for Vista, but are used in downlevel components
  90. /// </remarks>
  91. internal enum GPS
  92. {
  93. // If no flags are specified (GPS_DEFAULT), a read-only property store is returned that includes properties for the file or item.
  94. // In the case that the shell item is a file, the property store contains:
  95. // 1. properties about the file from the file system
  96. // 2. properties from the file itself provided by the file's property handler, unless that file is offline,
  97. // see GPS_OPENSLOWITEM
  98. // 3. if requested by the file's property handler and supported by the file system, properties stored in the
  99. // alternate property store.
  100. //
  101. // Non-file shell items should return a similar read-only store
  102. //
  103. // Specifying other GPS_ flags modifies the store that is returned
  104. DEFAULT = 0x00000000,
  105. HANDLERPROPERTIESONLY = 0x00000001, // only include properties directly from the file's property handler
  106. READWRITE = 0x00000002, // Writable stores will only include handler properties
  107. TEMPORARY = 0x00000004, // A read/write store that only holds properties for the lifetime of the IShellItem object
  108. FASTPROPERTIESONLY = 0x00000008, // do not include any properties from the file's property handler (because the file's property handler will hit the disk)
  109. OPENSLOWITEM = 0x00000010, // include properties from a file's property handler, even if it means retrieving the file from offline storage.
  110. DELAYCREATION = 0x00000020, // delay the creation of the file's property handler until those properties are read, written, or enumerated
  111. BESTEFFORT = 0x00000040, // For readonly stores, succeed and return all available properties, even if one or more sources of properties fails. Not valid with GPS_READWRITE.
  112. NO_OPLOCK = 0x00000080, // some data sources protect the read property store with an oplock, this disables that
  113. MASK_VALID = 0x000000FF,
  114. }
  115. /// <summary>
  116. /// KNOWNDESTCATEGORY. KDC_*
  117. /// </summary>
  118. internal enum KDC
  119. {
  120. FREQUENT = 1,
  121. RECENT,
  122. }
  123. // IShellFolder::GetAttributesOf flags
  124. [Flags]
  125. internal enum SFGAO : uint
  126. {
  127. /// <summary>Objects can be copied</summary>
  128. /// <remarks>DROPEFFECT_COPY</remarks>
  129. CANCOPY = 0x1,
  130. /// <summary>Objects can be moved</summary>
  131. /// <remarks>DROPEFFECT_MOVE</remarks>
  132. CANMOVE = 0x2,
  133. /// <summary>Objects can be linked</summary>
  134. /// <remarks>
  135. /// DROPEFFECT_LINK.
  136. ///
  137. /// If this bit is set on an item in the shell folder, a
  138. /// 'Create Shortcut' menu item will be added to the File
  139. /// menu and context menus for the item. If the user selects
  140. /// that command, your IContextMenu::InvokeCommand() will be called
  141. /// with 'link'.
  142. /// That flag will also be used to determine if 'Create Shortcut'
  143. /// should be added when the item in your folder is dragged to another
  144. /// folder.
  145. /// </remarks>
  146. CANLINK = 0x4,
  147. /// <summary>supports BindToObject(IID_IStorage)</summary>
  148. STORAGE = 0x00000008,
  149. /// <summary>Objects can be renamed</summary>
  150. CANRENAME = 0x00000010,
  151. /// <summary>Objects can be deleted</summary>
  152. CANDELETE = 0x00000020,
  153. /// <summary>Objects have property sheets</summary>
  154. HASPROPSHEET = 0x00000040,
  155. // unused = 0x00000080,
  156. /// <summary>Objects are drop target</summary>
  157. DROPTARGET = 0x00000100,
  158. CAPABILITYMASK = 0x00000177,
  159. // unused = 0x00000200,
  160. // unused = 0x00000400,
  161. // unused = 0x00000800,
  162. // unused = 0x00001000,
  163. /// <summary>Object is encrypted (use alt color)</summary>
  164. ENCRYPTED = 0x00002000,
  165. /// <summary>'Slow' object</summary>
  166. ISSLOW = 0x00004000,
  167. /// <summary>Ghosted icon</summary>
  168. GHOSTED = 0x00008000,
  169. /// <summary>Shortcut (link)</summary>
  170. LINK = 0x00010000,
  171. /// <summary>Shared</summary>
  172. SHARE = 0x00020000,
  173. /// <summary>Read-only</summary>
  174. READONLY = 0x00040000,
  175. /// <summary> Hidden object</summary>
  176. HIDDEN = 0x00080000,
  177. DISPLAYATTRMASK = 0x000FC000,
  178. /// <summary> May contain children with SFGAO_FILESYSTEM</summary>
  179. FILESYSANCESTOR = 0x10000000,
  180. /// <summary>Support BindToObject(IID_IShellFolder)</summary>
  181. FOLDER = 0x20000000,
  182. /// <summary>Is a win32 file system object (file/folder/root)</summary>
  183. FILESYSTEM = 0x40000000,
  184. /// <summary>May contain children with SFGAO_FOLDER (may be slow)</summary>
  185. HASSUBFOLDER = 0x80000000,
  186. CONTENTSMASK = 0x80000000,
  187. /// <summary>Invalidate cached information (may be slow)</summary>
  188. VALIDATE = 0x01000000,
  189. /// <summary>Is this removeable media?</summary>
  190. REMOVABLE = 0x02000000,
  191. /// <summary> Object is compressed (use alt color)</summary>
  192. COMPRESSED = 0x04000000,
  193. /// <summary>Supports IShellFolder, but only implements CreateViewObject() (non-folder view)</summary>
  194. BROWSABLE = 0x08000000,
  195. /// <summary>Is a non-enumerated object (should be hidden)</summary>
  196. NONENUMERATED = 0x00100000,
  197. /// <summary>Should show bold in explorer tree</summary>
  198. NEWCONTENT = 0x00200000,
  199. /// <summary>Obsolete</summary>
  200. CANMONIKER = 0x00400000,
  201. /// <summary>Obsolete</summary>
  202. HASSTORAGE = 0x00400000,
  203. /// <summary>Supports BindToObject(IID_IStream)</summary>
  204. STREAM = 0x00400000,
  205. /// <summary>May contain children with SFGAO_STORAGE or SFGAO_STREAM</summary>
  206. STORAGEANCESTOR = 0x00800000,
  207. /// <summary>For determining storage capabilities, ie for open/save semantics</summary>
  208. STORAGECAPMASK = 0x70C50008,
  209. /// <summary>
  210. /// Attributes that are masked out for PKEY_SFGAOFlags because they are considered
  211. /// to cause slow calculations or lack context
  212. /// (SFGAO_VALIDATE | SFGAO_ISSLOW | SFGAO_HASSUBFOLDER and others)
  213. /// </summary>
  214. PKEYSFGAOMASK = 0x81044000,
  215. }
  216. /// <summary>
  217. /// IShellFolder::EnumObjects grfFlags bits. Also called SHCONT
  218. /// </summary>
  219. internal enum SHCONTF
  220. {
  221. CHECKING_FOR_CHILDREN = 0x0010, // hint that client is checking if (what) child items the folder contains - not all details (e.g. short file name) are needed
  222. FOLDERS = 0x0020, // only want folders enumerated (SFGAO_FOLDER)
  223. NONFOLDERS = 0x0040, // include non folders (items without SFGAO_FOLDER)
  224. INCLUDEHIDDEN = 0x0080, // show items normally hidden (items with SFGAO_HIDDEN)
  225. INIT_ON_FIRST_NEXT = 0x0100, // DEFUNCT - this is always assumed
  226. NETPRINTERSRCH = 0x0200, // hint that client is looking for printers
  227. SHAREABLE = 0x0400, // hint that client is looking sharable resources (local drives or hidden root shares)
  228. STORAGE = 0x0800, // include all items with accessible storage and their ancestors
  229. NAVIGATION_ENUM = 0x1000, // mark child folders to indicate that they should provide a "navigation" enumeration by default
  230. FASTITEMS = 0x2000, // hint that client is only interested in items that can be enumerated quickly
  231. FLATLIST = 0x4000, // enumerate items as flat list even if folder is stacked
  232. ENABLE_ASYNC = 0x8000, // inform enumerator that client is listening for change notifications so enumerator does not need to be complete, items can be reported via change notifications
  233. }
  234. /// <summary>
  235. /// IShellFolder::GetDisplayNameOf/SetNameOf uFlags. Also called SHGDNF.
  236. /// </summary>
  237. /// <remarks>
  238. /// For compatibility with SIGDN, these bits must all sit in the LOW word.
  239. /// </remarks>
  240. [Flags]
  241. internal enum SHGDN
  242. {
  243. SHGDN_NORMAL = 0x0000, // default (display purpose)
  244. SHGDN_INFOLDER = 0x0001, // displayed under a folder (relative)
  245. SHGDN_FOREDITING = 0x1000, // for in-place editing
  246. SHGDN_FORADDRESSBAR = 0x4000, // UI friendly parsing name (remove ugly stuff)
  247. SHGDN_FORPARSING = 0x8000, // parsing name for ParseDisplayName()
  248. }
  249. /// <summary>
  250. /// SHELLITEMCOMPAREHINTF. SICHINT_*.
  251. /// </summary>
  252. internal enum SICHINT : uint
  253. {
  254. /// <summary>iOrder based on display in a folder view</summary>
  255. DISPLAY = 0x00000000,
  256. /// <summary>exact instance compare</summary>
  257. ALLFIELDS = 0x80000000,
  258. /// <summary>iOrder based on canonical name (better performance)</summary>
  259. CANONICAL = 0x10000000,
  260. TEST_FILESYSPATH_IF_NOT_EQUAL = 0x20000000,
  261. };
  262. /// <summary>
  263. /// ShellItem enum. SIGDN_*.
  264. /// </summary>
  265. internal enum SIGDN : uint
  266. { // lower word (& with 0xFFFF)
  267. NORMALDISPLAY = 0x00000000, // SHGDN_NORMAL
  268. PARENTRELATIVEPARSING = 0x80018001, // SHGDN_INFOLDER | SHGDN_FORPARSING
  269. DESKTOPABSOLUTEPARSING = 0x80028000, // SHGDN_FORPARSING
  270. PARENTRELATIVEEDITING = 0x80031001, // SHGDN_INFOLDER | SHGDN_FOREDITING
  271. DESKTOPABSOLUTEEDITING = 0x8004c000, // SHGDN_FORPARSING | SHGDN_FORADDRESSBAR
  272. FILESYSPATH = 0x80058000, // SHGDN_FORPARSING
  273. URL = 0x80068000, // SHGDN_FORPARSING
  274. PARENTRELATIVEFORADDRESSBAR = 0x8007c001, // SHGDN_INFOLDER | SHGDN_FORPARSING | SHGDN_FORADDRESSBAR
  275. PARENTRELATIVE = 0x80080001, // SHGDN_INFOLDER
  276. }
  277. /// <summary>
  278. /// STR_GPS_*
  279. /// </summary>
  280. /// <remarks>
  281. /// When requesting a property store through IShellFolder, you can specify the equivalent of
  282. /// GPS_DEFAULT by passing in a null IBindCtx parameter.
  283. ///
  284. /// You can specify the equivalent of GPS_READWRITE by passing a mode of STGM_READWRITE | STGM_EXCLUSIVE
  285. /// in the bind context
  286. ///
  287. /// Here are the string versions of GPS_ flags, passed to IShellFolder::BindToObject() via IBindCtx::RegisterObjectParam()
  288. /// These flags are valid when requesting an IPropertySetStorage or IPropertyStore handler
  289. ///
  290. /// The meaning of these flags are described above.
  291. ///
  292. /// There is no STR_ equivalent for GPS_TEMPORARY because temporary property stores
  293. /// are provided by IShellItem2 only -- not by the underlying IShellFolder.
  294. /// </remarks>
  295. internal static class STR_GPS
  296. {
  297. public const string HANDLERPROPERTIESONLY = "GPS_HANDLERPROPERTIESONLY";
  298. public const string FASTPROPERTIESONLY = "GPS_FASTPROPERTIESONLY";
  299. public const string OPENSLOWITEM = "GPS_OPENSLOWITEM";
  300. public const string DELAYCREATION = "GPS_DELAYCREATION";
  301. public const string BESTEFFORT = "GPS_BESTEFFORT";
  302. public const string NO_OPLOCK = "GPS_NO_OPLOCK";
  303. }
  304. #endregion
  305. #region Structs
  306. [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Unicode)]
  307. internal struct THUMBBUTTON
  308. {
  309. /// <summary>
  310. /// WPARAM value for a THUMBBUTTON being clicked.
  311. /// </summary>
  312. public const int THBN_CLICKED = 0x1800;
  313. public THB dwMask;
  314. public uint iId;
  315. public uint iBitmap;
  316. public IntPtr hIcon;
  317. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
  318. public string szTip;
  319. public THBF dwFlags;
  320. }
  321. [StructLayout(LayoutKind.Sequential, Pack = 4)]
  322. internal struct PKEY
  323. {
  324. /// <summary>fmtid</summary>
  325. private readonly Guid _fmtid;
  326. /// <summary>pid</summary>
  327. private readonly uint _pid;
  328. public PKEY(Guid fmtid, uint pid)
  329. {
  330. _fmtid = fmtid;
  331. _pid = pid;
  332. }
  333. /// <summary>PKEY_Title</summary>
  334. public static readonly PKEY Title = new PKEY(new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9"), 2);
  335. /// <summary>PKEY_AppUserModel_ID</summary>
  336. public static readonly PKEY AppUserModel_ID = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 5);
  337. /// <summary>PKEY_AppUserModel_IsDestListSeparator</summary>
  338. public static readonly PKEY AppUserModel_IsDestListSeparator = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 6);
  339. /// <summary>PKEY_AppUserModel_RelaunchCommand</summary>
  340. public static readonly PKEY AppUserModel_RelaunchCommand = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 2);
  341. /// <summary>PKEY_AppUserModel_RelaunchDisplayNameResource</summary>
  342. public static readonly PKEY AppUserModel_RelaunchDisplayNameResource = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 4);
  343. /// <summary>PKEY_AppUserModel_RelaunchIconResource</summary>
  344. public static readonly PKEY AppUserModel_RelaunchIconResource = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 3);
  345. }
  346. #endregion
  347. #region Interfaces
  348. [
  349. ComImport,
  350. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  351. Guid(IID.EnumIdList),
  352. ]
  353. internal interface IEnumIDList
  354. {
  355. [PreserveSig()]
  356. HRESULT Next(uint celt, out IntPtr rgelt, out int pceltFetched);
  357. [PreserveSig()]
  358. HRESULT Skip(uint celt);
  359. void Reset();
  360. void Clone([Out, MarshalAs(UnmanagedType.Interface)] out IEnumIDList ppenum);
  361. }
  362. [
  363. ComImport,
  364. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  365. Guid(IID.EnumObjects),
  366. ]
  367. internal interface IEnumObjects
  368. {
  369. //[local]
  370. // This signature might not work... Hopefully don't need this interface though.
  371. void Next(uint celt, [In] ref Guid riid, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.IUnknown, IidParameterIndex = 1, SizeParamIndex = 0)] object[] rgelt, [Out] out uint pceltFetched);
  372. /*
  373. [call_as(Next)] HRESULT RemoteNext(
  374. [in] ULONG celt,
  375. [in] REFIID riid,
  376. [out, size_is(celt), length_is(*pceltFetched), iid_is(riid)] void **rgelt,
  377. [out] ULONG *pceltFetched);
  378. */
  379. void Skip(uint celt);
  380. void Reset();
  381. IEnumObjects Clone();
  382. }
  383. /// <summary>Unknown Object Array</summary>
  384. [
  385. ComImport,
  386. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  387. Guid(IID.ObjectArray),
  388. ]
  389. internal interface IObjectArray
  390. {
  391. uint GetCount();
  392. [return: MarshalAs(UnmanagedType.IUnknown)]
  393. object GetAt([In] uint uiIndex, [In] ref Guid riid);
  394. }
  395. [
  396. ComImport,
  397. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  398. Guid(IID.ObjectArray),
  399. ]
  400. interface IObjectCollection : IObjectArray
  401. {
  402. #region IObjectArray redeclarations
  403. new uint GetCount();
  404. [return: MarshalAs(UnmanagedType.IUnknown)]
  405. new object GetAt([In] uint uiIndex, [In] ref Guid riid);
  406. #endregion
  407. void AddObject([MarshalAs(UnmanagedType.IUnknown)] object punk);
  408. void AddFromArray(IObjectArray poaSource);
  409. void RemoveObjectAt(uint uiIndex);
  410. void Clear();
  411. }
  412. [
  413. ComImport,
  414. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  415. Guid(IID.PropertyStore)
  416. ]
  417. internal interface IPropertyStore
  418. {
  419. uint GetCount();
  420. PKEY GetAt(uint iProp);
  421. void GetValue([In] ref PKEY pkey, [In, Out] PROPVARIANT pv);
  422. void SetValue([In] ref PKEY pkey, PROPVARIANT pv);
  423. void Commit();
  424. }
  425. [
  426. ComImport,
  427. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  428. Guid(IID.ShellFolder),
  429. ]
  430. internal interface IShellFolder
  431. {
  432. void ParseDisplayName(
  433. [In] IntPtr hwnd,
  434. [In] IBindCtx pbc,
  435. [In, MarshalAs(UnmanagedType.LPWStr)] string pszDisplayName,
  436. [In, Out] ref int pchEaten,
  437. [Out] out IntPtr ppidl,
  438. [In, Out] ref uint pdwAttributes);
  439. IEnumIDList EnumObjects(
  440. [In] IntPtr hwnd,
  441. [In] SHCONTF grfFlags);
  442. // returns an instance of a sub-folder which is specified by the IDList (pidl).
  443. // IShellFolder or derived interfaces
  444. [return: MarshalAs(UnmanagedType.Interface)]
  445. object BindToObject(
  446. [In] IntPtr pidl,
  447. [In] IBindCtx pbc,
  448. [In] ref Guid riid);
  449. // produces the same result as BindToObject()
  450. [return: MarshalAs(UnmanagedType.Interface)]
  451. object BindToStorage([In] IntPtr pidl, [In] IBindCtx pbc, [In] ref Guid riid);
  452. // compares two IDLists and returns the result. The shell
  453. // explorer always passes 0 as lParam, which indicates 'sort by name'.
  454. // It should return 0 (as CODE of the scode), if two id indicates the
  455. // same object; negative value if pidl1 should be placed before pidl2;
  456. // positive value if pidl2 should be placed before pidl1.
  457. // use the macro ResultFromShort() to extract the result comparison
  458. // it deals with the casting and type conversion issues for you
  459. [PreserveSig]
  460. HRESULT CompareIDs([In] IntPtr lParam, [In] IntPtr pidl1, [In] IntPtr pidl2);
  461. // creates a view object of the folder itself. The view
  462. // object is a difference instance from the shell folder object.
  463. // 'hwndOwner' can be used as the owner window of its dialog box or
  464. // menu during the lifetime of the view object.
  465. // This member function should always create a new
  466. // instance which has only one reference count. The explorer may create
  467. // more than one instances of view object from one shell folder object
  468. // and treat them as separate instances.
  469. // returns IShellView derived interface
  470. [return: MarshalAs(UnmanagedType.Interface)]
  471. object CreateViewObject([In] IntPtr hwndOwner, [In] ref Guid riid);
  472. // returns the attributes of specified objects in that
  473. // folder. 'cidl' and 'apidl' specifies objects. 'apidl' contains only
  474. // simple IDLists. The explorer initializes *prgfInOut with a set of
  475. // flags to be evaluated. The shell folder may optimize the operation
  476. // by not returning unspecified flags.
  477. void GetAttributesOf(
  478. [In] uint cidl,
  479. [In] IntPtr apidl,
  480. [In, Out] ref SFGAO rgfInOut);
  481. // creates a UI object to be used for specified objects.
  482. // The shell explorer passes either IID_IDataObject (for transfer operation)
  483. // or IID_IContextMenu (for context menu operation) as riid
  484. // and many other interfaces
  485. [return: MarshalAs(UnmanagedType.Interface)]
  486. object GetUIObjectOf(
  487. [In] IntPtr hwndOwner,
  488. [In] uint cidl,
  489. [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.SysInt, SizeParamIndex = 2)] IntPtr apidl,
  490. [In] ref Guid riid,
  491. [In, Out] ref uint rgfReserved);
  492. // returns the display name of the specified object.
  493. // If the ID contains the display name (in the locale character set),
  494. // it returns the offset to the name. Otherwise, it returns a pointer
  495. // to the display name string (UNICODE), which is allocated by the
  496. // task allocator, or fills in a buffer.
  497. // use the helper APIS StrRetToStr() or StrRetToBuf() to deal with the different
  498. // forms of the STRRET structure
  499. void GetDisplayNameOf([In] IntPtr pidl, [In] SHGDN uFlags, [Out] out IntPtr pName);
  500. // sets the display name of the specified object.
  501. // If it changes the ID as well, it returns the new ID which is
  502. // alocated by the task allocator.
  503. void SetNameOf([In] IntPtr hwnd,
  504. [In] IntPtr pidl,
  505. [In, MarshalAs(UnmanagedType.LPWStr)] string pszName,
  506. [In] SHGDN uFlags,
  507. [Out] out IntPtr ppidlOut);
  508. }
  509. /// <summary>
  510. /// Shell Namespace helper
  511. /// </summary>
  512. [
  513. ComImport,
  514. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  515. Guid(IID.ShellItem),
  516. ]
  517. internal interface IShellItem
  518. {
  519. [return: MarshalAs(UnmanagedType.Interface)]
  520. object BindToHandler(IBindCtx pbc, [In] ref Guid bhid, [In] ref Guid riid);
  521. IShellItem GetParent();
  522. [return: MarshalAs(UnmanagedType.LPWStr)]
  523. string GetDisplayName(SIGDN sigdnName);
  524. SFGAO GetAttributes(SFGAO sfgaoMask);
  525. int Compare(IShellItem psi, SICHINT hint);
  526. }
  527. [
  528. ComImport,
  529. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  530. Guid(IID.ShellItemArray),
  531. ]
  532. internal interface IShellItemArray
  533. {
  534. [return: MarshalAs(UnmanagedType.Interface)]
  535. object BindToHandler(IBindCtx pbc, [In] ref Guid rbhid, [In] ref Guid riid);
  536. [return: MarshalAs(UnmanagedType.Interface)]
  537. object GetPropertyStore(int flags, [In] ref Guid riid);
  538. [return: MarshalAs(UnmanagedType.Interface)]
  539. object GetPropertyDescriptionList([In] ref PKEY keyType, [In] ref Guid riid);
  540. uint GetAttributes(SIATTRIBFLAGS dwAttribFlags, uint sfgaoMask);
  541. uint GetCount();
  542. IShellItem GetItemAt(uint dwIndex);
  543. [return: MarshalAs(UnmanagedType.Interface)]
  544. object EnumItems();
  545. }
  546. /// <summary>
  547. /// Shell Namespace helper 2
  548. /// </summary>
  549. [
  550. ComImport,
  551. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  552. Guid(IID.ShellItem2),
  553. ]
  554. interface IShellItem2 : IShellItem
  555. {
  556. #region IShellItem redeclarations
  557. [return: MarshalAs(UnmanagedType.Interface)]
  558. new object BindToHandler([In] IBindCtx pbc, [In] ref Guid bhid, [In] ref Guid riid);
  559. new IShellItem GetParent();
  560. [return: MarshalAs(UnmanagedType.LPWStr)]
  561. new string GetDisplayName(SIGDN sigdnName);
  562. new SFGAO GetAttributes(SFGAO sfgaoMask);
  563. new int Compare(IShellItem psi, SICHINT hint);
  564. #endregion
  565. [return: MarshalAs(UnmanagedType.Interface)]
  566. object GetPropertyStore(
  567. GPS flags,
  568. [In] ref Guid riid);
  569. [return: MarshalAs(UnmanagedType.Interface)]
  570. object GetPropertyStoreWithCreateObject(
  571. GPS flags,
  572. [MarshalAs(UnmanagedType.IUnknown)] object punkCreateObject, // factory for low-rights creation of type ICreateObject
  573. [In] ref Guid riid);
  574. [return: MarshalAs(UnmanagedType.Interface)]
  575. object GetPropertyStoreForKeys(
  576. IntPtr rgKeys,
  577. uint cKeys,
  578. GPS flags,
  579. [In] ref Guid riid);
  580. [return: MarshalAs(UnmanagedType.Interface)]
  581. object GetPropertyDescriptionList(
  582. IntPtr keyType,
  583. [In] ref Guid riid);
  584. // Ensures any cached information in this item is up to date, or returns __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) if the item does not exist.
  585. void Update(IBindCtx pbc);
  586. PROPVARIANT GetProperty(IntPtr key);
  587. Guid GetCLSID(IntPtr key);
  588. FILETIME GetFileTime(IntPtr key);
  589. int GetInt32(IntPtr key);
  590. [return: MarshalAs(UnmanagedType.LPWStr)]
  591. string GetString(IntPtr key);
  592. uint GetUInt32(IntPtr key);
  593. ulong GetUInt64(IntPtr key);
  594. [return: MarshalAs(UnmanagedType.Bool)]
  595. void GetBool(IntPtr key);
  596. }
  597. [
  598. ComImport,
  599. InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown),
  600. Guid(IID.ShellLink),
  601. ]
  602. internal interface IShellLinkW
  603. {
  604. void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, [In, Out] WIN32_FIND_DATAW pfd, SLGP fFlags);
  605. void GetIDList(out IntPtr ppidl);
  606. void SetIDList(IntPtr pidl);
  607. void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxName);
  608. void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
  609. void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);
  610. void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
  611. void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);
  612. void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
  613. short GetHotKey();
  614. void SetHotKey(short wHotKey);
  615. uint GetShowCmd();
  616. void SetShowCmd(uint iShowCmd);
  617. void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon);
  618. void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
  619. void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved);
  620. void Resolve(IntPtr hwnd, uint fFlags);
  621. void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
  622. }
  623. [
  624. ComImport,
  625. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  626. Guid(IID.TaskbarList),
  627. ]
  628. internal interface ITaskbarList
  629. {
  630. /// <summary>
  631. /// This function must be called first to validate use of other members.
  632. /// </summary>
  633. void HrInit();
  634. /// <summary>
  635. /// This function adds a tab for hwnd to the taskbar.
  636. /// </summary>
  637. /// <param name="hwnd">The HWND for which to add the tab.</param>
  638. void AddTab(IntPtr hwnd);
  639. /// <summary>
  640. /// This function deletes a tab for hwnd from the taskbar.
  641. /// </summary>
  642. /// <param name="hwnd">The HWND for which the tab is to be deleted.</param>
  643. void DeleteTab(IntPtr hwnd);
  644. /// <summary>
  645. /// This function activates the tab associated with hwnd on the taskbar.
  646. /// </summary>
  647. /// <param name="hwnd">The HWND for which the tab is to be actuvated.</param>
  648. void ActivateTab(IntPtr hwnd);
  649. /// <summary>
  650. /// This function marks hwnd in the taskbar as the active tab.
  651. /// </summary>
  652. /// <param name="hwnd">The HWND to activate.</param>
  653. void SetActiveAlt(IntPtr hwnd);
  654. }
  655. [
  656. ComImport,
  657. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  658. Guid(IID.TaskbarList2),
  659. ]
  660. internal interface ITaskbarList2 : ITaskbarList
  661. {
  662. #region ITaskbarList redeclaration
  663. new void HrInit();
  664. new void AddTab(IntPtr hwnd);
  665. new void DeleteTab(IntPtr hwnd);
  666. new void ActivateTab(IntPtr hwnd);
  667. new void SetActiveAlt(IntPtr hwnd);
  668. #endregion
  669. /// <summary>
  670. /// Marks a window as full-screen.
  671. /// </summary>
  672. /// <param name="hwnd">The handle of the window to be marked.</param>
  673. /// <param name="fFullscreen">A Boolean value marking the desired full-screen status of the window.</param>
  674. /// <remarks>
  675. /// Setting the value of fFullscreen to true, the Shell treats this window as a full-screen window, and the taskbar
  676. /// is moved to the bottom of the z-order when this window is active. Setting the value of fFullscreen to false
  677. /// removes the full-screen marking, but <i>does not</i> cause the Shell to treat the window as though it were
  678. /// definitely not full-screen. With a false fFullscreen value, the Shell depends on its automatic detection facility
  679. /// to specify how the window should be treated, possibly still flagging the window as full-screen.
  680. /// </remarks>
  681. void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
  682. }
  683. // Used to remove items from the automatic destination lists created when apps or the system call SHAddToRecentDocs to report usage of a document.
  684. [
  685. ComImport,
  686. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  687. Guid(IID.ApplicationDestinations)
  688. ]
  689. internal interface IApplicationDestinations
  690. {
  691. // Set the App User Model ID for the application removing destinations from its list. If an AppID is not provided
  692. // via this method, the system will use a heuristically determined ID. This method must be called before
  693. // RemoveDestination or RemoveAllDestinations.
  694. void SetAppID([In, MarshalAs(UnmanagedType.LPWStr)] string pszAppID);
  695. // Remove an IShellItem or an IShellLink from the automatic destination list
  696. void RemoveDestination([MarshalAs(UnmanagedType.IUnknown)] object punk);
  697. // Clear the frequent and recent destination lists for this application.
  698. void RemoveAllDestinations();
  699. }
  700. /// <summary>
  701. /// Allows an application to retrieve the most recent and frequent documents opened in that app, as reported via SHAddToRecentDocs
  702. /// </summary>
  703. [
  704. ComImport,
  705. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  706. Guid(IID.ApplicationDocumentLists)
  707. ]
  708. internal interface IApplicationDocumentLists
  709. {
  710. /// <summary>
  711. /// Set the App User Model ID for the application retrieving this list. If an AppID is not provided via this method,
  712. /// the system will use a heuristically determined ID. This method must be called before GetList.
  713. /// </summary>
  714. /// <param name="pszAppID">App Id.</param>
  715. void SetAppID([MarshalAs(UnmanagedType.LPWStr)] string pszAppID);
  716. /// <summary>
  717. /// Retrieve an IEnumObjects or IObjectArray for IShellItems and/or IShellLinks.
  718. /// Items may appear in both the frequent and recent lists.
  719. /// </summary>
  720. /// <param name="?"></param>
  721. /// <returns></returns>
  722. [return: MarshalAs(UnmanagedType.IUnknown)]
  723. object GetList([In] APPDOCLISTTYPE listtype, [In] uint cItemsDesired, [In] ref Guid riid);
  724. }
  725. // Custom Destination List
  726. [
  727. ComImport,
  728. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  729. Guid(IID.CustomDestinationList)
  730. ]
  731. internal interface ICustomDestinationList
  732. {
  733. void SetAppID([In, MarshalAs(UnmanagedType.LPWStr)] string pszAppID);
  734. // Retrieve IObjectArray of IShellItems or IShellLinks that represent removed destinations
  735. [return: MarshalAs(UnmanagedType.Interface)]
  736. object BeginList(out uint pcMaxSlots, [In] ref Guid riid);
  737. // PreserveSig because this will return custom errors when attempting to add unregistered ShellItems.
  738. // Can't readily detect that case without just trying to append it.
  739. [PreserveSig]
  740. HRESULT AppendCategory([MarshalAs(UnmanagedType.LPWStr)] string pszCategory, IObjectArray poa);
  741. void AppendKnownCategory(KDC category);
  742. [PreserveSig]
  743. HRESULT AddUserTasks(IObjectArray poa);
  744. void CommitList();
  745. // Retrieve IObjectCollection of IShellItems
  746. [return: MarshalAs(UnmanagedType.Interface)]
  747. object GetRemovedDestinations([In] ref Guid riid);
  748. void DeleteList([MarshalAs(UnmanagedType.LPWStr)] string pszAppID);
  749. void AbortList();
  750. }
  751. /// <summary>
  752. /// Provides access to the App User Model ID on objects supporting this value.
  753. /// </summary>
  754. [
  755. ComImport,
  756. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  757. Guid(IID.ObjectWithAppUserModelId)
  758. ]
  759. internal interface IObjectWithAppUserModelId
  760. {
  761. void SetAppID([MarshalAs(UnmanagedType.LPWStr)] string pszAppID);
  762. [return: MarshalAs(UnmanagedType.LPWStr)]
  763. string GetAppID();
  764. };
  765. /// <summary>
  766. /// Provides access to the ProgID associated with an object
  767. /// </summary>
  768. [
  769. ComImport,
  770. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  771. Guid(IID.ObjectWithProgId)
  772. ]
  773. internal interface IObjectWithProgId
  774. {
  775. void SetProgID([MarshalAs(UnmanagedType.LPWStr)] string pszProgID);
  776. [return: MarshalAs(UnmanagedType.LPWStr)]
  777. string GetProgID();
  778. };
  779. [
  780. ComImport,
  781. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  782. Guid(IID.TaskbarList3),
  783. ]
  784. internal interface ITaskbarList3 : ITaskbarList2
  785. {
  786. #region ITaskbarList2 redeclaration
  787. #region ITaskbarList redeclaration
  788. new void HrInit();
  789. new void AddTab(IntPtr hwnd);
  790. new void DeleteTab(IntPtr hwnd);
  791. new void ActivateTab(IntPtr hwnd);
  792. new void SetActiveAlt(IntPtr hwnd);
  793. #endregion
  794. new void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
  795. #endregion
  796. [PreserveSig]
  797. HRESULT SetProgressValue(IntPtr hwnd, ulong ullCompleted, ulong ullTotal);
  798. [PreserveSig]
  799. HRESULT SetProgressState(IntPtr hwnd, TBPF tbpFlags);
  800. [PreserveSig]
  801. HRESULT RegisterTab(IntPtr hwndTab, IntPtr hwndMDI);
  802. [PreserveSig]
  803. HRESULT UnregisterTab(IntPtr hwndTab);
  804. [PreserveSig]
  805. HRESULT SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore);
  806. [PreserveSig]
  807. HRESULT SetTabActive(IntPtr hwndTab, IntPtr hwndMDI, uint dwReserved);
  808. [PreserveSig]
  809. HRESULT ThumbBarAddButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] THUMBBUTTON[] pButtons);
  810. [PreserveSig]
  811. HRESULT ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] THUMBBUTTON[] pButtons);
  812. [PreserveSig]
  813. HRESULT ThumbBarSetImageList(IntPtr hwnd, [MarshalAs(UnmanagedType.IUnknown)] object himl);
  814. [PreserveSig]
  815. HRESULT SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, [MarshalAs(UnmanagedType.LPWStr)] string pszDescription);
  816. [PreserveSig]
  817. HRESULT SetThumbnailTooltip(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszTip);
  818. // Using RefRECT to making passing NULL possible. Removes clipping from the HWND.
  819. [PreserveSig]
  820. HRESULT SetThumbnailClip(IntPtr hwnd, RefRECT prcClip);
  821. }
  822. [
  823. ComImport,
  824. InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
  825. Guid(IID.TaskbarList3),
  826. ]
  827. internal interface ITaskbarList4 : ITaskbarList3
  828. {
  829. #region ITaskbarList3 redeclaration
  830. #region ITaskbarList2 redeclaration
  831. #region ITaskbarList redeclaration
  832. new void HrInit();
  833. new void AddTab(IntPtr hwnd);
  834. new void DeleteTab(IntPtr hwnd);
  835. new void ActivateTab(IntPtr hwnd);
  836. new void SetActiveAlt(IntPtr hwnd);
  837. #endregion
  838. new void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
  839. #endregion
  840. [PreserveSig] new HRESULT SetProgressValue(IntPtr hwnd, ulong ullCompleted, ulong ullTotal);
  841. [PreserveSig] new HRESULT SetProgressState(IntPtr hwnd, TBPF tbpFlags);
  842. [PreserveSig] new HRESULT RegisterTab(IntPtr hwndTab, IntPtr hwndMDI);
  843. [PreserveSig] new HRESULT UnregisterTab(IntPtr hwndTab);
  844. [PreserveSig] new HRESULT SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore);
  845. [PreserveSig] new HRESULT SetTabActive(IntPtr hwndTab, IntPtr hwndMDI, uint dwReserved);
  846. [PreserveSig] new HRESULT ThumbBarAddButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] THUMBBUTTON[] pButtons);
  847. [PreserveSig] new HRESULT ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] THUMBBUTTON[] pButtons);
  848. [PreserveSig] new HRESULT ThumbBarSetImageList(IntPtr hwnd, [MarshalAs(UnmanagedType.IUnknown)] object himl);
  849. [PreserveSig] new HRESULT SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, [MarshalAs(UnmanagedType.LPWStr)] string pszDescription);
  850. [PreserveSig] new HRESULT SetThumbnailTooltip(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszTip);
  851. // Using RefRECT to making passing NULL possible. Removes clipping from the HWND.
  852. [PreserveSig] new HRESULT SetThumbnailClip(IntPtr hwnd, RefRECT prcClip);
  853. #endregion
  854. void SetTabProperties(IntPtr hwndTab, STPF stpFlags);
  855. }
  856. #endregion
  857. }