Exemplo n.º 1
0
        /// <summary>
        /// Tries to get a typed clipboard format as a stream from the current clipboard. Returns false
        /// if the format does not exist, or fails for another reason.
        /// </summary>
        public virtual bool TryGetFormatStream(ClipboardFormat format, out Stream stream)
        {
            if (TryGetFormatObject(format.Id, new BytesDataConverter(), out var bytes))
            {
                if (bytes != null)
                {
                    stream = new MemoryStream(bytes);

                    return(true);
                }
            }

            stream = default;
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a list of all the formats currently stored in the current clipboard object.
        /// </summary>
        public virtual IEnumerable <ClipboardFormat> GetPresentFormats()
        {
            ThrowIfDisposed();

            uint next = NativeMethods.EnumClipboardFormats(0);

            while (next != 0)
            {
                yield return(ClipboardFormat.GetFormatById(next));

                next = NativeMethods.EnumClipboardFormats(next);
            }

            // If there are no more clipboard formats to enumerate, the return value is zero.
            // In this case, the GetLastError function returns the value ERROR_SUCCESS.
            var err = Marshal.GetLastWin32Error();

            if (err != 0)
            {
                Marshal.ThrowExceptionForHR(err);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set clipboard format to the current clipboard. This will clear the clipboard
        /// if this is the first call to "Set" since the clipboard handle was opened.
        /// </summary>
        public virtual void SetFormat(ClipboardFormat format, Stream stream)
        {
            var bytes = StructUtil.ReadBytes(stream);

            SetFormatObject(format.Id, bytes, new BytesDataConverter());
        }
Exemplo n.º 4
0
 /// <summary>
 /// Set a clipboard format to the current clipboard. This will clear the clipboard
 /// if this is the first call to "Set" since the clipboard handle was opened.
 /// </summary>
 public virtual void SetFormat(ClipboardFormat format, byte[] bytes)
 {
     SetFormatObject(format.Id, bytes, new BytesDataConverter());
 }
Exemplo n.º 5
0
 /// <summary>
 /// Set clipboard format to the current clipboard. This will clear the clipboard
 /// if this is the first call to "Set" since the clipboard handle was opened.
 /// </summary>
 public virtual void SetFormat <T>(ClipboardFormat <T> format, T obj)
 {
     SetFormatObject(format.Id, obj, format.TypeObjectReader);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Retrieves a typed clipboard format as a stream from the current clipboard. Throws exception if
 /// the format is not currently on the clipboard.
 /// </summary>
 public virtual Stream GetFormatStream(ClipboardFormat format)
 {
     return(new MemoryStream(GetFormatBytes(format)));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Retrieves a typed clipboard format as bytes from the current clipboard. Throws exception if
 /// the format is not currently on the clipboard.
 /// </summary>
 public virtual byte[] GetFormatBytes(ClipboardFormat format)
 {
     return(GetFormatObject(format.Id, new BytesDataConverter()));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Tries to get a typed clipboard format as bytes from the current clipboard. Returns false
 /// if the format does not exist, or fails for another reason.
 /// </summary>
 public virtual bool TryGetFormatBytes(ClipboardFormat format, out byte[] bytes)
 {
     return(TryGetFormatObject(format.Id, new BytesDataConverter(), out bytes));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Retrieves a typed clipboard format object from the current clipboard. Throws exception if
 /// the format is not currently on the clipboard.
 /// </summary>
 public virtual T GetFormatType <T>(ClipboardFormat <T> format)
 {
     return(GetFormatObject(format.Id, format.TypeObjectReader));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Tries to get a typed clipboard format object from the current clipboard. Returns false
 /// if the format does not exist, or fails for another reason.
 /// </summary>
 public virtual bool TryGetFormatType <T>(ClipboardFormat <T> format, out T value)
 {
     return(TryGetFormatObject(format.Id, format.TypeObjectReader, out value));
 }