Jul 12th, 2007 by Chris Thornton
Copyright 1999-2003 Thornsoft Development, Inc.
There are times when it is necessary or desirable to inform clipboard viewers (any application that is monitoring clipboard updates) that you do NOT want it to capture the clipboard update. Such a time is when ClipMate’s PowerPaste function is active, and ClipMate wants to tell other applications to ignore the new data arriving on the clipboard. Since this requires cooperation between ClipMate and the other clipboard viewers, we decided to establish a standardized way of handling the interaction. It can be used in reverse – to tell ClipMate not to capture data, as well. This method is being provided in an attempt to make all programs work better together, even competitors.
When a clipboard update occurs, all clipboard viewers are notified via the WM_DrawClipboard message. Upon receiving the message, look for the presence of the CF_CLIPBOARD_VIEWER_IGNORE data format. If it is present – do not grab the data. Do not even open the clipboard (you can check without opening it). Simply pass the message down the chain as you normally would. If it is appropriate to change the state of your program to indicate “update ignored”, do so. (In ClipMate, we have a special kind of beep, and we gray out the area where we show the current clipboard contents.)
If you are on the other end, and need other clipboard viewers to ignore YOUR update, then simply add a CF_CLIPBOARD_VIEWER_IGNORE data format to the clipboard, right along with the other data type(s). For example, if you normally placed CF_TEXT and CF_Bitmap on the clipboard, you’d also have CF_CLIPBOARD_VIEWER_IGNORE. The data itself should contain a short string identifying your app.
Format Name: “Clipboard Viewer Ignore”
Clipboard Format Type: Private (must be registered by your program at startup)
Contains: NULL Data. Optinally, you can include text string up to 80 bytes, identifying originating program. Zero terminated. But since nothing should ever look at it, you should be able to leave it null.
During start-up, register the CF_CLIPBOARD_VIEWER_IGNORE format, so that you can use it later on during clipboard calls. The spelling of the name is important. Since don’t all work from a common header file, we all need to call it the same thing: “Clipboard Viewer Ignore”
In Delphi, it looks like this:
CF_CLIPBOARD_VIEWER_IGNORE := RegisterClipboardFormat(‘Clipboard Viewer Ignore’);
When you receive a clipboard update via the WM_DrawClipboard message, see if the Clipboard Viewer Ignore format is present on the clipboard. If it is, don’t paste it.
/* Without opening the clipboard, see if the ignore format is present*/
/* Don’t paste it */
/* Paste it, and process normally */
/* Now send the message along to the next viewer, as you always do. */
If, on the other hand, you need to tell other clipboard viewers to ignore YOUR data (such as if you don’t want data going into ClipMate), then you need to put the CF_CLIPBOARD_VIEWER_IGNORE data format on the clipboard, along with your regular data. Be sure to do this in the SAME open/clear/update/close operation.
Delphi example using WinAPI
IF OpenClipboard(hWindow) THEN
/* Copy the ignore format, plus any of your own */
/* Here is yours – allocate as usual */
/* And any more formats that you have…. */
There is a demo application called the Clipboard Viewer / Ignore Demo, which handles both sides of this situation. It can send text to the clipboard, both with and without the CF_CLIPBOARD_VIEWER_IGNORE format, so that you can test your apps. It also is a Viewer, which implements the “ignoring”, so that you can see the behavior. It logs clipboard messages as well, so that you can troubleshoot certain situations, such as when applications send multiple updates in a row. Finally, it’s a darn good example of a clipboard viewer, so you can base clipboard viewer designs from it. There is a complete Delphi4 project, and the main program – IgnoreDemoForm.PAS is suitable as pseudo-code for VB and C++ programmers. And there is a compiled executable, if you just want to play. Get the demo here: http://www.thornsoft.com/dist/techsupport/ignoredemo.zip
The demo app has two sections on the form – the top half is for sending the ignore format, plus some text, to the clipboard. The bottom half is a clipboard viewer, so that you can see how to properly deal with the ignore format. You can, of course, send data from the top portion, to the clipboard, and then see the result in the bottom portion.
DEMO – Clipboard Monitoring
To use as an example of a viewer, just click the Monitor Clipboard button, and it starts monitoring. By default, it uses the “ignore” format, but you can de-select that option. While it monitors, all events are logged, even if they’re “ignored”. There is a handy counter, showing the number of events received while monitoring. If you see it go up by more than 1 for each copy, then some application is double-copying, or doing the clear and updates in different steps. That’s BAD – you should always do it like this: open/clear/update/close. Multiple open..close sequences send multiple updates.
DEMO – Sending Data With The IGNORE Instruction
In the top half of the demo, you can enter some text, press the COPY button, and it goes to the clipboard. If you have the “ignore” option checked, it’ll send the CF_CLIPBOARD_VIEWER_IGNORE format along with the CF_TEXT. Otherwise, it won’t. If you have monitoring enabled in the bottom half, you can see the results.
- Microsoft Platform SDK – Base Services | Interprocess Communication | Clipboard | Clipboard References | Clipboard Messages
- Microsoft Platform SDK – Base Services | Interprocess Communication | Clipboard | Using The Clipboard | Creating A Clipboard Viewer Window
The above two topics, while available in the MSDN, are currently online at:
In case they’ve moved it, do a search on: “Clipboard Viewer Windows”
Just use it. We don’t want to get paid, or restrict anyone from using it. But please document the original source of this information as http://www.thornsoft.com/developer.htm
If Microsoft wants to incorporate this into the grand scheme of things, all the better.