PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Common/Definitions.cs

http://tsanie-shellextension.googlecode.com/
C# | 933 lines | 483 code | 159 blank | 291 comment | 0 complexity | 8ed5f5fd8b62fd11dadf8e8d8575939d MD5 | raw file
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. using System.Runtime.CompilerServices;
  5. using System.Runtime.InteropServices.ComTypes;
  6. using System.IO;
  7. namespace Tsanie.ShellExtension {
  8. // This namespace contains all the COM
  9. // interfaces required for the shell extesions
  10. #region - Types -
  11. [StructLayout(LayoutKind.Sequential, Pack = 4)]
  12. public struct SIZE {
  13. public int cx;
  14. public int cy;
  15. }
  16. #endregion
  17. #if IPropertyHandler
  18. #region - IPropertyHandler Structs/Enums -
  19. /// <summary>
  20. /// Specifies the FMTID/PID identifier that programmatically identifies a property.
  21. /// </summary>
  22. /// <remarks> MSDN Reference: http://msdn.microsoft.com/en-us/library/bb773381.aspx </remarks>
  23. [StructLayout(LayoutKind.Sequential)]
  24. public struct PROPERTYKEY {
  25. /// <summary>
  26. /// A unique GUID for the property.
  27. /// </summary>
  28. public Guid fmtid;
  29. /// <summary>
  30. /// A property identifier (PID).
  31. /// </summary>
  32. public int pid;
  33. }
  34. /// <summary>
  35. /// Used by the <see cref="IPropertyStore.GetValue"/> and <see cref="IPropertyStore.SetValue"/> methods
  36. /// of <see cref="IPropertyStore"/> as the primary way to program item properties.
  37. /// </summary>
  38. /// <remarks> MSDN Reference: http://msdn.microsoft.com/en-us/library/aa380072.aspx </remarks>
  39. [StructLayout(LayoutKind.Sequential)]
  40. public struct PROPVARIANT {
  41. /// <summary>
  42. /// Value type tag.
  43. /// </summary>
  44. public short vt;
  45. /// <summary>
  46. /// Reserved for future use.
  47. /// </summary>
  48. public short wReserved1;
  49. /// <summary>
  50. /// Reserved for future use.
  51. /// </summary>
  52. public short wReserved2;
  53. /// <summary>
  54. /// Reserved for future use.
  55. /// </summary>
  56. public short wReserved3;
  57. /// <summary>
  58. /// Represents the variant data section.
  59. /// </summary>
  60. public VariantData Data;
  61. }
  62. /// <summary>
  63. /// Represents the variant data section of the PROPVARIANT structure.
  64. /// </summary>
  65. /// <remarks>
  66. /// This only provides variants for use within the context of MMDevice properties.
  67. /// </remarks>
  68. [StructLayout(LayoutKind.Explicit)]
  69. public struct VariantData {
  70. /// <summary>
  71. /// Represents the data as a boolean value.
  72. /// </summary>
  73. [FieldOffset(0)]
  74. public bool AsBoolean;
  75. /// <summary>
  76. /// Represents the data as a unsigned 32-bit integer.
  77. /// </summary>
  78. [FieldOffset(0)]
  79. public UInt32 AsUInt32;
  80. /// <summary>
  81. /// Represents the data as a unicode string pointer.
  82. /// </summary>
  83. [FieldOffset(0)]
  84. public IntPtr AsStringPtr;
  85. /// <summary>
  86. /// Represents the data as a pointer to a WAVEFORMATEX structure.
  87. /// </summary>
  88. [FieldOffset(4)]
  89. public IntPtr AsFormatPtr;
  90. }
  91. #endregion
  92. #region - IPropertyHandler -
  93. /// <summary>
  94. /// Exposes methods for enumerating, getting, and setting property values.
  95. /// </summary>
  96. /// <remarks>
  97. /// MSDN Reference: http://msdn.microsoft.com/en-us/library/bb761474.aspx
  98. /// Note: This item is defined in the Windows Property System API. (propsys.h)
  99. /// </remarks>
  100. [Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99")]
  101. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  102. public interface IPropertyStore {
  103. /// <summary>
  104. /// Gets the number of properties attached to the file.
  105. /// </summary>
  106. /// <param name="propertyCount">Receives the property count.</param>
  107. /// <returns>An HRESULT code indicating whether the operation passed of failed.</returns>
  108. [PreserveSig]
  109. int GetCount([Out] [MarshalAs(UnmanagedType.U4)] out UInt32 propertyCount);
  110. /// <summary>
  111. /// Gets a property key from an item's array of properties.
  112. /// </summary>
  113. /// <param name="propertyIndex">The index of the property key in the array of <see cref="PROPERTYKEY"/> structures.</param>
  114. /// <param name="propertyKey">The unique identifier for a property.</param>
  115. /// <returns>An HRESULT code indicating whether the operation passed of failed.</returns>
  116. [PreserveSig]
  117. int GetAt([In] [MarshalAs(UnmanagedType.U4)] UInt32 propertyIndex, [Out] out PROPERTYKEY propertyKey);
  118. /// <summary>
  119. /// Gets data for a specific property.
  120. /// </summary>
  121. /// <param name="propertyKey">A <see cref="PROPERTYKEY"/> structure containing a unique identifier for the property in question.</param>
  122. /// <param name="value">Receives a <see cref="PROPVARIANT"/> structure that contains the property data.</param>
  123. /// <returns>An HRESULT code indicating whether the operation passed of failed.</returns>
  124. [PreserveSig]
  125. int GetValue([In] ref PROPERTYKEY propertyKey, [Out] out PROPVARIANT value);
  126. /// <summary>
  127. /// Sets a new property value, or replaces or removes an existing value.
  128. /// </summary>
  129. /// <param name="propertyKey">A <see cref="PROPERTYKEY"/> structure containing a unique identifier for the property in question.</param>
  130. /// <param name="value">A <see cref="PROPVARIANT"/> structure that contains the new property data.</param>
  131. /// <returns>An HRESULT code indicating whether the operation passed of failed.</returns>
  132. [PreserveSig]
  133. int SetValue([In] ref PROPERTYKEY propertyKey, [In] ref PROPVARIANT value);
  134. /// <summary>
  135. /// Saves a property change.
  136. /// </summary>
  137. /// <returns>An HRESULT code indicating whether the operation passed of failed.</returns>
  138. [PreserveSig]
  139. int Commit();
  140. }
  141. #endregion
  142. #endif
  143. #if IShellExtInit
  144. #region - IShellExtInit -
  145. /// <summary>
  146. /// The IShellExtInit interface is used by the shell to initialize shell extension objects.
  147. /// </summary>
  148. [ComImport]
  149. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  150. [Guid("000214E8-0000-0000-c000-000000000046")]
  151. public interface IShellExtInit {
  152. /// <summary>
  153. /// The Initialize method is called when File Explorer is initializing a context menu extension,
  154. /// a property sheet extension, or a non-default drag-and-drop extension.
  155. /// </summary>
  156. /// <param name="pidlFolder">The pidl folder.</param>
  157. /// <param name="dataObject">The data object.</param>
  158. /// <param name="hkeyProgId">The hkey prog id.</param>
  159. void Initialize(IntPtr pidlFolder, [In] IDataObject dataObject, uint hkeyProgId);
  160. }
  161. #endregion
  162. #endif
  163. #if IDataObject
  164. #region - IDataObject Enums/Structs -
  165. public enum DATADIR {
  166. DATADIR_GET = 1,
  167. DATADIR_SET = 2
  168. }
  169. public enum TYMED {
  170. TYMED_HGLOBAL = 1,
  171. TYMED_FILE = 2,
  172. TYMED_ISTREAM = 4,
  173. TYMED_ISTORAGE = 8,
  174. TYMED_GDI = 16,
  175. TYMED_MFPICT = 32,
  176. TYMED_ENHMF = 64,
  177. TYMED_NULL = 0
  178. }
  179. public enum DVASPECT {
  180. DVASPECT_CONTENT = 1,
  181. DVASPECT_THUMBNAIL = 2,
  182. DVASPECT_ICON = 4,
  183. DVASPECT_DOCPRINT = 8
  184. }
  185. public struct FORMATETC {
  186. public short cfFormat;
  187. public int ptd;
  188. public DVASPECT dwAspect;
  189. public int lindex;
  190. public TYMED tymed;
  191. }
  192. public struct STGMEDIUM {
  193. public TYMED tymed;
  194. public int data;
  195. [MarshalAs(UnmanagedType.IUnknown)]
  196. public Object pUnkForRelease;
  197. }
  198. #endregion
  199. #region - IDataObject -
  200. [ComImport]
  201. [Guid("0000010e-0000-0000-C000-000000000046")]
  202. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  203. public interface IDataObject {
  204. void GetData(
  205. ref FORMATETC pformatetcIn,
  206. ref STGMEDIUM pmedium);
  207. void GetDataHere(
  208. ref FORMATETC pformatetc,
  209. ref STGMEDIUM pmedium);
  210. [PreserveSig]
  211. int QueryGetData(ref FORMATETC pformatetc);
  212. void GetCanonicalFormatEtc(
  213. ref FORMATETC pformatectIn,
  214. ref FORMATETC pformatetcOut);
  215. void SetData(
  216. ref FORMATETC pformatetc,
  217. ref STGMEDIUM pmedium,
  218. [MarshalAs(UnmanagedType.Bool)] Boolean fRelease);
  219. [return: MarshalAs(UnmanagedType.Interface)]
  220. Object EnumFormatEtc(DATADIR dwDirection);
  221. int DAdvise(
  222. ref FORMATETC pformatetc,
  223. int advf,
  224. [MarshalAs(UnmanagedType.Interface)] Object pAdvSink);
  225. void DUnadvise(int dwConnection);
  226. [return: MarshalAs(UnmanagedType.Interface)]
  227. Object EnumDAdvise();
  228. }
  229. #endregion
  230. #endif
  231. #if IExtractIcon
  232. #region - IExtractIcon Enums -
  233. [Flags]
  234. public enum IconHandlerFlags {
  235. Open = 0x1,
  236. ForShell = 0x2,
  237. Async = 0x20,
  238. DefaultIcon = 0x40,
  239. ForShortcut = 0x80
  240. }
  241. [Flags]
  242. public enum IconHandlerReturnFlags {
  243. SimulateDoc = 0x1,
  244. PerInstance = 0x2,
  245. PerClass = 0x4,
  246. NotFilename = 0x8,
  247. DontCache = 0x10
  248. }
  249. #endregion
  250. #region - IExtractIcon -
  251. [Guid("000214EB-0000-0000-C000-000000000046")]
  252. [ComImport]
  253. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  254. public interface IExtractIconA {
  255. IconHandlerReturnFlags GetIconLocation(
  256. [In] IconHandlerFlags uFlags,
  257. [In, Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder szIconFile,
  258. [In] int cchMax,
  259. [In, Out] ref int piIndex);
  260. void Extract(
  261. [In, MarshalAs(UnmanagedType.LPStr)] String pszFile,
  262. [In] int nIconIndex,
  263. [In, Out] ref IntPtr phiconLarge,
  264. [In, Out] ref IntPtr phiconSmall,
  265. [In] int nIconSize);
  266. }
  267. [Guid("000214FA-0000-0000-C000-000000000046")]
  268. [ComImport]
  269. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  270. public interface IExtractIconW {
  271. IconHandlerReturnFlags GetIconLocation(
  272. [In] IconHandlerFlags uFlags,
  273. [In, Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder szIconFile,
  274. [In] int cchMax,
  275. [In, Out] ref int piIndex);
  276. void Extract(
  277. [In, MarshalAs(UnmanagedType.LPWStr)] String pszFile,
  278. [In] int nIconIndex,
  279. [In, Out] ref IntPtr phiconLarge,
  280. [In, Out] ref IntPtr phiconSmall,
  281. [In] int nIconSize);
  282. }
  283. #endregion
  284. #endif
  285. #if IExtractImage
  286. #region - IExtractImage Enums -
  287. [Flags]
  288. public enum ThumbnailFlags {
  289. Async = 0x1, // ask the extractor if it supports ASYNC extract (free threaded)
  290. Cache = 0x2, // returned from the extractor if it does NOT cache the thumbnail
  291. Aspect = 0x4, // passed to the extractor to beg it to render to the aspect ratio of the supplied rect
  292. OffLine = 0x8, // if the extractor shouldn//t hit the net to get any content neede for the rendering
  293. Gleam = 0x10, // does the image have a gleam ? this will be returned if it does
  294. Screen = 0x20, // render as if for the screen (this is exlusive with IEIFLAG_ASPECT )
  295. OrigSize = 0x40 // render to the approx size passed, but crop if neccessary
  296. }
  297. #endregion
  298. #region - IExtractImage -
  299. [Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1")]
  300. [ComImport]
  301. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  302. public interface IExtractImage {
  303. void GetLocation(
  304. [In, Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszPathBuffer,
  305. [In] int cch,
  306. [Out] out int pdwPriority,
  307. [In] ref SIZE prgSize,
  308. [In] int dwRecClrDepth,
  309. [In] ref ThumbnailFlags pdwFlags);
  310. IntPtr Extract();
  311. }
  312. [Guid("953BB1EE-93B4-11d1-98A3-00C04FB687DA")]
  313. [ComImport]
  314. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  315. public interface IExtractImage2 {
  316. void GetLocation(
  317. [In, Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszPathBuffer,
  318. [In] int cch,
  319. [Out] out int pdwPriority,
  320. [In] ref SIZE prgSize,
  321. [In] int dwRecClrDepth,
  322. [In] ref ThumbnailFlags pdwFlags);
  323. IntPtr Extract();
  324. long GetDateStamp();
  325. }
  326. #endregion
  327. #endif
  328. #if IContextMenu
  329. #region - IContextMenu Enums/Structs -
  330. /// <summary>
  331. /// Flag options for the IContextMenu interface.
  332. /// </summary>
  333. [Flags]
  334. public enum QueryContextMenuOptions {
  335. /// <summary>
  336. /// Indicates normal operation. A shortcut menu extension, namespace extension,
  337. /// or drag-and-drop handler can add all menu items. (CMF_NORMAL).
  338. /// </summary>
  339. Normal = 0,
  340. /// <summary>
  341. /// The user is activating the default action, typically by double-clicking.
  342. /// This flag provides a hint for the shortcut menu extension to add nothing if it
  343. /// does not modify the default item in the menu. A shortcut menu extension or
  344. /// drag-and-drop handler should not add any menu items if this value is specified.
  345. /// A namespace extension should at most add only the default item. (CMF_DEFAULTONLY).
  346. /// </summary>
  347. DefaultOnly = 1,
  348. /// <summary>
  349. /// The shortcut menu is that of a shortcut file (normally, a .lnk file).
  350. /// Shortcut menu handlers should ignore this value. (CMF_VERBSONLY).
  351. /// </summary>
  352. VerbsOnly = 2,
  353. /// <summary>
  354. /// The Windows Explorer tree window is present. (CMF_EXPLORE).
  355. /// </summary>
  356. Explore = 4,
  357. /// <summary>
  358. /// This flag is set for items displayed in the Send To menu.
  359. /// Shortcut menu handlers should ignore this value. (CMF_NOVERBS).
  360. /// </summary>
  361. NoVerbs = 8,
  362. /// <summary>
  363. /// The calling application supports renaming of items.
  364. /// A shortcut menu or drag-and-drop handler should ignore this flag.
  365. /// A namespace extension should add a Rename item to the menu if applicable. (CMF_CANRENAME).
  366. /// </summary>
  367. CanRename = 0x10,
  368. /// <summary>
  369. /// No item in the menu has been set as the default.
  370. /// A drag-and-drop handler should ignore this flag.
  371. /// A namespace extension should not set any of the menu items as the default. (CMF_NODEFAULT)
  372. /// </summary>
  373. NoDefault = 0x20,
  374. CMF_INCLUDESTATIC = 0x40,
  375. CMF_RESERVED = unchecked((int)0xFFFF0000)
  376. }
  377. [Flags]
  378. public enum InvokeCommandMask {
  379. CMIC_MASK_HOTKEY = 0x20,
  380. CMIC_MASK_ICON = 0x10,
  381. CMIC_MASK_FLAG_NO_UI = 0x400,
  382. CMIC_MASK_UNICODE = 0x4000,
  383. CMIC_MASK_NO_CONSOLE = 0x8000,
  384. CMIC_MASK_ASYNCOK = 0x100000,
  385. CMIC_MASK_PTINVOKE = 0x20000000,
  386. CMIC_MASK_SHIFT_DOWN = 0x10000000,
  387. CMIC_MASK_CONTROL_DOWN = 0x20000000
  388. }
  389. /// <summary>
  390. /// Flags specifying the information to return.
  391. /// </summary>
  392. public enum GetCommandStringOptions {
  393. /// <summary>
  394. /// Sets pszName to an ANSI string containing the help text for the command (GCS_VERBA).
  395. /// </summary>
  396. CanonicalVerbAnsi = 0x0,
  397. /// <summary>
  398. /// Sets pszName to a Unicode string containing the language-independent command name for the menu item (GCS_VERBW).
  399. /// </summary>
  400. CanonicalVerb = 0x4,
  401. /// <summary>
  402. /// Sets pszName to a Unicode string containing the help text for the command (GCS_HELPTEXTW).
  403. /// </summary>
  404. HelpText = 0x5,
  405. /// <summary>
  406. /// Returns S_OK if the menu item exists, or S_FALSE otherwise.
  407. /// </summary>
  408. Validate = 0x6
  409. }
  410. /// <summary>
  411. /// Contains information needed by IContextMenu::InvokeCommand to
  412. /// invoke a shortcut menu command (CMINVOKECOMMANDINFO).
  413. /// </summary>
  414. [StructLayout(LayoutKind.Sequential)]
  415. public struct InvokeCommandInfo {
  416. /// <summary>
  417. /// The size of this structure, in bytes (cbSize).
  418. /// </summary>
  419. public int cbSize; // sizeof(CMINVOKECOMMANDINFO)
  420. /// <summary>
  421. /// Any combination of CMIC_MASK_*.
  422. /// </summary>
  423. public InvokeCommandMask fMask;
  424. /// <summary>
  425. /// Might be NULL, indicating no owner window (hwnd).
  426. /// </summary>
  427. public IntPtr parentWindow;
  428. /// <summary>
  429. /// either a string or MAKEINTRESOURCE(idOffset).
  430. /// </summary>
  431. public IntPtr lpVerb;
  432. /// <summary>
  433. /// might be NULL (indicating no parameter).
  434. /// </summary>
  435. public string lpParameters;
  436. /// <summary>
  437. /// Might be NULL (indicating no specific directory).
  438. /// </summary>
  439. public string lpDirectory;
  440. /// <summary>
  441. /// one of SW_ values for ShowWindow() API.
  442. /// </summary>
  443. public int nShow;
  444. /// <summary>
  445. /// An optional keyboard shortcut to assign to any application activated by the command.
  446. /// If the fMask parameter does not specify CMIC_MASK_HOTKEY, this member is ignored.
  447. /// </summary>
  448. public int dwHotKey;
  449. /// <summary>
  450. /// An icon to use for any application activated by the command.
  451. /// If the fMask member does not specify CMIC_MASK_ICON, this member is ignored.
  452. /// </summary>
  453. public IntPtr hIcon;
  454. }
  455. #endregion
  456. #region - IContextMenu -
  457. /// <summary>
  458. /// Exposes methods that either create or merge a shortcut menu associated with a Shell object.
  459. /// Allows client objects to handle messages associated with owner-drawn menu items and extends
  460. /// IContextMenu2 by accepting a return value from that message handling.
  461. /// </summary>
  462. [ComImport]
  463. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  464. [Guid("000214E4-0000-0000-c000-000000000046")]
  465. public interface IContextMenu {
  466. /// <summary>
  467. /// Queries the context menu (from IContextMenu).
  468. /// </summary>
  469. /// <param name="menuHandle">A handle to the shortcut menu. The handler should specify this handle when adding menu items (hmenu).</param>
  470. /// <param name="position">The zero-based position at which to insert the first new menu item (indexMenu).</param>
  471. /// <param name="firstCommandId">The minimum value that the handler can specify for a menu item identifier (idCmdFirst).</param>
  472. /// <param name="lastCommandId">The maximum value that the handler can specify for a menu item identifier (idCmdLast).</param>
  473. /// <param name="flags">Optional flags that specify how the shortcut menu can be changed (uFlags).</param>
  474. /// <returns>
  475. /// If successful, returns an HRESULT value that has its severity value set to SEVERITY_SUCCESS and
  476. /// its code value set to the offset of the largest command identifier that was assigned.
  477. /// </returns>
  478. [PreserveSig]
  479. [return: MarshalAs(UnmanagedType.Error)]
  480. int QueryContextMenu(IntPtr menuHandle, uint position, uint firstCommandId, uint lastCommandId, QueryContextMenuOptions flags);
  481. /// <summary>
  482. /// Carries out the command associated with a shortcut menu item (from IContextMenu).
  483. /// </summary>
  484. /// <param name="invokeCommandInfo">The invoke command info.</param>
  485. void InvokeCommand([In] ref InvokeCommandInfo invokeCommandInfo);
  486. /// <summary>
  487. /// Gets information about a shortcut menu command, including the help string and the
  488. /// language-independent, or canonical, name for the command (from IContextMenu).
  489. /// </summary>
  490. /// <param name="idCommand">Menu command identifier offset.</param>
  491. /// <param name="flags">Flags specifying the information to return.</param>
  492. /// <param name="reserved">Reserved. Applications must specify NULL when calling this method and handlers must ignore this parameter when called.</param>
  493. /// <param name="name">The reference of the buffer to receive the null-terminated string being retrieved.</param>
  494. /// <param name="cch">Size of the buffer, in characters, to receive the null-terminated string.</param>
  495. /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
  496. [PreserveSig]
  497. [return: MarshalAs(UnmanagedType.Error)]
  498. int GetCommandString(IntPtr idCommand, GetCommandStringOptions flags, int reserved, IntPtr name, int cch);
  499. }
  500. /// <summary>
  501. /// Exposes methods that either create or merge a shortcut menu associated with a Shell object.
  502. /// Allows client objects to handle messages associated with owner-drawn menu items and extends
  503. /// IContextMenu2 by accepting a return value from that message handling.
  504. /// </summary>
  505. [ComImport]
  506. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  507. [Guid("000214F4-0000-0000-c000-000000000046")]
  508. public interface IContextMenu2 {
  509. [PreserveSig]
  510. [return: MarshalAs(UnmanagedType.Error)]
  511. int QueryContextMenu(IntPtr menuHandle, uint position, uint firstCommandId, uint lastCommandId, QueryContextMenuOptions flags);
  512. void InvokeCommand([In] ref InvokeCommandInfo invokeCommandInfo);
  513. [PreserveSig]
  514. [return: MarshalAs(UnmanagedType.Error)]
  515. int GetCommandString(IntPtr idCommand, GetCommandStringOptions flags, int reserved, IntPtr name, int cch);
  516. /// <summary>
  517. /// Enables client objects of the IContextMenu interface to handle messages
  518. /// associated with owner-drawn menu items (from IContextMenu2).
  519. /// </summary>
  520. /// <param name="message">The message to be processed.</param>
  521. /// <param name="wParam">Additional message information. The value of the wParam parameter depends on the value of the message parameter.</param>
  522. /// <param name="lParam">Additional message information. The value of the lParam parameter depends on the value of the message parameter.</param>
  523. void HandleMenuMsg(uint message, IntPtr wParam, IntPtr lParam);
  524. }
  525. /// <summary>
  526. /// Exposes methods that either create or merge a shortcut menu associated with a Shell object.
  527. /// Allows client objects to handle messages associated with owner-drawn menu items and extends
  528. /// IContextMenu2 by accepting a return value from that message handling.
  529. /// </summary>
  530. [ComImport]
  531. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  532. [Guid("bcfce0a0-ec17-11d0-8d10-00a0c90f2719")]
  533. public interface IContextMenu3 {
  534. [PreserveSig]
  535. [return: MarshalAs(UnmanagedType.Error)]
  536. int QueryContextMenu(IntPtr menuHandle, uint position, uint firstCommandId, uint lastCommandId, QueryContextMenuOptions flags);
  537. void InvokeCommand([In] ref InvokeCommandInfo invokeCommandInfo);
  538. [PreserveSig]
  539. [return: MarshalAs(UnmanagedType.Error)]
  540. int GetCommandString(IntPtr idCommand, GetCommandStringOptions flags, int reserved, IntPtr name, int cch);
  541. void HandleMenuMsg(uint message, IntPtr wParam, IntPtr lParam);
  542. /// <summary>
  543. /// Allows client objects of the IContextMenu3 interface to handle messages associated with owner-drawn menu items.
  544. /// </summary>
  545. /// <param name="message">The message to be processed.</param>
  546. /// <param name="wParam">Additional message information. The value of the wParam parameter depends on the value of the message parameter.</param>
  547. /// <param name="lParam">Additional message information. The value of the lParam parameter depends on the value of the message parameter.</param>
  548. /// <param name="result">A pointer to the result.</param>
  549. void HandleMenuMsg2(uint message, IntPtr wParam, IntPtr lParam, IntPtr result);
  550. }
  551. #endregion
  552. #endif
  553. #if IQueryInfo
  554. #region - IQueryInfo Enums -
  555. /// <summary>
  556. /// Flags that define the handling of the item when retrieving the info tip text.
  557. /// </summary>
  558. [Flags]
  559. public enum InfoTipOptions {
  560. /// <summary>
  561. /// No special handling. QITIPF_DEFAULT (0).
  562. /// </summary>
  563. Default = 0,
  564. /// <summary>
  565. /// Provide the name of the item in ppwszTip rather than the info tip text. QITIPF_USENAME (1).
  566. /// </summary>
  567. UseName = 1,
  568. /// <summary>
  569. /// If the item is a shortcut, retrieve the info tip text of the shortcut rather than its target. QITIPF_LINKNOTARGET (2).
  570. /// </summary>
  571. LinkNoTarget = 2,
  572. /// <summary>
  573. /// If the item is a shortcut, retrieve the info tip text of the shortcut's target. QITIPF_LINKUSETARGET (4).
  574. /// </summary>
  575. LinkUseTarget = 4,
  576. /// <summary>
  577. /// Search the entire namespace for the information. This may result in a delayed response time. QITIPF_USESLOWTIP (8).
  578. /// </summary>
  579. UseSlowTip = 8,
  580. /// <summary>
  581. /// Put the info tip on a single line (only Windows Vista and later). QITIPF_SINGLELINE (10).
  582. /// </summary>
  583. SingleLine = 0x10
  584. }
  585. [Flags]
  586. public enum InfoFlags {
  587. None = 0,
  588. Cached = 0x1,
  589. DontExpandFolder = 0x2
  590. }
  591. #endregion
  592. #region - IQueryInfo -
  593. /// <summary>
  594. /// Exposes methods that the Shell uses to retrieve flags and info tip information for an item that resides
  595. /// in an IShellFolder implementation. Info tips are usually displayed inside a ToolTip control.
  596. /// </summary>
  597. [ComImport]
  598. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  599. [Guid("00021500-0000-0000-C000-000000000046")]
  600. public interface IQueryInfo {
  601. /// <summary>
  602. /// Gets the info tip text for an item.
  603. /// </summary>
  604. /// <param name="options">Flags directing the handling of the item from which you're retrieving the info tip text. This value is commonly zero (QITIPF_DEFAULT).</param>
  605. /// <param name="text">The info tip text.</param>
  606. void GetInfoTip([In] InfoTipOptions options, [Out, MarshalAs(UnmanagedType.LPWStr)] out string text);
  607. /// <summary>
  608. /// Gets the information flags for an item.
  609. /// </summary>
  610. /// <param name="options">The options.</param>
  611. void GetInfoFlags([Out] out InfoFlags flag);
  612. }
  613. #endregion
  614. #endif
  615. #if IShellPropSheetExt
  616. #region - IShellPropSheetExt Delegates -
  617. /// <summary>
  618. /// Callback, passed to 'AddPages'.
  619. /// </summary>
  620. public delegate bool AddPageDelegate(IntPtr hPage, IntPtr lParam);
  621. #endregion
  622. #region - IShellPropSheetExt -
  623. /// <summary>
  624. /// Exposes methods that allow a property sheet handler to add or replace pages in the property sheet displayed for a file object.
  625. /// </summary>
  626. [ComImport]
  627. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  628. [Guid("000214E9-0000-0000-C000-000000000046")]
  629. public interface IShellPropSheetExt {
  630. /// <summary>
  631. /// Adds one or more pages to a property sheet that the Shell displays for a file object.
  632. /// The Shell calls this method for each property sheet handler registered to the file type.
  633. /// </summary>
  634. /// <param name="addPageFunction">
  635. /// A pointer to a function that the property sheet handler calls to add a page to the property sheet.
  636. /// The function takes a property sheet handle returned by the CreatePropertySheetPage function and
  637. /// the lParam parameter passed to this method.</param>
  638. /// <param name="lParam">Handler-specific data to pass to the function pointed to by pfnAddPage.</param>
  639. /// <returns>If successful, returns a one-based index to specify the page that should be initially displayed.</returns>
  640. [PreserveSig]
  641. [return: MarshalAs(UnmanagedType.Error)]
  642. int AddPages([MarshalAs(UnmanagedType.FunctionPtr)] AddPageDelegate addPageFunction, IntPtr lParam);
  643. /// <summary>
  644. /// Replaces a page in a property sheet for a Control Panel object.
  645. /// </summary>
  646. /// <param name="pageId">Windows XP and earlier: a type EXPPS identifier of the page to replace.</param>
  647. /// <param name="replaceWithFunction">
  648. /// A pointer to a function that the property sheet handler calls to replace a page to the property sheet.
  649. /// The function takes a property sheet handle returned by the CreatePropertySheetPage function and
  650. /// the lParam parameter passed to the ReplacePage method.</param>
  651. /// <param name="lParam">The parameter to pass to the function specified by the pfnReplacePage parameter.</param>
  652. void ReplacePage(uint pageId, IntPtr replaceWithFunction, IntPtr lParam);
  653. }
  654. #endregion
  655. #endif
  656. #if IDropTarget
  657. #region - IDropTarget Enums -
  658. [Flags]
  659. public enum DragDropEffects {
  660. None = 0,
  661. Copy = 1,
  662. Move = 2,
  663. Link = 4,
  664. Scroll = unchecked((int)0x80000000),
  665. All = unchecked((int)0x80000003)
  666. }
  667. [Flags]
  668. public enum KeyStates {
  669. LeftButton = 1,
  670. RightButton = 2,
  671. Shift = 4,
  672. Control = 8,
  673. MedButton = 0x10,
  674. Alt = 0x20
  675. }
  676. #endregion
  677. #region - IDropTarget -
  678. [ComImport]
  679. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  680. [Guid("00000122-0000-0000-C000-000000000046")]
  681. public interface IDropTarget {
  682. void DragEnter(
  683. IDataObject pDataObj,
  684. KeyStates grfKeyState,
  685. int ptX,
  686. int ptY,
  687. ref DragDropEffects pdwEffect);
  688. void DragOver(
  689. KeyStates grfKeyState,
  690. int ptX,
  691. int ptY,
  692. ref DragDropEffects pdwEffect);
  693. void DragLeave();
  694. void Drop(
  695. IDataObject pDataObj,
  696. KeyStates grfKeyState,
  697. int ptX,
  698. int ptY,
  699. ref DragDropEffects pdwEffect);
  700. }
  701. #endregion
  702. #endif
  703. #if IShellExecuteHook
  704. #region - IShellExecuteHook Enums/Structs -
  705. [Flags]
  706. public enum ShellExecuteHookFlags {
  707. ClassName = 0x1,
  708. ClassKey = 0x3,
  709. IdList = 0x4,
  710. InvokeIdList = 0xC,
  711. Icon = 0x10,
  712. HotKey = 0x20,
  713. NoCloseProcess = 0x40,
  714. ConnectNetDrv = 0x80,
  715. DdeWait = 0x100,
  716. DoEnvSubst = 0x200,
  717. NoUI = 0x400,
  718. Unicode = 0x4000,
  719. NoConsole = 0x8000,
  720. AsynOK = 0x100000,
  721. hMonitor = 0x200000,
  722. }
  723. public struct SHELLEXECUTEINFO_ {
  724. public int cbSize;
  725. public ShellExecuteHookFlags fMask;
  726. public IntPtr hWnd;
  727. public IntPtr lpVerb;
  728. public IntPtr lpFile;
  729. public IntPtr lpParameters;
  730. public IntPtr lpDirectory;
  731. public int nShow;
  732. public IntPtr hInstApp;
  733. public IntPtr lpIDList;
  734. public IntPtr lpClass;
  735. public IntPtr hKeyClass;
  736. public int dwHotKey;
  737. public IntPtr hIcon_hMonitor;
  738. public IntPtr hProcess;
  739. }
  740. public struct ShellExecuteInfo {
  741. public ShellExecuteHookFlags Mask;
  742. public IntPtr hWnd;
  743. public String Verb;
  744. public String File;
  745. public String Parameters;
  746. public String Directory;
  747. public int ShowMode;
  748. public IntPtr hInstApp;
  749. public IntPtr IDList;
  750. public String Class;
  751. public IntPtr hKeyClass;
  752. public int HotKey;
  753. public IntPtr hIcon;
  754. public IntPtr hProcess;
  755. }
  756. #endregion
  757. #region - IShellExecuteHook -
  758. [Guid("000214F5-0000-0000-C000-000000000046")]
  759. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  760. [ComImport]
  761. public interface IShellExecuteHookA {
  762. [PreserveSig]
  763. int Execute(ref SHELLEXECUTEINFO_ pei);
  764. }
  765. [Guid("000214FB-0000-0000-C000-000000000046")]
  766. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  767. [ComImport]
  768. public interface IShellExecuteHookW {
  769. [PreserveSig]
  770. int Execute(ref SHELLEXECUTEINFO_ pei);
  771. }
  772. #endregion
  773. #endif
  774. }