locked
Inserting a file in the clipboard RRS feed

  • Question

  • Hello oh great Microsoft developing community!

    I have just started working with C++ and I want to put a file into the clipboard, if possible on demand. I only have a Bytestream of the file and want to build it when its needed.

    I want to have the file in the FormatList (actually, I have the file already there), but use delayed rendering. Only when paste is called the file should be build.

    What do I have to do? I am more than confused, do I have to use Ole with Ole.SetClipboard (And what kind of cf-format do I have to put into the Formatetc then? Or is a simple Clipboard.SetData(file.xyz) enough?

    Thursday, September 11, 2014 9:27 AM

Answers

  • Format choice would depends on what kind of object you are copying, and what kind of program you want to paste into. For example if you are copying an image tag in HTML you may want to put both image and its alt text on the clipboard. Generally speaking you should give as many formats as you can to the object you are copying, budget and time permitting.

    If the byte stream is from an existing file, you need to supply CF_HDROP and CFSTR_SHELLIDLIST. For file-like streasm data, use CFSTR_FILECONTENTS/CFSTR_FILEDESCRIPTOR formats with TYMED_ISTREAM. 

    Check http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/94bb2db4-3ca2-4cd8-9f7c-6dd9aab6fd18/need-help-to-complete-gdi-program-to-loadsave-to-clipboard?forum=windowssdk about the order of clipboard format choice. 



    Visual C++ MVP

    • Marked as answer by Sarenor Friday, September 12, 2014 7:56 AM
    Thursday, September 11, 2014 5:35 PM

All replies

  • Format choice would depends on what kind of object you are copying, and what kind of program you want to paste into. For example if you are copying an image tag in HTML you may want to put both image and its alt text on the clipboard. Generally speaking you should give as many formats as you can to the object you are copying, budget and time permitting.

    If the byte stream is from an existing file, you need to supply CF_HDROP and CFSTR_SHELLIDLIST. For file-like streasm data, use CFSTR_FILECONTENTS/CFSTR_FILEDESCRIPTOR formats with TYMED_ISTREAM. 

    Check http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/94bb2db4-3ca2-4cd8-9f7c-6dd9aab6fd18/need-help-to-complete-gdi-program-to-loadsave-to-clipboard?forum=windowssdk about the order of clipboard format choice. 



    Visual C++ MVP

    • Marked as answer by Sarenor Friday, September 12, 2014 7:56 AM
    Thursday, September 11, 2014 5:35 PM
  • What I want to do is to be able to get a filename.extension and the actual file content, combine it and put it in the clipboard to make it pasteable.

    If I understood you, the CFSTR_FILECONTENTS/CFSTR_FILEDESCRIPTOR formats seem like the right choice for that. Please correct me if I'm wrong.

    Friday, September 12, 2014 8:13 AM