private static bool GetPrefferdDropEffect(IntPtr hwnd) { uint uFormat = PInvoke.RegisterClipboardFormat("Preferred DropEffect"); bool flag = false; if (PInvoke.OpenClipboard(hwnd)) { try { IntPtr clipboardData = PInvoke.GetClipboardData(uFormat); if (!(clipboardData != IntPtr.Zero)) { return(flag); } IntPtr source = PInvoke.GlobalLock(clipboardData); try { if (source != IntPtr.Zero) { byte[] destination = new byte[4]; Marshal.Copy(source, destination, 0, 4); flag = (destination[0] & 2) != 0; } } finally { PInvoke.GlobalUnlock(clipboardData); } } finally { PInvoke.CloseClipboard(); } } return(flag); }
public static bool SetClipboardFileDropPaths(List <string> lstPaths, bool fCut, IntPtr hwnd) { string str = MakeFILEOPPATHS(lstPaths); if ((hwnd != IntPtr.Zero) && (str.Length > 1)) { if (!PInvoke.OpenClipboard(hwnd)) { return(false); } PInvoke.EmptyClipboard(); try { DROPFILES structure = new DROPFILES(); structure.pFiles = Marshal.SizeOf(structure); structure.fWide = true; IntPtr hMem = PInvoke.GlobalAlloc(0x42, (IntPtr)(Marshal.SizeOf(structure) + (str.Length * Marshal.SystemMaxDBCSCharSize))); if (hMem != IntPtr.Zero) { IntPtr ptr = PInvoke.GlobalLock(hMem); Marshal.StructureToPtr(structure, ptr, false); Marshal.Copy(str.ToCharArray(), 0, PtrPlus(ptr, Marshal.SizeOf(structure)), str.Length); PInvoke.GlobalUnlock(hMem); } IntPtr ptr3 = PInvoke.GlobalAlloc(0x42, (IntPtr)4); if (ptr3 != IntPtr.Zero) { IntPtr destination = PInvoke.GlobalLock(ptr3); byte[] source = new byte[4]; source[0] = fCut ? ((byte)2) : ((byte)5); Marshal.Copy(source, 0, destination, 4); PInvoke.GlobalUnlock(ptr3); } if ((hMem != IntPtr.Zero) && (ptr3 != IntPtr.Zero)) { uint uFormat = PInvoke.RegisterClipboardFormat("Preferred DropEffect"); PInvoke.SetClipboardData(15, hMem); PInvoke.SetClipboardData(uFormat, ptr3); return(true); } } finally { PInvoke.CloseClipboard(); } } return(false); }