|
Imports System.Windows.Forms
Public Class Form1
Private Const WM_DRAWCLIPBOARD As Integer = &H308
Private Const WM_CHANGECBCHAIN As Integer = &H30D
Private mNextClipBoardViewerHWnd As IntPtr
Declare Auto Function SetClipboardViewer Lib "user32" (ByVal HWnd As IntPtr) As IntPtr
Declare Auto Function ChangeClipboardChain Lib "user32" (ByVal HWnd As IntPtr, ByVal HWndNext As IntPtr) As Boolean
Declare Auto Function SendMessage Lib "User32" (ByVal HWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Long
Public Sub NewViewer()
mNextClipBoardViewerHWnd = SetClipboardViewer(Me.Handle)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case Is = WM_DRAWCLIPBOARD 'The clipboard has changed...
SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam, m.LParam)
If Clipboard.ContainsText = True Then
TextBox1.Text = Clipboard.GetText
End If
If Clipboard.ContainsImage() = True Then
PictureBox1.Image = Clipboard.GetImage()
PictureBox1.Update()
End If
Case Is = 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
Private Sub clipboardMon_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
NewViewer()
End Sub
End Class
|
|