예제 #1
0
        public static void DoDragAndDrop(Control dragSource, IEnumerable <DragFileInfo> files)
        {
            var dataObject      = new DataObjectEx();
            var fileDescriptors = new List <FileDescriptor>();
            var i = 0;

            foreach (var file in files)
            {
                dataObject.SetFileContents(file.Stream, i);
                fileDescriptors.Add(new FileDescriptor
                {
                    cFileName     = file.FileName,
                    nFileSizeHigh = (uint)(file.Stream.Length >> 32),
                    nFileSizeLow  = (uint)(file.Stream.Length & 0xFFFFFFFF),
                    dwFlags       = FileDescriptorFlags.FileSize | FileDescriptorFlags.ProgressUi
                });
                ++i;
            }

            var fileGroupDescriptor = new FileGroupDescriptor(fileDescriptors.Count);
            var descriptorSize      = Marshal.SizeOf(fileGroupDescriptor) +
                                      Marshal.SizeOf <FileDescriptor>() * fileDescriptors.Count;

            using (var descriptorStream = new MemoryStream(descriptorSize))
            {
                StructToArray(fileGroupDescriptor, descriptorStream);
                foreach (var descriptor in fileDescriptors)
                {
                    StructToArray(descriptor, descriptorStream);
                }
                dataObject.SetData("FileGroupDescriptorW", descriptorStream);

                dragSource.DoDragDrop(dataObject, DragDropEffects.Copy);
            }
        }
예제 #2
0
 private static void StructToArray(FileGroupDescriptor @struct, Stream stream)
 {
     stream.Write(BitConverter.GetBytes(@struct.cItems), 0, sizeof(int));
 }