packages/Windows API Code Pack 1.1/source/WindowsAPICodePack/Shell/Common/ShellObjectCollection.cs
/// <summary>
/// Builds the data for the CFSTR_SHELLIDLIST Drag and Clipboard data format from the 
/// ShellObjects in the collection.
/// </summary>
/// <returns>A memory stream containing the drag/drop data.</returns>
Builds the data for the CFSTR_SHELLIDLIST Drag and Clipboard data format from the
ShellObjects in the collection.
Builds the data for the CFSTR_SHELLIDLIST Drag and Clipboard data format from the ShellObjects in the collection .
public MemoryStream BuildShellIDList()
        {
            if (content.Count == 0)
            {
                throw new InvalidOperationException(LocalizedMessages.ShellObjectCollectionEmptyCollection);
            }
            MemoryStream mstream = new MemoryStream();
            try
            {
                BinaryWriter bwriter = new BinaryWriter(mstream);
                uint itemCount = (uint)(content.Count + 1);
                IntPtr[] idls = new IntPtr[itemCount];
                for (int index = 0; index < itemCount; index++)
                {
                    if (index == 0)
                    {
                        idls[index] = ((ShellObject)KnownFolders.Desktop).PIDL;
                    }
                    else
                    {
                        idls[index] = content[index - 1].PIDL;
                    }
                }
                uint[] offsets = new uint[itemCount + 1];
                for (int index = 0; index < itemCount; index++)
                {
                    if (index == 0)
                    {
                        offsets[0] = (uint)(sizeof(uint) * (offsets.Length + 1));
                    }
                    else
                    {
                        offsets[index] = offsets[index - 1] + ShellNativeMethods.ILGetSize(idls[index - 1]);
                    }
                }
                    typedef struct _IDA {
                    UINT cidl;           number of relative IDList
                    UINT aoffset[1];     [0]: folder IDList, [1]-[cidl]: item IDList
                    } CIDA, * LPIDA;
                bwriter.Write(content.Count);
                foreach (uint offset in offsets)
                {
                    bwriter.Write(offset);
                }
                 copy idls
                foreach (IntPtr idl in idls)
                {
                    byte[] data = new byte[ShellNativeMethods.ILGetSize(idl)];
                    Marshal.Copy(idl, data, 0, data.Length);
                    bwriter.Write(data, 0, data.Length);
                }
            }
            catch
            {
                mstream.Dispose();
                throw;
            }
             return CIDA stream 
            return mstream;
        }
public MemoryStream BuildShellIDList ( ) { if ( content . Count == 0 ) { throw new InvalidOperationException ( LocalizedMessages . ShellObjectCollectionEmptyCollection ) ; } MemoryStream mstream = new MemoryStream ( ) ; try { BinaryWriter bwriter = new BinaryWriter ( mstream ) ; uint itemCount = ( uint ) ( content . Count + 1 ) ; IntPtr [ ] idls = new IntPtr [ itemCount ] ; for ( int index = 0 ; index < itemCount ; index ++ ) { if ( index == 0 ) { idls [ index ] = ( ( ShellObject ) KnownFolders . Desktop ) . PIDL ; } else { idls [ index ] = content [ index - 1 ] . PIDL ; } } uint [ ] offsets = new uint [ itemCount + 1 ] ; for ( int index = 0 ; index < itemCount ; index ++ ) { if ( index == 0 ) { offsets [ 0 ] = ( uint ) ( sizeof ( uint ) * ( offsets . Length + 1 ) ) ; } else { offsets [ index ] = offsets [ index - 1 ] + ShellNativeMethods . ILGetSize ( idls [ index - 1 ] ) ; } } bwriter . Write ( content . Count ) ; foreach ( uint offset in offsets ) { bwriter . Write ( offset ) ; } foreach ( IntPtr idl in idls ) { byte [ ] data = new byte [ ShellNativeMethods . ILGetSize ( idl ) ] ; Marshal . Copy ( idl , data , 0 , data . Length ) ; bwriter . Write ( data , 0 , data . Length ) ; } } catch { mstream . Dispose ( ) ; throw ; } return mstream ; }
Builds the data for the CFSTR_SHELLIDLIST Drag and Clipboard data format from the
ShellObjects in the collection.
Builds the data for the CFSTR_SHELLIDLIST Drag and Clipboard data format from the ShellObjects in the collection .
// number of IDLs to be written (shell objects + parent folder) // grab the object IDLs             // Because the ShellObjects passed in may be from anywhere, the  // parent folder reference must be the desktop. // calculate offset array (folder IDL + item IDLs) // first offset equals size of CIDA header data // Fill out the CIDA header // //    typedef struct _IDA { //    UINT cidl;          // number of relative IDList //    UINT aoffset[1];    // [0]: folder IDList, [1]-[cidl]: item IDList //    } CIDA, * LPIDA; // // copy idls // return CIDA stream 
A memory stream containing the drag/drop data.
A memory stream containing the drag / drop data .