none
Inner workings of clipboard / Paste Special for office apps RRS feed

  • Question

  • I have two (closely related) software components.  One is a full-blown application that generates some data (let's just call them FOO files).  The other is an ActiveX control that displays/manipulates FOO files.

    What I would like to do is to be able to do a "copy" in the application to put a FOO file (or a link to it) on the clipboard; go to PowerPoint or Word; do a Paste Special; and have it be able to insert by FOO viewer control initialized with the FOO data on the clipboard.

    I have researched this as far as I think I can online.  Apparently I don't know the correct Google, uh, I mean, Bing incantation to get the right information.  This seems like a pretty basic question.

    I've got all of the information about how to register a clipboard type; put data on the clipboard; and retrieve it.  What I'm missing is:

    - How do Office apps populate the Paste Special list based on the information on the clipboard?  Asked another way, how do I register my control in such a way that Office apps know that the stuff that's on the clipboard is associated with my FOO viewer control?

    - What COM API is used to initialize my FOO Viewer control with the clipboard data?  I'm assuming it's got something to do with IOleObject::InitFromData()?

    Thanks bunches,
    Dan

    Friday, June 3, 2011 10:45 PM

Answers

  • Hi Dan,

    This last post raised a host of questions, but the fog prevails because of that number. You want to be more comfortable with the ramifications of dropping your control onto PowerPoint under various circumstances. The inference is that the control doesn’t expose a user interface but your control needs to respond to the need of the end user to access a number of foo files.

    The mother of all information about COM, Ole, and the clipboard is in the seminal volume “Inside Ole – Second edition”.  You should use it for reference. Links to its content are found at:

    http://social.msdn.microsoft.com/Search/en-US?query=inside%20ole%202nd%20edition&resultsLang=en-US&beta=0&ac=1

    See the discussion of PasteSpecial beginning on page 581.

    Also please see:
    http://social.msdn.microsoft.com/Search/en-US?query=pastespecial%20dialog%20box&resultsLang=en-US&beta=0&ac=3

    There is a wealth of information that applies to your issue in the KB database of VKB when you use the query argument ‘pastespecial’.

    More useful content is indexed at http://www.codeproject.com/KB/clipboard/

    You may also wish to use more in-depth level of support.  Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    If you do choose to use Microsoft Support the engineer with whom you work will be able to better assist you if you can share your application and provide a more complete description of the business objectives – more specific than ‘foo.’

    By the way, in reply to your comment about the end-user being unhappy about a foo file being on the clipboard but the user didn’t do a Paste operation a touchy part of the process of programmatically using the clipboard is to save the contents either by serializing to an external file, or moving to allocated memory, then your code clears the clipboard to use it, then your code reloads the clipboard with the previous content (which may have been a picture of the user’s new baby.)

    Regards,
    Chris Jensen
    Senior Technical Support Lead

    • Proposed as answer by cjatmsModerator Wednesday, June 29, 2011 9:17 PM
    • Marked as answer by Bruce Song Thursday, July 7, 2011 12:07 PM
    Wednesday, June 22, 2011 6:16 PM
    Moderator

All replies

  • Hi Dan,

    As far as I know, office uses the Ole clipboard which is built on top of the regular Windows clipboard.

    For more details, please take a look at this thread:

    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/ae04e2be-f8ef-4b9f-9422-1a2e46424b7d

    And this article:http://msdn.microsoft.com/en-us/library/6www2be1(VS.80).aspx which describes using OLE clipboard mechanism.

    I hope you can get some useful information from the thread and the article.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Monday, June 6, 2011 7:03 AM
  • I can't answer specifically but I have tried, and failed, to get Word to recognise custom clipboard formats - I think it decides that it already knows about all the formats it can possibly handle, and it is selective about what it populates the Paste Special list with.
     

    Enjoy,
    Tony
    www.WordArticles.com
    Monday, June 6, 2011 10:24 AM
  • Bruce, I am constrained to using straight up COM (not MFC).  I can't seem to find any information on how this works in COM.  Will Office apps just try to call my control via IOleObject::InitFromData() with the clipboard contents stored in an IDataObject format?

    Thanks,
    Dan

    Monday, June 6, 2011 6:27 PM
  • Hi Dan

    We are doing the research abou this problem. There might be some delay about the response. Appriciate your patience.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 7, 2011 10:02 AM
  • Hello Dan,

    I’m uncertain about your FOO Viewer Control. Is that the target of the PasteSpecial operation?  In that case FOOFiles application needs to define the CF_Format and register it. Then your app that binds the control to the office application (Embeds? Inserts?)  needs to copy the file and paste it from the clipboard into the FOOViewer control, or the FOOViewer control  needs code to select the file and copy/paste that into itself.

    Or, does the app or the FOOViewer control pasteSpecial into the host Office application? In that case the file format still has to be defined and its CF_Format needs to be registered.  

    Each COM-compliant application has a list of formats it recognizes. It iterates through the IDataObject  interface methods to try to match the format of the data on the clipboard to one of the native formats that application recognizes.  Your application and the FOOViewControl can coordinate with one-another if the clipboard data is in a custom format.  If you need the Office application to accept a custom format then you need to use the PasteSpecial method of that application

    The content at the following link discusses presenting a PasteSpecial dialog for the end-user’s use.

    SOX990218700115            VB: How to display Paste special dlg box and paste
    https://vkbexternal.partners.extranet.microsoft.com/VKBWebService/ViewContent.aspx?scid=SO;US;SOX990218700115
    (has c code)

    The next 4 articles show the parameter for the signature of the PasteSpecial method of each of the subject Office applications.

    PasteSpecial Method [Word 2007 Developer Reference]
    http://msdn.microsoft.com/en-us/library/bb241758.aspx
    (Contains table of data types of parameters in signature of PasteSpecial)

    Selection.PasteSpecial Method (Microsoft.Office.Interop.Word)
    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.selection.pastespecial(office.11).aspx

    PasteSpecial Method [PowerPoint 2007 Developer Reference]
    http://msdn.microsoft.com/en-us/library/bb251372(office.12).aspx
    (Displays table of parameters for Shapes.PasteSpecial method of PPT Shapes.PasteSpecial)

    PasteSpecial Method [Excel 2007 Developer Reference]
    http://msdn.microsoft.com/en-us/library/bb179201.aspx

    PasteSpecial method in word using C#
    http://social.msdn.microsoft.com/forums/en-US/vsto/thread/7bdf78aa-400c-4481-9bf0-ce0460749600

    Some of the content you get when you query VKB with IDataObject

    250336  INFO: Excel 2000 Needs Metafile Format to Insert Object
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;250336

    118613  INFO: Accessing OLE 2.0 Embedded Object Dirties OLE 1.0 Client
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;118613

    818410  How to save a graphic from the Clipboard to a file by using Visual Basic .NET or Visual Basic 2005
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;818410

    Clipboard Class topic for .NET Framework 1.1
    http://msdn2.microsoft.com/en-us/library/system.windows.forms.clipboard(vs.71).aspx
    (Call SetDataObject to put data on the clipboard. To place a persistent copy of the data on the clipboard, set the copy parameter to true.

    Note Place data on the clipboard in multiple formats to maximize the possibility that a target application, whose format requirements you might not know, can successfully retrieve the data.

    Call GetDataObject to retrieve data from the clipboard. The data is returned as an object that implements the IDataObject interface. Use the methods specified by IDataObject and fields in DataFormats to extract the data from the object. If you do not know the format of the data you retrieved, call the GetFormats method of the IDataObject interface to get a list of all formats that data is stored in. Then call the GetData method of the IDataObject interface, and specify a format that your application can use.

    Note All Windows applications share the system clipboard, so the contents are subject to change when you switch to another application.

    Note A class must be serializable for it to be put on the clipboard. See Serializing Objects for more information on serialization.)
    The content there continues with an Example.

    Please let us know if this information meets your needs.

    Regards,
    Chris Jensen
    Senior Technical Support Lead




    Chris Jensen
    Wednesday, June 15, 2011 5:50 PM
    Moderator
  • Chris,

    Thanks so much for the detailed response.  Sorry if I wasn't clear enough.  Here's how I would ideally like it to work.  From a high-level viewpoint it seems so easy and straightforward.  The "devil is in the details" of course.  I'm not even sure this is possible, although it sure should be.

    Let's assume the following.  FooViewer is an OLE 2.0-compliant, in-place-activation-enabled ActiveX control that can initialize itself (supports IOleObject::InitFromData), supports persistance, etc.  It is registered according to the minimum registration requirements listed in MSDN for ActiveX controls.

    FooApp is used to create Foo files.  A user creates a Foo file in the FooApp and copies it to the clipboard (let's assume that FooApp has registered a custom clipboard format for Foo files).  The user then goes to PowerPoint, and does a Paste Special.  Since there is a Foo file on the clipboard, FooViewer should show up in the list.  They select FooViewer, and the FooViewer control is inserted into the PowerPoint initialized with the data in the clipboard.

    Nice.  So, this leads to a number of specific technical questions:

    1) How do I register my control so that PowerPoint will know that it groks Foo files (i.e. so FooViewer is on the Paste Special list when a Foo file is on the clipboard)?

    2) How does my control know that it is getting created as a result of a Paste Special rather than an Insert->Object... (i.e. initialized without any data)?  I would assume that PowerPoint would get the clipboard data as an IDataObject using the APIs that you mentioned, and feed it to my control via IoleObject::InitFromData(), but I haven't been able to find any documentation on this.

    Clearly I don't always want to initialize my control based on clipboard data -- if a Foo file happens to be on the clipboard but the user didn't do a Paste operation, they will get annoyed if I initialize from the clipboard... right?

    Hope that clears up the fog.  Hopefully you can shed some light from that end of things.

    Regards,
    Dan

    Thursday, June 16, 2011 4:45 PM
  • Hi Dan,

    This last post raised a host of questions, but the fog prevails because of that number. You want to be more comfortable with the ramifications of dropping your control onto PowerPoint under various circumstances. The inference is that the control doesn’t expose a user interface but your control needs to respond to the need of the end user to access a number of foo files.

    The mother of all information about COM, Ole, and the clipboard is in the seminal volume “Inside Ole – Second edition”.  You should use it for reference. Links to its content are found at:

    http://social.msdn.microsoft.com/Search/en-US?query=inside%20ole%202nd%20edition&resultsLang=en-US&beta=0&ac=1

    See the discussion of PasteSpecial beginning on page 581.

    Also please see:
    http://social.msdn.microsoft.com/Search/en-US?query=pastespecial%20dialog%20box&resultsLang=en-US&beta=0&ac=3

    There is a wealth of information that applies to your issue in the KB database of VKB when you use the query argument ‘pastespecial’.

    More useful content is indexed at http://www.codeproject.com/KB/clipboard/

    You may also wish to use more in-depth level of support.  Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    If you do choose to use Microsoft Support the engineer with whom you work will be able to better assist you if you can share your application and provide a more complete description of the business objectives – more specific than ‘foo.’

    By the way, in reply to your comment about the end-user being unhappy about a foo file being on the clipboard but the user didn’t do a Paste operation a touchy part of the process of programmatically using the clipboard is to save the contents either by serializing to an external file, or moving to allocated memory, then your code clears the clipboard to use it, then your code reloads the clipboard with the previous content (which may have been a picture of the user’s new baby.)

    Regards,
    Chris Jensen
    Senior Technical Support Lead

    • Proposed as answer by cjatmsModerator Wednesday, June 29, 2011 9:17 PM
    • Marked as answer by Bruce Song Thursday, July 7, 2011 12:07 PM
    Wednesday, June 22, 2011 6:16 PM
    Moderator