示例#1
0
        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);
        }
示例#2
0
 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;
 }