22. Windows API Process Communication and clipboard (Clipboard)

Source: Internet
Author: User

The clipboard is defined by the system and does not belong to any specific process. All processes in the system can access and set the clipboard. Compilation of many texts with the "copy" and "Paste" FunctionsProgramAll operations are performed through the clipboard.

The biggest feature of the clipboard is that there is no clear target for data transmission and data is passively accessed. The program that sets the clipboard does not know when the set data is accessed, you do not know which process you want to access. The content in the clipboard can also be accessed multiple times until new data is written. Therefore, using the clipboard is also an alternative way of inter-process communication. However, since any process in the system can access the Clipboard without restrictions, the clipboard is also an unreliable communication method.

Refer to [1, 2] to introduce basic operations on the clipboard, including setting data in the clipboard, obtaining data from the clipboard, and monitoring how to modify the clipboard, this mechanism allows programs to detect data changes in the clipboard in a timely manner. Using the clipboard to transmit data can be real-time, as well as the formats of data in the clipboard and custom data formats.

Clipboard [3].

1. Monitor the clipboard

Principle:

(1) wm_drawclipboa

The system provides the wm_drawclipboard message to monitor clipboard changes. If you call

The setclipboardviewer function sets the window as the clipboard viewer. When the content in the clipboard changes, the registered Viewer window will receive the wm_changecbchain message and wm_drawclipboard message.

When the content in the clipboard changes, the window will receive the WM drawclipboard message. When a new node of the viewer chain is added or a node exits, the message wm_changecbchain is received.

(2) setclipboardviewer Function

2. Clipboard data format

Various types of data may exist in the clipboard. Therefore, when saving data in the clipboard, you also need to save the data format information.

The system uses a uint type of data to represent the data format in the clipboard. Many of these formats are common among various applications, such as text and bitmap. These data formats have been pre-defined by the system, known as standard formats.

Some applications also want to customize the data format of the clipboard, in this way, you can easily transfer data between different instances of the same application without having to process the data format too much (typically word ).

Reference

[1] proficient in Windows API functions, interfaces, and programming instances

[2]Http://www.cnblogs.com/mydomain/archive/2010/09/04/1818257.html

[3]Http://msdn.microsoft.com/en-us/library/ms649012%28VS.85%29.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.