By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,710 Members | 1,613 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,710 IT Pros & Developers. It's quick & easy.

Question regarding the clipboard

P: n/a
LG
Just have a question with regards to the clipboard, and how to read what
other applications (Adobe InDesignCS) place in the clipboard.

I am currently in the process of creating a booklet from a database, and I
need the data to be laid out in a tabular format, and set out in a specific
way. At the current point in time, I am copy/pasting the raw text from the
database into a table layout in InDesign. What I was thinking is that if I
could somehow find out exactly what data is placed into clipboard when I
copy the table (in InDesign) then I can write an app to output the data (and
whatever else goes into making a clipboard copy of an InDesign table) to a
text file in that format. So, in theory, I can just copy the contents of the
text file, and paste it into InDesign, which would then create the table and
the contents.

However... Using, Clipboard.GetData and Clipboard.GetText, it seems that
only the text portion of the copied table is, well, copied. No formatting,
no table data, or anything other than the straight text.

My question is, is InDesign storing the format of the data (in this case the
format that tells InDesign that the data in clipboard is a table) in another
place that is not included in the Clipboard method, and if so, is it
possible to retrieve the formatting data.

I hope this makes sence to everyone :P

Thanks in advance
G
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Most apps that utilize specific formats utilize a function of the clipboard
API that allows the registering of private clipboard formats. In doing so
the calling app provides a custom name that the clipboard format is to be
known, and the RegisterClipboardFormat function returns an app-specific
value representing the key to access data in that format. The value will be
between &HC000 and &HFFFF&.

The EnumClipboardFormats API provides a means for any app to enumerate the
data formats currently available on the clipboard.

The types of data VB can access are called "standard clipboard formats" that
Windows maintains for use by any/all apps, if desired. In API parlance they
are known as CF_ (clipboard format) CF_BITMAP, CB_TEXT, etc corresponding to
VB's clipboard constants. But these are but a minor subset of the standard
clipboard data formats Windows makes available ...

CF_BITMAP A handle to a bitmap (HBITMAP).
CF_DIB A memory object containing a BITMAPINFO structure followed by
the bitmap bits.
CF_DIBV5 Windows 2000/XP: A memory object containing a BITMAPV5HEADER
structure followed by the bitmap color space information and the bitmap
bits.
CF_DIF Software Arts' Data Interchange Format.
CF_DSPBITMAP Bitmap display format associated with a private format.
The hMem parameter must be a handle to data that can be displayed in bitmap
format in lieu of the privately formatted data.
CF_DSPENHMETAFILE Enhanced metafile display format associated with a
private format. The hMem parameter must be a handle to data that can be
displayed in enhanced metafile format in lieu of the privately formatted
data.
CF_DSPMETAFILEPICT Metafile-picture display format associated with a
private format. The hMem parameter must be a handle to data that can be
displayed in metafile-picture format in lieu of the privately formatted
data.
CF_DSPTEXT Text display format associated with a private format. The
hMem parameter must be a handle to data that can be displayed in text format
in lieu of the privately formatted data.
CF_ENHMETAFILE A handle to an enhanced metafile (HENHMETAFILE).
CF_GDIOBJFIRST through CF_GDIOBJLAST Range of integer values for
application-defined Microsoft Windows Graphics Device Interface (GDI) object
clipboard formats. Handles associated with clipboard formats in this range
are not automatically deleted using the GlobalFree function when the
clipboard is emptied. Also, when using values in this range, the hMem
parameter is not a handle to a GDI object, but is a handle allocated by the
GlobalAlloc function with the GMEM_MOVEABLE flag.
CF_HDROP A handle to type HDROP that identifies a list of files. An
application can retrieve information about the files by passing the handle
to the DragQueryFile functions.
CF_LOCALE The data is a handle to the locale identifier associated
with text in the clipboard. When you close the clipboard, if it contains
CF_TEXT data but no CF_LOCALE data, the system automatically sets the
CF_LOCALE format to the current input language. You can use the CF_LOCALE
format to associate a different locale with the clipboard text.
An application that pastes text from the clipboard can retrieve this
format to determine which character set was used to generate the text.

Note that the clipboard does not support plain text in multiple
character sets. To achieve this, use a formatted text data type such as Rich
Text Format (RTF) instead.

Windows NT/2000/XP: The system uses the code page associated with
CF_LOCALE to implicitly convert from CF_TEXT to CF_UNICODETEXT. Therefore,
the correct code page table is used for the conversion.

CF_METAFILEPICT Handle to a metafile picture format as defined by the
METAFILEPICT structure. When passing a CF_METAFILEPICT handle by means of
Dynamic Data Exchange (DDE), the application responsible for deleting hMem
should also free the metafile referred to by the CF_METAFILEPICT handle.
CF_OEMTEXT Text format containing characters in the OEM character set.
Each line ends with a carriage return/linefeed (CR-LF) combination. A null
character signals the end of the data.
CF_OWNERDISPLAY Owner-display format. The clipboard owner must display
and update the clipboard viewer window, and receive the WM_ASKCBFORMATNAME,
WM_HSCROLLCLIPBOARD, WM_PAINTCLIPBOARD, WM_SIZECLIPBOARD, and
WM_VSCROLLCLIPBOARD messages. The hMem parameter must be NULL.
CF_PALETTE Handle to a color palette. Whenever an application places
data in the clipboard that depends on or assumes a color palette, it should
place the palette on the clipboard as well.
If the clipboard contains data in the CF_PALETTE (logical color
palette) format, the application should use the SelectPalette and
RealizePalette functions to realize (compare) any other data in the
clipboard against that logical palette.
When displaying clipboard data, the clipboard always uses as its
current palette any object on the clipboard that is in the CF_PALETTE
format.

CF_PENDATA Data for the pen extensions to the Microsoft Windows for
Pen Computing.
CF_PRIVATEFIRST through CF_PRIVATELAST Range of integer values for
private clipboard formats. Handles associated with private clipboard formats
are not freed automatically; the clipboard owner must free such handles,
typically in response to the WM_DESTROYCLIPBOARD message.
CF_RIFF Represents audio data more complex than can be represented in
a CF_WAVE standard wave format.
CF_SYLK Microsoft Symbolic Link (SYLK) format.
CF_TEXT Text format. Each line ends with a carriage return/linefeed
(CR-LF) combination. A null character signals the end of the data. Use this
format for ANSI text.
CF_WAVE Represents audio data in one of the standard wave formats,
such as 11 kHz or 22 kHz Pulse Code Modulation (PCM).
CF_TIFF Tagged-image file format.
CF_UNICODETEXT Windows NT/2000/XP: Unicode text format. Each line ends
with a carriage return/linefeed (CR-LF) combination. A null character
signals the end of the data.
In order to use any of the non-VB-provided 'standard' formats, you must use
the Clipboard APIs. The ability to access private clipboard formats is
limited, from what I can see. So while it may be possible to determine
through the EnumClipboardFormats API that there is a private InDesign format
on registered, accessing it may not be as straightforward, if at all
possible. The reason you can get the data in raw text mode is that Windows
provides a means for automatic data conversion to some of the standard
clipboard formats.

I believe there is a clipboard demo at www.mvps.org/vb/

--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"LG" <lg@noreply.com> wrote in message
news:l8*****************@news-server.bigpond.net.au...
: Just have a question with regards to the clipboard, and how to read what
: other applications (Adobe InDesignCS) place in the clipboard.
:
: I am currently in the process of creating a booklet from a database, and I
: need the data to be laid out in a tabular format, and set out in a
specific
: way. At the current point in time, I am copy/pasting the raw text from the
: database into a table layout in InDesign. What I was thinking is that if I
: could somehow find out exactly what data is placed into clipboard when I
: copy the table (in InDesign) then I can write an app to output the data
(and
: whatever else goes into making a clipboard copy of an InDesign table) to a
: text file in that format. So, in theory, I can just copy the contents of
the
: text file, and paste it into InDesign, which would then create the table
and
: the contents.
:
: However... Using, Clipboard.GetData and Clipboard.GetText, it seems that
: only the text portion of the copied table is, well, copied. No formatting,
: no table data, or anything other than the straight text.
:
: My question is, is InDesign storing the format of the data (in this case
the
: format that tells InDesign that the data in clipboard is a table) in
another
: place that is not included in the Clipboard method, and if so, is it
: possible to retrieve the formatting data.
:
: I hope this makes sence to everyone :P
:
: Thanks in advance
: G
:
:

Jul 17 '05 #2

P: n/a

"LG" <lg@noreply.com> wrote in message
news:l8*****************@news-server.bigpond.net.au...

| Just have a question with regards to the clipboard, and how to read
what
| other applications (Adobe InDesignCS) place in the clipboard.
|

|
| My question is, is InDesign storing the format of the data (in this
case the
| format that tells InDesign that the data in clipboard is a table) in
another
| place that is not included in the Clipboard method, and if so, is it
| possible to retrieve the formatting data.
|

In addition to Randy's full answer on clipboards, here are a couple of
additional points worth noting:

1. The clipboard can contain multiple formats at the same time. That is,
it can have data as a bitmap, plus data as text, plus data in custom
formats.

You can see this pretty easily using Excel and Word. In an Excel
spreadsheet, highlight some cells and click Copy. Then switch to Word,
and select Edit, Paste Special from the menu. You will see a list of
choices similar to:
Microsoft Excel Worksheet Object
Formatted Text (RTF)
Unformatted Text
Picture
Bitmap
Picture (Enhanced Metafile)

All of these formats are available from the clipboard at the same time.

2. As Randy noted, most programs create their own formats for copying
complex data. While it might be possible to decode the InDesign format,
it would be like trying to figure out how to save some data as an
InDesign file - or to save some text as a Word file, for that matter.
Not easy, and probably not effective use of your time.

Jul 17 '05 #3

P: n/a
Hi Steve ...

I was wondering if perhaps the Picture, Bitmap and Enhanced Metafile options
might not be formats that Word was prepared to reformat the Excel data into,
if desired, rather than data that Excel itself placed on the clipboard. So I
knocked together a demo to do enumeration of the data formats after copying
a few cells from Excel and the following were all returned as available on
the clipboard! .. :

1 CF_TEXT: Null-terminated, plain ANSI text in a global memory
block

2 CF_BITMAP: A bitmap compatible with Windows 2.x

3 CF_METAFILEPICT: Windows metafile with additional information
about how the metafile should be displayed

4 CF_SYLK: Symbolic Link (SYLK) (ASCII text format used by older
Microsoft products)

5 CF_DIF: Software Art's data interchange format (DIF). Also an
ASCII text format

7 CF_OEMTEXT: Similar to CF_TEXT but using the OEM character set

8 CF_DIB: global memory block containing a Windows
device-independent bitmap (DIB) as a BITMAPINFO structure followed by the
bitmap bits

13 CF_UNICODETEXT: Unicode text format, available only under
Windows NT 4.0 or later

14 CF_ENHMETAFILE: handle to an enhanced metafile (HENHMETAFILE)

16 CF_LOCALE: handle to the locale identifier associated with
text in the clipboard

17 CF_DIBV5: memory object containing BITMAPV5HEADER structure
followed by the bitmap color space information and the bitmap bits (2000/XP
only)

129 CF_DSPTEXT: Text display format associated with a private
format

49703 PRIVATE: Biff8
49721 PRIVATE: Biff5
49693 PRIVATE: Biff4
49799 PRIVATE: Biff3
49697 PRIVATE: Biff
49718 PRIVATE: Wk1
49161 PRIVATE: DataObject
49810 PRIVATE: XML Spreadsheet
49349 PRIVATE: HTML Format
49720 PRIVATE: Csv
49366 PRIVATE: Rich Text Format
49163 PRIVATE: Embed Source
49156 PRIVATE: Native
49155 PRIVATE: OwnerLink
49166 PRIVATE: Object Descriptor
49165 PRIVATE: Link Source
49167 PRIVATE: Link Source Descriptor
49385 PRIVATE: Link
49154 PRIVATE: ObjectLink
49171 PRIVATE: Ole Private Data
From reading the MSDN I also discovered that:

- an app can register a data format that requires the application to render
all data on the clipboard, and prepare the view window (the clipboard
viewer). This provides a way for an app to conceal its data format (and
data) from other apps.

- for an application to use (access) a specific non-standard data type, it
just needs to call RegisterClipboardFormat passing the name (string) of the
format that is desired. In the above listings, one could pass "HTML Format"
to the procedure then access the HTML placed on the clipboard by Excel,
using the Clipboard APIs.

--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"Steve Gerrard" <my********@comcast.net> wrote in message
news:Oc********************@comcast.com...
:
: "LG" <lg@noreply.com> wrote in message
: news:l8*****************@news-server.bigpond.net.au...
:
: | Just have a question with regards to the clipboard, and how to read
: what
: | other applications (Adobe InDesignCS) place in the clipboard.
: |
:
: |
: | My question is, is InDesign storing the format of the data (in this
: case the
: | format that tells InDesign that the data in clipboard is a table) in
: another
: | place that is not included in the Clipboard method, and if so, is it
: | possible to retrieve the formatting data.
: |
:
: In addition to Randy's full answer on clipboards, here are a couple of
: additional points worth noting:
:
: 1. The clipboard can contain multiple formats at the same time. That is,
: it can have data as a bitmap, plus data as text, plus data in custom
: formats.
:
: You can see this pretty easily using Excel and Word. In an Excel
: spreadsheet, highlight some cells and click Copy. Then switch to Word,
: and select Edit, Paste Special from the menu. You will see a list of
: choices similar to:
: Microsoft Excel Worksheet Object
: Formatted Text (RTF)
: Unformatted Text
: Picture
: Bitmap
: Picture (Enhanced Metafile)
:
: All of these formats are available from the clipboard at the same time.
:
: 2. As Randy noted, most programs create their own formats for copying
: complex data. While it might be possible to decode the InDesign format,
: it would be like trying to figure out how to save some data as an
: InDesign file - or to save some text as a Word file, for that matter.
: Not easy, and probably not effective use of your time.
:
:
:

Jul 17 '05 #4

P: n/a

"Randy Birch" <rg************@mvps.org> wrote in message
news:de********************@rogers.com...
| Hi Steve ...
|
| I was wondering ...

(snip long list of Excel clipboard formats)

Yikes. As the saying goes, "too much information."

I have sometimes seen a message box when shutting down MS apps (Excel
and Access in particular) about "there is a large amount of information
on the clipboard, do you want to keep it...". Now I see why.

Does Excel actually put all that info on the clipboard when you click
copy, or does it just say its available, and actually only transfer the
data in the format requested? I suppose the answer is "some of each",
but I wonder how much it does up front versus on demand.
Jul 17 '05 #5

P: n/a
LG
Thanks for the replies.

Once again, it seems that what sounds like a simple thing, is actually
really a pain in the butt to do. Just thought I would ask just in case there
was some way that is easier than laying out each and every DB entry
manually.

Thanks again.
Jul 17 '05 #6

P: n/a
That's the $10 question. But unless there's some interprocess communication,
the app responsible for the data has no way of knowing who/what is wanting
to paste it. So I'm almost willing to bet after reading the msdn that all
those different formats are placed there.

Ah ... just tried the same thing again ... with some Excel data copied to
the clipboard there were 32 data formats enumerated as available. I left the
text on the clipboard but shut down Excel - enumeration then indicated there
were now only 5 formats available, all text or rich text format. So it looks
like Excel places the data types available on the clipboard and communicates
directly with the clipboard (or perhaps even with another Office app) to
prepare the data in the requested format if required. Either that or Excel
nukes all but the text versions of the data when it shuts down.

Ah/2 ... looks like one of those choices are the case (for Excel). I copied
Excel data to the clipboard, opened Word, selected Paste Special, selected
Enhanced Metafile, but before saying OK to the paste dialog I closed Excel
.... Word reported the requested data type was unavailable.

--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"Steve Gerrard" <my********@comcast.net> wrote in message
news:Y8********************@comcast.com...
:
: "Randy Birch" <rg************@mvps.org> wrote in message
: news:de********************@rogers.com...
: | Hi Steve ...
: |
: | I was wondering ...
:
: (snip long list of Excel clipboard formats)
:
: Yikes. As the saying goes, "too much information."
:
: I have sometimes seen a message box when shutting down MS apps (Excel
: and Access in particular) about "there is a large amount of information
: on the clipboard, do you want to keep it...". Now I see why.
:
: Does Excel actually put all that info on the clipboard when you click
: copy, or does it just say its available, and actually only transfer the
: data in the format requested? I suppose the answer is "some of each",
: but I wonder how much it does up front versus on demand.
:
:

Jul 17 '05 #7

P: n/a

"Randy Birch" <rg************@mvps.org> wrote in message
news:x4********************@rogers.com...
| That's the $10 question. But unless there's some interprocess
communication,
| the app responsible for the data has no way of knowing who/what is
wanting
| to paste it. So I'm almost willing to bet after reading the msdn that
all
| those different formats are placed there.
|
| Ah ... just tried the same thing again ... with some Excel data copied
to
| the clipboard there were 32 data formats enumerated as available. I
left the
| text on the clipboard but shut down Excel - enumeration then indicated
there
| were now only 5 formats available, all text or rich text format. So it
looks
| like Excel places the data types available on the clipboard and
communicates
| directly with the clipboard (or perhaps even with another Office app)
to
| prepare the data in the requested format if required. Either that or
Excel
| nukes all but the text versions of the data when it shuts down.
|
| Ah/2 ... looks like one of those choices are the case (for Excel). I
copied
| Excel data to the clipboard, opened Word, selected Paste Special,
selected
| Enhanced Metafile, but before saying OK to the paste dialog I closed
Excel
| ... Word reported the requested data type was unavailable.
|
| --
|

Some MSDN snooping reveals:

<MSDN>

The SetClipboardData function places data on the clipboard in a
specified clipboard format.
Parameters:
uFormat - Specifies a clipboard format. This parameter can be a
registered format or any of the standard clipboard formats.
hMem - Handle to the data in the specified format. This parameter can be
NULL, indicating that the window provides data in the specified
clipboard format (renders the format) upon request.
------
The WM_RENDERFORMAT message is sent to the clipboard owner if it has
delayed rendering a specific clipboard format and if an application has
requested data in that format. The clipboard owner must render data in
the specified format and place it on the clipboard by calling the
SetClipboardData function.
-----
The WM_RENDERALLFORMATS message is sent to the clipboard owner before it
is destroyed, if the clipboard owner has delayed rendering one or more
clipboard formats. For the content of the clipboard to remain available
to other applications, the clipboard owner must render data in all the
formats it is capable of generating, and place the data on the clipboard
by calling the SetClipboardData function. When the application returns,
the system removes any unrendered formats from the list of available
clipboard formats.

</MSDN>

So, Excel must call SetClipboardData 5 times using the standard text
clipboard formats and passing the actual data; then call it 27 more
times, specifying its private clipboard formats and passing Null as the
data. If you pick one of the private formats, a WM_RENDERFORMAT message
goes to Excel, which puts that format on the clipboard. If you close
Excel and then pick a private format, it will either have been put on
the clipboard in response to WM_RENDERALLFORMATS, or it will have been
removed from the list of available formats.

Cool. For some reason, this seems like an interesting process to
explore, even though it would be a lot of work to make use of it. It
does seems to me that you could retrieve any of the private formats as a
byte array, and then have fun trying to make sense of it.
Jul 17 '05 #8

P: n/a
I was thinking the same thing ... never toyed with the clipboard api before.
Hmm ...

--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
: Cool. For some reason, this seems like an interesting process to
: explore, even though it would be a lot of work to make use of it. It
: does seems to me that you could retrieve any of the private formats as a
: byte array, and then have fun trying to make sense of it.
:
:

Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.