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