public static string GetDisplayName(IntPtr pIDL, bool fDisplayName) { IShellFolder ppv = null; Guid riid = ExplorerGUIDs.IID_IShellFolder; try { IntPtr ptr; STRRET strret; if ((PInvoke.SHBindToParent(pIDL, riid, out ppv, out ptr) != 0) || (ppv == null)) { return(string.Empty); } uint uFlags = fDisplayName ? 0 : 0x8000u; StringBuilder pszBuf = new StringBuilder(260); if (ppv.GetDisplayNameOf(ptr, uFlags, out strret) == 0) { PInvoke.StrRetToBuf(ref strret, ptr, pszBuf, pszBuf.Capacity); } return(pszBuf.ToString()); } catch { } finally { if (ppv != null) { Marshal.ReleaseComObject(ppv); } } return(string.Empty); }
public static DragDropEffects DoDragDrop(string path, Control control) { DragDropEffects none; if ((path == null) || (path.Length == 0)) { return(DragDropEffects.None); } IShellFolder ppv = null; object obj2 = null; IntPtr zero = IntPtr.Zero; try { IntPtr ptr2; zero = PInvoke.ILCreateFromPath(path); if (((zero == IntPtr.Zero) || (PInvoke.SHBindToParent(zero, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr2) != 0)) || (ppv == null)) { return(DragDropEffects.None); } IntPtr[] apidl = new IntPtr[] { ptr2 }; uint rgfReserved = 0; Guid riid = ExplorerGUIDs.IID_IDataObject; ppv.GetUIObjectOf(IntPtr.Zero, (uint)apidl.Length, apidl, ref riid, ref rgfReserved, out obj2); if (obj2 != null) { return(control.DoDragDrop(obj2, DragDropEffects.Link | DragDropEffects.Move | DragDropEffects.Copy)); } none = DragDropEffects.None; } finally { if (obj2 != null) { Marshal.ReleaseComObject(obj2); obj2 = null; } if (ppv != null) { Marshal.ReleaseComObject(ppv); ppv = null; } if (zero != IntPtr.Zero) { PInvoke.CoTaskMemFree(zero); } } return(none); }
public static string GetShellInfoTipText(IntPtr pIDL, bool fAllowSlow) { if (pIDL != IntPtr.Zero) { IShellFolder ppv = null; IQueryInfo o = null; try { IntPtr ptr; if (PInvoke.SHBindToParent(pIDL, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr) == 0) { Guid riid = ExplorerGUIDs.IID_IQueryInfo; IntPtr[] apidl = new IntPtr[] { ptr }; uint rgfReserved = 0; object obj2; if (ppv.GetUIObjectOf(IntPtr.Zero, 1, apidl, ref riid, ref rgfReserved, out obj2) == 0) { string str; o = obj2 as IQueryInfo; if ((o != null) && (o.GetInfoTip(fAllowSlow ? 8 : 0, out str) == 0)) { return(str); } } } } catch (Exception exception) { QTUtility2.MakeErrorLog(exception, null); } finally { if (ppv != null) { Marshal.ReleaseComObject(ppv); } if (o != null) { Marshal.ReleaseComObject(o); } } } return(null); }
public static uint GetAttributes(IntPtr pIDL, bool fValidate) { if (pIDL != IntPtr.Zero) { uint rgfInOut = 0x60010100; if (fValidate) { rgfInOut |= 0x1000000; } Guid riid = ExplorerGUIDs.IID_IShellFolder; IShellFolder ppv = null; try { IntPtr ptr; if (PInvoke.SHBindToParent(pIDL, riid, out ppv, out ptr) == 0) { IntPtr[] apidl = new IntPtr[] { ptr }; int num2 = ppv.GetAttributesOf(1, apidl, ref rgfInOut); if (fValidate) { return((uint)num2); } if (num2 == 0L) { return(rgfInOut); } } return(uint.MaxValue); } catch { } finally { if (ppv != null) { Marshal.ReleaseComObject(ppv); } } } return(uint.MaxValue); }
public static int PopUpSystemContextMenu(IDLWrapper idlw, Point pntShow, ref IContextMenu2 pIContextMenu2, IntPtr hwndParent, bool fCanRemove) { IShellFolder ppv = null; int num5; try { IntPtr ptr; if ((!idlw.Available || (PInvoke.SHBindToParent(idlw.PIDL, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr) != 0)) || (ppv == null)) { return(-1); } IntPtr[] apidl = new IntPtr[] { ptr }; uint rgfReserved = 0; Guid riid = ExplorerGUIDs.IID_IContextMenu; object obj2; ppv.GetUIObjectOf(IntPtr.Zero, (uint)apidl.Length, apidl, ref riid, ref rgfReserved, out obj2); if (pIContextMenu2 != null) { Marshal.ReleaseComObject(pIContextMenu2); pIContextMenu2 = null; } pIContextMenu2 = obj2 as IContextMenu2; if (pIContextMenu2 == null) { return(-2); } ContextMenu menu = new ContextMenu(); uint uFlags = 0; if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { uFlags |= 0x100; } pIContextMenu2.QueryContextMenu(menu.Handle, 0, 1, 0xffff, uFlags); if (fCanRemove) { PInvoke.AppendMenu(menu.Handle, 0x800, IntPtr.Zero, null); PInvoke.AppendMenu(menu.Handle, 0, new IntPtr(0xffff), QTUtility.ResMain[0x19]); } if ((idlw.HasPath && (idlw.Path.Length > 3)) && (idlw.IsFileSystemFolder || idlw.IsFileSystemFile)) { if (!fCanRemove) { PInvoke.AppendMenu(menu.Handle, 0x800, IntPtr.Zero, null); } PInvoke.AppendMenu(menu.Handle, 0, new IntPtr(0xfffe), QTUtility.ResMain[0x1a]); } uint num3 = PInvoke.TrackPopupMenu(menu.Handle, 0x100, pntShow.X, pntShow.Y, 0, hwndParent, IntPtr.Zero); int num4 = -3; switch (num3) { case 0: num4 = 0xfffd; break; case 0xffff: menu.Dispose(); return(0xffff); case 0xfffe: if (idlw.HasPath) { try { string directoryName = Path.GetDirectoryName(idlw.Path); if (Directory.Exists(directoryName)) { IntPtr currentHandle = QTUtility.instanceManager.CurrentHandle; if (PInvoke.IsWindow(currentHandle)) { QTUtility2.SendCOPYDATASTRUCT(currentHandle, (IntPtr)0x10, directoryName, IntPtr.Zero); num4 = 0xfffe; } else { Process.Start(directoryName); num4 = -4; } } } catch { SystemSounds.Asterisk.Play(); } } break; default: { CMINVOKECOMMANDINFO structure = new CMINVOKECOMMANDINFO(); structure.cbSize = Marshal.SizeOf(structure); structure.fMask = 0; structure.hwnd = hwndParent; structure.lpVerb = (IntPtr)((num3 - 1) & 0xffff); structure.lpParameters = IntPtr.Zero; structure.lpDirectory = IntPtr.Zero; structure.nShow = 1; structure.dwHotKey = 0; structure.hIcon = IntPtr.Zero; num4 = pIContextMenu2.InvokeCommand(ref structure); break; } } menu.Dispose(); num5 = num4; } catch { num5 = -1; } finally { if (ppv != null) { Marshal.ReleaseComObject(ppv); } } return(num5); }
public static int PopUpSystemContextMenu(List <string> lstPaths, Point pntShow, ref IContextMenu2 pIContextMenu2, IntPtr hwndParent) { IShellFolder ppv = null; List <IntPtr> list = new List <IntPtr>(); try { IntPtr ptr; List <IntPtr> list2 = new List <IntPtr>(); foreach (IntPtr item in lstPaths.Select(PInvoke.ILCreateFromPath).Where(item => item != IntPtr.Zero)) { list.Add(item); list2.Add(PInvoke.ILFindLastID(item)); } if ((list.Count == 0) || (PInvoke.SHBindToParent(list[0], ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr) != 0)) { return(-1); } IntPtr[] apidl = list2.ToArray(); uint rgfReserved = 0; Guid riid = ExplorerGUIDs.IID_IContextMenu; object obj2; ppv.GetUIObjectOf(IntPtr.Zero, (uint)apidl.Length, apidl, ref riid, ref rgfReserved, out obj2); if (pIContextMenu2 != null) { Marshal.ReleaseComObject(pIContextMenu2); pIContextMenu2 = null; } pIContextMenu2 = obj2 as IContextMenu2; if (pIContextMenu2 == null) { return(-1); } using (ContextMenu menu = new ContextMenu()) { uint uFlags = 0; if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { uFlags |= 0x100; } pIContextMenu2.QueryContextMenu(menu.Handle, 0, 1, 0xffff, uFlags); uint num3 = PInvoke.TrackPopupMenu(menu.Handle, 0x100, pntShow.X, pntShow.Y, 0, hwndParent, IntPtr.Zero); if (num3 != 0) { CMINVOKECOMMANDINFO structure = new CMINVOKECOMMANDINFO(); structure.cbSize = Marshal.SizeOf(structure); structure.fMask = 0; structure.hwnd = hwndParent; structure.lpVerb = (IntPtr)((num3 - 1) & 0xffff); structure.lpParameters = IntPtr.Zero; structure.lpDirectory = IntPtr.Zero; structure.nShow = 1; structure.dwHotKey = 0; structure.hIcon = IntPtr.Zero; pIContextMenu2.InvokeCommand(ref structure); return(0); } } } catch { } finally { if (ppv != null) { Marshal.ReleaseComObject(ppv); } foreach (IntPtr ptr3 in list) { if (ptr3 != IntPtr.Zero) { PInvoke.CoTaskMemFree(ptr3); } } } return(-1); }
public static DragDropEffects DoDragDrop(List <string> lstPaths, Control control, bool fSameDirecotry) { DragDropEffects none; if ((lstPaths == null) || (lstPaths.Count == 0)) { return(DragDropEffects.None); } IShellFolder ppv = null; object obj2 = null; List <IntPtr> list = new List <IntPtr>(); try { IntPtr[] ptrArray; if (fSameDirecotry) { IntPtr ptr2; IntPtr item = PInvoke.ILCreateFromPath(lstPaths[0]); list.Add(item); if ((PInvoke.SHBindToParent(item, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr2) != 0) || (ppv == null)) { return(DragDropEffects.None); } List <IntPtr> list2 = new List <IntPtr>(); if (ptr2 != IntPtr.Zero) { list2.Add(ptr2); } for (int i = 1; i < lstPaths.Count; i++) { IntPtr ptr3 = PInvoke.ILCreateFromPath(lstPaths[i]); if (ptr3 != IntPtr.Zero) { list.Add(ptr3); IntPtr ptr4 = PInvoke.ILFindLastID(ptr3); if (ptr4 != IntPtr.Zero) { list2.Add(ptr4); } } } if (list2.Count == 0) { return(DragDropEffects.None); } ptrArray = list2.ToArray(); } else { list.AddRange(lstPaths.Select(PInvoke.ILCreateFromPath).Where(ptr5 => ptr5 != IntPtr.Zero)); PInvoke.SHGetDesktopFolder(out ppv); if ((list.Count == 0) || (ppv == null)) { return(DragDropEffects.None); } ptrArray = list.ToArray(); } uint rgfReserved = 0; Guid riid = ExplorerGUIDs.IID_IDataObject; ppv.GetUIObjectOf(IntPtr.Zero, (uint)ptrArray.Length, ptrArray, ref riid, ref rgfReserved, out obj2); if (obj2 != null) { return(control.DoDragDrop(obj2, DragDropEffects.Link | DragDropEffects.Move | DragDropEffects.Copy)); } none = DragDropEffects.None; } finally { if (obj2 != null) { Marshal.ReleaseComObject(obj2); } if (ppv != null) { Marshal.ReleaseComObject(ppv); } foreach (IntPtr ptr6 in list) { if (ptr6 != IntPtr.Zero) { PInvoke.CoTaskMemFree(ptr6); } } } return(none); }
public int DragDrop(System.Runtime.InteropServices.ComTypes.IDataObject pDataObj, int grfKeyState, BandObjectLib.POINT pt, ref DragDropEffects pdwEffect) { try { if (this.DragFileOver != null) { DragEventArgs e = new DragEventArgs(null, grfKeyState, pt.x, pt.y, DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll, pdwEffect); this.DragFileOver(null, e); pdwEffect = e.Effect; } else { pdwEffect = DragDropEffects.Copy; } if (pdwEffect != DragDropEffects.None) { if (this.DragFileDrop != null) { IntPtr ptr; byte[] buffer; switch (this.DragFileDrop(out ptr, out buffer)) { case -1: return(0); case 0: { IShellFolder ppv = null; object obj2 = null; Guid riid = ExplorerGUIDs.IID_IShellFolder; Guid guid2 = ExplorerGUIDs.IID_IDropTarget; using (IDLWrapper wrapper = new IDLWrapper(buffer)) { if (wrapper.Available && wrapper.IsDropTarget) { try { IntPtr ptr2; if (PInvoke.SHBindToParent(wrapper.PIDL, riid, out ppv, out ptr2) == 0) { uint rgfReserved = 0; IntPtr[] apidl = new IntPtr[] { ptr2 }; if (ppv.GetUIObjectOf(ptr, 1, apidl, ref guid2, ref rgfReserved, out obj2) == 0) { _IDropTarget target = obj2 as _IDropTarget; if (target != null) { DragDropEffects effects = pdwEffect; if (target.DragEnter(pDataObj, this.iLastKeyState, pt, ref effects) == 0) { effects = pdwEffect; if (target.DragOver(this.iLastKeyState, pt, ref effects) == 0) { if ((this.iLastKeyState & 2) != 0) { pdwEffect = DragDropEffects.Link | DragDropEffects.Move | DragDropEffects.Copy; } return(target.DragDrop(pDataObj, this.iLastKeyState, pt, ref pdwEffect)); } } } } } } catch { } finally { if (ppv != null) { Marshal.ReleaseComObject(ppv); } if (obj2 != null) { Marshal.ReleaseComObject(obj2); } if (this.DragDropEnd != null) { this.DragDropEnd(this, EventArgs.Empty); } } } } return(0); } } } FORMATETC format = new FORMATETC(); format.cfFormat = 15; format.ptd = IntPtr.Zero; format.dwAspect = DVASPECT.DVASPECT_CONTENT; format.lindex = -1; format.tymed = TYMED.TYMED_HGLOBAL; STGMEDIUM medium = new STGMEDIUM(); try { pDataObj.GetData(ref format, out medium); PInvoke.SendMessage(this.hwnd, 0x233, medium.unionmember, IntPtr.Zero); } catch { } finally { PInvoke.ReleaseStgMedium(ref medium); } } } finally { if (pDataObj != null) { Marshal.FinalReleaseComObject(pDataObj); } } return(0); }