A simple windows clipboard Monitoring Program

Source: Internet
Author: User
Introduction

This is a simple winform component and winformProgramIt can monitor users' operations on the Windows clipboard in real time. When a user copies/cut, it automatically records the content copied/cut by the user. This program is completed using components, so you can easily use the clipboard monitoring component in your own program. Of course, the current component is very small and very simple, and its functions are not complete yet.

Use Win32 API

We use the Windows API to register our program, so that the operating system will notify the program when the user copies/cut. You need to use the following functions:

· Setclipboardviewer ()-adds a window to the Windows clipboard listener chain. In this way, Windows will send a wm_drawclipboard message to our window during user intelligence/cutting. In addition, when other programs Add/exit the listener linked list, Windows will send a wm_changecbchain message to our window. Note: When your window receives the two messages, you should use the sendmessage function to send the message to the next Listener.

· Changeconboardchain ()-enables a window to exit the Windows clipboard listener chain. Note that our program must call the changeconboardchain function to exit the listener linked list.

· Sendmessage ()-send messages to other windows to facilitate the transmission of messages in the Windows clipboard listener linked list.

Override the wndproc Method

Rewrite your wndproc method to receive Windows messages. When receiving the wm_drawclipboard message, you must first send the message to the next Listener. Then we can process our own program. Here we only trigger a simple event and hand over the event to a higher layer for processing. When receiving the wm_changecbchain, you need to change the listener linked list. Remember to send the message to the next Listener.

  Protected     Override     Void  Wndproc (  Ref  Message m)
{
Switch (MSGs) M. msg)
{
Case Msgs. wm_drawclipboard:
If (M_onwork)
{
Win32.sendmessage (clipboardviewernext, M. MSG, M. wparam, M. lparam );

If (Clipboarddrawn ! =   Null )
Clipboarddrawn ( This , New Clipboarddrawneventargs ( " Good " ));
}
Break ;

Case Msgs. wm_changecbchain:
If (M. wparam = Clipboardviewernext)
{
Clipboardviewernext = M. lparam;
}
Else
{
Win32.sendmessage (clipboardviewernext, M. MSG, M. wparam, M. lparam );
}
Break ;

Default :
Break ;
}
Base . Wndproc ( Ref M );
}
Use Components

In order to make the customer program more simple to use ourCode, We make our code into a component. Create a new component integrated from component in Visual Studio and add code. When other programs use our class library, developers simply need to drag our component on the designer, then, you can use the simple settings in the attribute box.

Note: There is a problem here. Windows messages can only be received by Windows (here the window is not a form), including system. Windows. Forms. Control and classes integrated with self-control, such as form. However, component is not in this range, so component cannot receive Windows messages strictly. So here I use a small method to write all the code in a custom control class, and then simply wrap a layer with component.

There are also some custom delegate, event, and event parameters used to make our components generate events.

Other problems

This program referencesClipspy +, this program is well written, but it does not seem very easy to use code.

Attachment

Demo program/files/flankerfc/200801003/clipmanager_bin.zip
Source code/Files/flankerfc/200801003/clipmanager_src.zip

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.