Shaun Wild
Shaun Wild

Reputation: 1243

In Windows, what actually is the clipboard?

This may sound like a silly question, but what actually is the clipboard?

My curiosity spiked after I noticed that the clipboard is used in more complex ways than I first thought possible. I thought the clipboard basically kept track of either a string of text, an image or a file and then simply would paste whatever if it had into the wherever the user specified if the context matched.

However, with word processing software like Microsoft Word I've noticed that you can copy and paste styles straight from websites and that on programs like Skype you can copy quotes that appear to be normal text in a Notepad document, but are actually formatted notes in Skype's UI.

I looked at the source code for a fake Skype quote generator, and it appears that there are multiple clipboards. Or is the clipboard laid out in a key-value type map?

Upvotes: 5

Views: 599

Answers (2)

Ic3fr0g
Ic3fr0g

Reputation: 1219

To add to @ybungalobill answer, read the rest of the information that is available at the Windows Dev Center here. A quick excerpt of the CUT/COPY operations is -

To place information on the clipboard, a window first clears any previous clipboard content by using the EmptyClipboard function. This function sends the WM_DESTROYCLIPBOARD message to the previous clipboard owner, frees resources associated with data on the clipboard, and assigns clipboard ownership to the window that has the clipboard open. To find out which window owns the clipboard, call the GetClipboardOwner function.

After emptying the clipboard, the window places data on the clipboard in as many clipboard formats as possible, ordered from the most descriptive clipboard format to the least descriptive. For each format, the window calls the SetClipboardData function, specifying the format identifier and a global memory handle. The memory handle can be NULL, indicating that the window renders the data on request. For more information, see Delayed Rendering.

You can follow up on the function definitions in the API reference if you so choose.But SetClipboardData is the function where magic happens.

Upvotes: 2

Yakov Galka
Yakov Galka

Reputation: 72529

There are multiple clipboard data formats and when you SetClipboardData you specify which format the data is. You can set multiple clipboard formats simultaneously because the clipboard is cleared explicitly with EmptyClipboard, You can also register your own custom formats to be used between your applications.

The other side opens the clipboard, looks which formats there currently are, chooses the most appropriate one, and proceeds accordingly.

Upvotes: 3

Related Questions