/// <summary> /// This method will use the GetUIObjectOf method of IShellFolder to obtain the IDropTarget of a /// ShellItem. /// </summary> /// <param name="item">The item for which to obtain the IDropTarget</param> /// <param name="dropTargetPtr">A pointer to the returned IDropTarget</param> /// <returns>the IDropTarget from the ShellItem</returns> public static bool GetIDropTarget(ShellItem item, out IntPtr dropTargetPtr, out ShellDll.IDropTarget dropTarget) { ShellItem parent = item.ParentItem != null ? item.ParentItem : item; if (parent.ShellFolder.GetUIObjectOf( IntPtr.Zero, 1, new IntPtr[] { item.PIDLRel.Ptr }, ref ShellAPI.IID_IDropTarget, IntPtr.Zero, out dropTargetPtr) == ShellAPI.S_OK) { dropTarget = (ShellDll.IDropTarget)Marshal.GetTypedObjectForIUnknown(dropTargetPtr, typeof(ShellDll.IDropTarget)); return true; } else { dropTarget = null; dropTargetPtr = IntPtr.Zero; return false; } }
/// <summary> /// Convert CSIDL to PIDL /// </summary> internal static PIDL CSIDLtoPIDL(ShellDll.ShellAPI.CSIDL csidl) { IntPtr ptrAddr; PIDL pidl; if (csidl == ShellAPI.CSIDL.MYDOCUMENTS) return PathtoPIDL(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); { int RetVal = ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, csidl, out ptrAddr); if (ptrAddr != IntPtr.Zero) { pidl = new PIDL(ptrAddr, false); return pidl; } else throw new ArgumentException("Invalid csidl " + RetVal); } //return null; }
public static extern int RegisterDragDrop( IntPtr hWnd, ShellDll.IDropTarget IdropTgt);
/// <summary> /// This method will use the GetUIObjectOf method of IShellFolder to obtain the IDropTarget of a /// ShellItem. /// </summary> /// <param name="item">The item for which to obtain the IDropTarget</param> /// <param name="dropTargetPtr">A pointer to the returned IDropTarget</param> /// <returns>the IDropTarget from the ShellItem</returns> public static bool GetIDropTarget(IntPtr[] pidls, IShellFolder parent, out IntPtr dropTargetPtr, out ShellDll.IDropTarget dropTarget) { if (parent.GetUIObjectOf( IntPtr.Zero, 1, pidls, ref ShellAPI.IID_IDropTarget, IntPtr.Zero, out dropTargetPtr) == ShellAPI.S_OK) { dropTarget = (ShellDll.IDropTarget)Marshal.GetTypedObjectForIUnknown(dropTargetPtr, typeof(ShellDll.IDropTarget)); return true; } else { dropTarget = null; dropTargetPtr = IntPtr.Zero; return false; } }