Vb. NET implementation of the Windows Clipboard Monitor

Source: Internet
Author: User

Windows clipboard

The Clipboard (ClipBoard) is an area in memory that is a very useful tool built into Windows, with a small clipboard that allows you to transfer and share information between applications by building a color bridge. However, the drawback is that the Clipboard can only keep one copy of the data, whenever new data is passed in, the old will be overwritten.

Related Windows APIs

The main thing is setclipboardviewer, whenever the contents of the Clipboard change, the function uses the Wm_drawclipboard message to add the window to the window chain being notified.
Because the handle to the next window in the Clipboard viewer chain has not been returned, the application should not pass it on SetClipboardViewer
The Wm_drawclipboard message received during the call.
If you want to remove the window chain from the Clipboard Viewer chain, the application must call the Changeclipboard member function.

Declare auto function setclipboardviewer Lib "user32" (ByVal HWnd as INTPTR) as Intptrdeclare Auto function Changeclipboar Dchain Lib "user32" (ByVal HWnd as INTPTR, ByVal Hwndnext as IntPtr) as Booleandeclare Auto Function SendMessage Lib "User (ByVal HWnd as INTPTR, ByVal Msg as Integer, ByVal WParam as INTPTR, ByVal LParam as INTPTR) as Long
WndProc function

The operating system sends a series of messages to the application, such as the left button press and the button lift, and the application will eventually submit the message to the window procedure (wndproc[full name, Windows process]) to a pointer to an application-defined window procedure, such as GetMessage.

We need to override this function to handle clipboard content change events:

    ' Override WndProc to get messages ... Protected Overrides Sub WndProc (ByRef m as Message) Select case m.msg case is = Wm_drawclipboard ' the CL                Ipboard has changed ... ' ########################################################################## ' Process Clipboard here:) ....                .................... ' ########################################################################## SendMessage (mnextclipboardviewe                    Rhwnd, M.msg, M.wparam, m.LParam) ' Displays the text information in the Clipboard If clipboard.containstext () = True Then Label1.Text = Clipboard.gettext () End if ' Displays the picture information in the Clipboard if CLIPBO Ard. ContainsImage () = True then pictureBox1.Image = Clipboard.getimage () picturebox1.upd                Ate () End If case was = Wm_changecbchain ' Another clipboard viewer has removed itself ... If M.wparam = CTyPE (MNEXTCLIPBOARDVIEWERHWND, IntPtr) then Mnextclipboardviewerhwnd = m.LParam Else        SendMessage (Mnextclipboardviewerhwnd, m.msg, M.wparam, m.LParam) End If End Select Mybase.wndproc (m) End Sub

Effect:


SOURCE Download: vb.net implement Windows Clipboard Monitor

Vb. NET implementation of the Windows Clipboard Monitor

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.