mardi 25 mars 2014

What really happens when you press Ctrl+C? Clipboard Format Spy has the answers

In theory, the Windows clipboard seems very simple. Select something, press Ctrl+C and it’s copied there; click somewhere else, press Ctrl+V and it’s pasted. Easy.


Then again, sometimes you’ll try to paste something and find the formatting is messed up, or you just don’t get what you expected. What’s happening? The free Clipboard Format Spy may be able to help.


The program provides a real-time view of the contents of your clipboard. To see how this works, highlight some text in Notepad, and press Ctrl+C. Clipboard Format Spy updates immediately to show any changes.


What you’ll notice immediately is there’s not just a single object. Your clipboard now contains a "text" object, some "OEM" text (usually the same), a Unicode version, and a Locale object which describes your text language. Double-clicking any of these displays their contents.


Now open Internet Explorer, visit a web page, then copy a mix of text and graphics to the clipboard. You still get plain and Unicode text copies, but this time there are Rich Text Format and HTML versions, with embedded graphics. An "msSourceUrl" gives you the address of the copied page, and again you can view any of these by double-clicking, or by choosing a specific option from the right-click menu ("View as binary", "View as text", and so on).


Why so many objects? When a program copies something to the clipboard, it doesn’t know whether you’ll need plain text, Unicode, simple formatting, graphics or anything else. Typically it’ll save multiple versions of the same object, and when you paste the data somewhere, the receiving application will choose whatever it thinks is best.


This isn’t always a great idea. If you’ve a copy of Google Earth installed, launch it, browse somewhere and click Edit > Copy Image. You might expect the program to copy a single image to the clipboard, but in fact there are nine: two DIBs (device-independent bitmaps), and seven others in various formats (JPG, PNG, BMP, PPM, XBM, JPEG and XPM). If a program does this with very high-res images then it could chew up a lot of RAM.


It’s a similar story with some other graphics tools. Open your preferred image editor, copy something to the clipboard and see what actually gets stored (it’s usually more than you’d expect).


Viewing this doesn’t have any great practical benefit. Clipboard Format Spy is mostly a programming demo showing how the clipboard can be monitored, so doesn’t have the extras you’d expect from an end-user tool. The main screen is text-only, for example (you only see graphics if you open them manually), and it can’t save a selected object to disk.


If you’d like an easy way to see how the clipboard is really being used, though -- or want to troubleshoot some odd clipboard issue -- then Clipboard Format Spy should work very well. Go take a look.






Aucun commentaire:

Enregistrer un commentaire