Real-time monitoring clipboard function for network ants

zhaozj2021-02-16  47

Real-time monitoring of clipboard functionality for network ants: Heilongjiang Province Wudalianchi Maming Chen We know that ants can monitor the network in real time to the clipboard, if we can achieve this functionality in your own programs, certainly considerably to our program. What is it realized? The easiest way we can think of is to open a timer directly, check the content on the clipboard, or check it. Both methods can monitor clipboards, but unfortunate is that the real-time performance is too bad, and it takes up a large number of resources for the system. It is very different. A better way can use the Win32API to the clipboard hook (hook) function, as long as the clipboard's hook function is installed, you can monitor the clipboard in real time, because any clipboard changes a message, and hook The function intercepted this information. However, this requires that the current program must have a chance to obtain CPU control to handle this message. If the program does not release the CPU, the program is monitored the clipboard and cannot handle the message. Only when the program is completed, other programs can get a process opportunity, but at this time, the clipboard only has the last paste content. Moreover, using the hook function is very dangerous, once your program has a problem, the entire system will follow. Since these methods are not ideal, then we may wish to convert thinking, no longer depends on clipboard, and think about how to let the clipboard send a message directly to our program, so it will definitely do 100% real-time. To this end, I carefully view the programming information of various Windows, the result is: because the clipboard does not have their own handle (Handle), it is not a class of Windows, so the clipboard will not send a message. But how can the system receive commands such as clipping / copy to a clipboard? That is, how is the message such as WM_COPY and WM_CUT, WM_PASTE? After study, it is possible to send a message to the clipboard viewer. The original multiple clipboard viewer is sequentially connected to the clipboard to view the chain. Therefore, to implement a real-time monitoring clipboard, you must register your own program into a clipboard viewer (ie, add the linked list). The author is programmed with C Builder 5.0 as an example to explain its specific implementation process. First create a new project, add a MEMO control on Form1, then add #include in Form1. Because the API function to be used below is defined in this header file. In the public Form1 .h plus: BEGIN_MESSAGE_MAPMESSAGE_HANDLER (WM_DRAWCLIPBOARD, TMessage, ClipboardChanged) // This message is mapped END_MESSAGE_MAP (TForm) HWND LastHandle; // save the clipboard viewer chain for the next window handle. Next, of course, register your own program window as a clipboard viewer. Add a sentence in the oncreate event of Form1: LastHandle = setClipboardViewer (Form1-> Handle); This function adds the specified window to the clipboard viewer chain, the parameter handle is the handle of the window you want to join, the return value is system The handle of the clipboard view in the next window. When your own program exits, you must delete this window from the clipboard viewer chain.

转载请注明原文地址:https://www.9cbs.com/read-27697.html

New Post(0)