Joining a clipboard chain

In addition to my custom-format clipboard post, I am considering writing my own clip monitoring component.

Prior to approval:

ClipboardWindow:=SetClipboardViewer(Form1.Handle); 

I saw in the sample code I studied the following snippet:

 OpenClipboard(Form1.Handle); EmptyClipboard; CloseClipboard; 

while others do not contain a cleanup code at all. I am embarrassed.

I believe that Clipbrd.TClipboard.Clear just does the same with VCL.

My question is :

When is it necessary to clear the clipboard before attaching to the clipboard chain ?

+3
source share
2 answers

No, there is no need to clear the clipboard. In fact, you should not. Other clipboard monitors will uselessly respond to the update, and the user may want to paste this thing that you just destroyed. In addition, monitoring buffer chains is much more than just adding yourself to the chain. You must pass events to the next window (the result descriptor from SetClipboardViewer), and you must, without fail, remove yourself from the chain when your application exits. In addition, you need to avoid blocking the clipboard unnecessarily. Typically, this means waiting for the clipboard to register events until you are ready to actually process the events. For example, do not do this first at startup if you subsequently open a dialog box asking the user where he wants to store data, if he has a license key, etc.

I have tips as well as general traps here: http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows/6

+3
source
  • The rule is as simple as possible: if you want to delete the contents of the clipboard (so that other applications cannot use it), delete it. if not, save it.

  • You don’t know if your use wants to save data OR Do you want to implement something fantastic? Do you know these applications (Paint Shop Pro - one of them) that ask: "You left a large image (10 MB of data) in the clipboard. Do you want to save or clear it?" You could do something like this. :)

0
source

Source: https://habr.com/ru/post/1390502/


All Articles