GFF Format Summary: Microsoft Windows Clipboard

# Microsoft Windows Clipboard

Also Known As: CLP

Type | Metafile
Colors | Bilevel to 24-bit
Compression | None
Maximum Image Size | 32Kx32K and 2Gx2G pixels
Multiple Images Per File | Yes
Numerical Format | Little-endian
Originator | Microsoft Corporation
Platform | Microsoft Windows
Supporting Applications | Microsoft Clipboard and ClipBook Viewer
See Also | Microsoft Bitmap, Microsoft Metafile, DIF, SYLK, RTF

Usage
Used as a "one-format-saves-all" solution for easily storing data in Windows to disk.

Comments
A useful and under-utilized format. Programmers can safely assume that every installation of Windows will have the ability to read and write Clipboard files.

The Clipboard file format is used to store Microsoft Windows Clipboard data to disk. The Clipboard is an area of shared memory found in the Windows operating system, and is the simplest mechanism available to exchange data between applications running in the Windows environment.

Contents:
File Organization
File Details
For Further Information

A set of functions in the Windows API is used to transfer data between the Clipboard and Windows applications. For example, the Cut, Copy, Clear, Paste, and Undo functions found in many Windows applications all use these function to access Clipboard memory as an area for temporary storage and data exchange. However, only one Windows application may access the Clipboard at a time. The Clipboard can also be accessed directly using the built-in Windows applications Clipboard Viewer and ClipBook Viewer.

The Clipboard Viewer is a simple application used to view the entire contents of the Clipboard and to save its data to disk using the CLP file format. The ClipBook Viewer is an extended version of the Clipboard Viewer that allows stored data to be divided into separate pages of information and shared over a Microsoft (NetBEUI) network using the OLE or DDE protocols. Each page in the ClipBook may hold the data captured by a single Cut or Copy operation. ClipBook may contain a maximum of 127 separate pages, each identified by a name up to 47 characters in length, and limited in size only by the amount of available disk space. Each page of the ClipBook may be stored in a separate CLP file.

The Clipboard Viewer and ClipBook Viewer are separate programs, but both use the executable file name clipbrd.exe, so it is not likely you will find both programs installed in the same Windows environment.

The Clipboard Viewer under Windows 2.x and 3.x is found in the Main group box. Windows for Workgroups 3.x and Windows NT 3.x provide only the ClipBook Viewer, also found in the Main group box.

Clipboard Viewer is not installed by default in Windows 95. To install the Clipboard Viewer under Windows 95, you must select Add/Remove Programs in Control Panel, click the Windows Setup tab, click Accessories, and then click Details. Click the Clipboard Viewer check box to select it, and then click OK or Apply. The Clipboard Viewer will be installed and a shortcut will be placed in the Accessories menu under the Programs menu.

The CD-ROM version of Windows 95 and CD-ROM Extras for Microsoft Windows 95 Upgrade also includes the ClipBook Viewer, but the floppy disk version of Windows 95 does not. If you install Windows 95 over Windows for Workgroups version 3.1, and during Setup choose to not install the Windows 95 Clipboard Viewer, Windows 95 retains and will use the Windows for Workgroups ClipBook Viewer.

It is important to realize that both the Clipboard and ClipBook Viewer are only applications that access the Clipboard and its data, and are not the Clipboard themselves. This point is often a source of confusion for both Windows users and programmers alike.

## File Organization

Clipboard files use a very simple data format, but can be quite complicated because they can store many types of data. The CLP file format begins with a header and is followed by a directory of one or more records that indicates the type and location of data within the Clipboard file. Following these records are the actual Clipboard data. (See Figure Microsoft Windows Clipboard-1.)

#### Figure Microsoft Windows Clipboard-1: Basic layout of a CLP file

There will be one section of data per record. The standard Clipboard data formats are listed in Table Microsoft Windows Clipboard-1.

Table Microsoft Windows Clipboard-1: Standard Clipboard Data Formats
Data Format | Format ID | Description
--- | --- | ---
TEXT | 0x0001 | ANSI text
BITMAP | 0x0002 | Windows Device-Dependent Bitmap
METAFILE | 0x0003 | Windows Clipboard Metafile
SYLK | 0x0004 | Microsoft spreadsheet format
DIF | 0x0005 | Soft Arts spreadsheet format
TIFF | 0x0006 | Adobe Tag Image File Format
OEMTEXT | 0x0007 | ASCII text
DIB | 0x0008 | Windows Device-Independent Bitmap
PALETTE | 0x0009 | Windows DIB Color Palette
PENDATA | 0x000A | Microsoft Pen Windows data
RIFF | 0x000B | Microsoft Resource Interchange File Format
WAVE | 0x000C | Microsoft Audio File Format
UNICODETEXT | 0x000D | Unicode text (Windows NT only)
ENHMETAFILE | 0x000E | Windows Enhanced Metafile (Windows 95 and NT only)
HDROP | 0x000F | Double NULL-terminated list of strings (Windows 95 only)
LOCALE | 0x0010 | Language and character set specifier (Windows 95 only)

Most of the native Windows data formats are supported by the Clipboard. The Clipboard is also capable of storing private or user-defined data formats (Table Microsoft Windows Metafile-2). Applications such as the Microsoft Windows Write word processor store a variety of private data formats using the Clipboard. You can also store any other file format as private data inside of a CLP file and read the file into the Clipboard using the Clipboard Viewer or your own Clipboard-aware application. Your application is then responsible for parsing and displaying the private data.

Table Microsoft Windows Clipboard-2: Private Clipboard Data Formats
Data Formats | Format ID | Description
--- | --- | ---
OWNERDISPLAY | 0x0080 | Private data not displayable on the Clipboard
DSPTEXT | 0x0081 | Display Text
DSPBITMAP | 0x0082 | Display Bitmap
DSPMETAFILEPICT | 0x0083 | Display Metafile Picture
DSPENHMETAFILE | 0x008E | Display Enhanced Metafile
PRIVATEFIRST | 0x0200 | First Private Data Format
PRIVATELAST | 0x02FF | Last Private Data Format
GDIOBJFIRST | 0x0300 | First Private Graphics Device Interface Object
GDIOBJLAST | 0x03FF | Last Private Graphics Device Interface Object

When a CLP file is read by a Clipboard viewer, the data of the first usable entry will be displayed. It is therefore necessary to store the most important data first in a CLP file. For example, you might store the same piece of text in both the TEXT and OEMTEXT formats. Windows would use the TEXT data, and other applications that use only the ASCII character set would use the OEMTEXT data. The same text data could also be stored as RTF and UNICODETEXT in the same CLP file.

Not every flavor of Windows is capable of supporting every Clipboard data format. For example, ENHMETAFILE is not supported by Windows 3.x and UNICODETEXT is presently only supported by Windows NT. If Windows cannot find data in a usable format on the Clipboard, it will attempt to convert a recognized data format to one considered more suitable. For example, TEXT or OEMTEXT data may be converted to UNICODETEXT; METAFILEPICT to ENHMETAFILE; BITMAP to DIB, and DIB to PALETTE. Unrecognized formats are ignored and not displayed by the viewers.

## File Details

The CLP header is four bytes in length and has the following format:

    typedef struct _ClpHeader
    {
        WORD FileId;        /* File identifier (always 3C50h) */
        WORD FormatCount;   /* Number of records in directory */
    } CLPHEADER;

FileId is used to identify a CLP file. This value is always 3C50h.

FormatCount is the number of record entries in the format directory.

### Clipboard Records

Following the header is one or more records that indicate the type and location of data within the Clipboard file. The number of records is specified by the FormatCount field in the header. Each record may be from 11 to 89 bytes in length and has the following format:

    typedef struct _FormatRecord
    {
        WORD  FormatId;       /* Format Identifier */
        DWORD DataLength;     /* Number of bytes in the data */
        DWORD DataOffset;     /* Offset of the data in the file */
        BYTE  FormatName[];   /* Format name */
    } FORMATRECORD;

FormatId identifies the type of data indicated by this record. Valid values for this field are listed in the Format ID columns of Tables Microsoft Windows Clipboard-1 and Microsoft Windows Clipboard-2.

DataLength specifies the length of the data in bytes.

DataOffset indicates the offset of the data within the Clipboard file. The offset is always calculated from the beginning of the file.

FormatName is a plain-text string that describes the name of the format. This string will be "Text" for TEXT data, "Bitmap" for BITMAP data, and so forth. Private data types, such as "Rich Text Format", will also be described. This string may be up to 78 characters in length and is always terminated with a NULL (0x00).

The format of an entire Clipboard file can be defined as such:

    typedef struct _ClipboardFormat
    {
        CLPHEADER ClpHeader;
        FORMATRECORD ClpRecords[ClpHeader.FormatCount];
        BYTE Data[];
    } CLIPBOARDFORMAT;

### Clipboard Data

The CLP format supports a bewildering variety of data formats. Most of these formats are documented as separate file formats described elsewhere in this book. Following is a description of the format data types listed in Tables Microsoft Windows Clipboard-1 and Microsoft Windows Clipboard-2.

TEXT is one or more strings of 8-bit ANSI characters. Each string is terminated by a carriage return (0x0D) and a line feed (0x0A). A NULL (0x00) byte indicates the end of the TEXT data. The ANSI character set is the default character set used by Windows.

BITMAP is a Microsoft Device-Dependent Bitmap (DDB). Refer to the Microsoft Windows Bitmap format article for more information on the DDB format.

METAFILE is a standard Windows Metafile, but is preceded by an additional header used by the Clipboard. Refer to the Microsoft Windows Metafile format article for the format of the Clipboard Metafile.

SYLK is the Microsoft Symbolic Link data format used by Microsoft Excel, Chart, and Multiplan to store spreadsheet data. The SYLK data is stored as ASCII text with each line terminated with a carriage return and line feed. Refer to the Microsoft SYLK file format article for more information on the SYLK format.

DIF is the Software Arts Data Interchange Format used to store spreadsheet data. The DIF data is stored as ASCII text with each line terminated with a carriage return and line feed. Refer to the Lotus DIF file format article for more information on the DIF format.

TIFF is the Tag Image File Format created by Aldus, Hewlett-Packard, and others, and is now administered by Adobe Systems. Refer to the Tag Image File Format article for further information on TIFF.

OEMTEXT is one or more strings of 7-bit ASCII characters. Each string is terminated by a carriage return (0x0D) and a line feed (0x0A). A NULL (0x00) byte indicates the end of the OEMTEXT data. The ASCII character set is the default character set used by MS-DOS.

DIB is a Microsoft Device-Independent Bitmap (DIB). Refer to the Microsoft Windows Bitmap format article for more information on the DIB format.

PALETTE is a DIB color palette. Refer to the Microsoft Windows Bitmap format article for more information on the DIB color palettes.

RIFF is the Microsoft Resource Interchange File Format. This is Microsoft's "store anything" multimedia file format. Refer to the Microsoft RIFF article for more information.

WAVE is the Microsoft Waveform audio file format (.wav files). A wave file is nothing more than a RIFF file that stores only digital audio data.

UNICODETEXT is one or more strings of 16-bit Unicode characters. Each string is terminated by a carriage return (0x000D) and a line feed (0x000A). A NULL (0x0000) byte indicates the end of the UNICODETEXT data. The Unicode character set is the default character set used by Windows NT and Win32.

ENHMETAFILE is an Enhanced Windows Metafile found on Win32 systems. Refer to the Microsoft Windows Metafile format article for the format of the Enhanced Metafile.

OWNERDISPLAY is private data that is not recognized by the Clipboard, and is therefore not displayed by the Clipboard Viewer. The FormatName field of this data's record should yield a clue as to the format of the data.

DSPTEXT is a collection of private text. This data is stored using the same format as the TEXT format, and will be displayed as text, but is not available via the TEXT format ID.

DSPBITMAP is a collection of private text. This data is stored using the same format as the BITMAP format, and will be displayed as text, but is not retrievable using the BITMAP format ID.

DSPMETAFILEPICT is a collection of private text. This data is stored using the same format as the METAFILEPICT format, and will be displayed as text, but is not retrievable using the METAFILEPICT format ID.

DSPENHMETAFILE is a collection of private text. This data is stored using the same format as the ENHMETAFILE format, and will be displayed as text, but is not retrievable using the ENHMETAFILE format ID.

GDIOBJFIRST and GDIOBJLAST are a range of reserved values use to register private GDI objects. GDI objects include brushes, pens, palettes, and fonts. Under Windows the object is created first in memory and then saved to the Clipboard using the SetClipboardData() functions call. The handle of the GDI object and a value in the range of GDIOBJFIRST and GDIOBJLAST (inclusive) are passed to the function.

PRIVATEFIRST and PRIVATELAST are a range of reserved values used to register private data formats. There is no official registration of private data format numbers, so your reader application needs to both recognize this value and the FormatName string to properly identify the private data.

For example, let's say you want to import a 32K IFF file into your application through the Clipboard. You might construct a CLP file with a single record and containing the IFF file data:

    typedef struct _PrivateIffFormat
    {
        WORD  FileId;           /* 0x3C50 */
        WORD  FormatCount;      /* 0x0001 */
        WORD  FormatId;         /* 0x0200 */
        DWORD DataLength;       /* 0x00007FFF */
        DWORD DataOffset;       /* 0x00000026 */
        BYTE  FormatName[];     /* "Interchange File Format\0" */
        BYTE  Data[];           /* The entire IFF file */
    } PRIVATEIFFFORMAT;

In this example we see a CLP file that contains a single record describing a private format with an ID value of 0x200. The data is 32K in size and begins 39 bytes into the file. Once this file has been read into the Clipboard the IFF file data may be read and parsed by any application that can access the Clipboard.

## For Further Information

There is no official CLP file format specification. The Clipboard File Format and Clipboard management functions are described in detail in:

> Microsoft Windows Programmer's Reference, Volumes 2 and 4, Microsoft Press, Redmond, WA, 1990.

The Microsoft Developers Network (MSDN) distributes several files containing information on the CLP format. These files may be found on the MSDN CD, or on the Microsoft Web site at:

> http://www.microsoft.com/developr/MSDN/

Copyright © 1996, 1994 O'Reilly & Associates, Inc. All Rights Reserved.