Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 453
Shaun Wild Avatar asked May 20 '16 07:05

Shaun Wild


People also ask

What is my Windows clipboard?

What is the Windows clipboard? The latest clipboard, designed for Windows 10, is cloud-based. Its main feature is the ability to copy up to 25 pieces of text or images for later use. You can access these items on the same PC or a different one, so you can paste those same items into another application or program.

What does it mean when it says copied to clipboard?

Android can cut, copy and paste text, and like a computer, the operating system transfers the data to the clipboard. Unless you use an app or extension like Clipper or aNdClip to retain your clipboard history, however, once you copy new data to the clipboard, the old information is lost.


2 Answers

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.

like image 131
Yakov Galka Avatar answered Dec 10 '22 01:12

Yakov Galka


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.

like image 27
Ic3fr0g Avatar answered Dec 10 '22 02:12

Ic3fr0g