ZooFlow: Add Clipboard Watcher Class

This commit is contained in:
Jonathan Jenne 2021-01-14 13:24:23 +01:00
parent 845237963a
commit 8a934eb581
4 changed files with 105 additions and 12 deletions

View File

@ -1,6 +1,17 @@
Imports System.Runtime.InteropServices Imports System.Runtime.InteropServices
Public Class ClassWin32 Public Class ClassWin32
Public Const ULW_COLORKEY As Int32 = &H1
Public Const ULW_ALPHA As Int32 = &H2
Public Const ULW_OPAQUE As Int32 = &H4
Public Const AC_SRC_OVER As Byte = &H0
Public Const AC_SRC_ALPHA As Byte = &H1
Public Const WM_NCLBUTTONDOWN As Integer = &HA1
Public Const HTCAPTION As Integer = &H2
Public Const WM_DRAWCLIPBOARD As Integer = &H308
Public Enum Bool Public Enum Bool
[False] = 0 [False] = 0
[True] [True]
@ -44,40 +55,51 @@ Public Class ClassWin32
Public AlphaFormat As Byte Public AlphaFormat As Byte
End Structure End Structure
Public Const ULW_COLORKEY As Int32 = &H1
Public Const ULW_ALPHA As Int32 = &H2
Public Const ULW_OPAQUE As Int32 = &H4
Public Const AC_SRC_OVER As Byte = &H0
Public Const AC_SRC_ALPHA As Byte = &H1
Public Const WM_NCLBUTTONDOWN As Integer = &HA1
Public Const HTCAPTION As Integer = &H2
<DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)> <DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function UpdateLayeredWindow(ByVal hwnd As IntPtr, ByVal hdcDst As IntPtr, ByRef pptDst As Point, ByRef psize As Size, ByVal hdcSrc As IntPtr, ByRef pprSrc As Point, ByVal crKey As Int32, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Int32) As Bool Public Shared Function UpdateLayeredWindow(ByVal hwnd As IntPtr, ByVal hdcDst As IntPtr, ByRef pptDst As Point, ByRef psize As Size, ByVal hdcSrc As IntPtr, ByRef pprSrc As Point, ByVal crKey As Int32, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Int32) As Bool
End Function End Function
<DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)> <DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function GetDC(ByVal hWnd As IntPtr) As IntPtr Public Shared Function GetDC(ByVal hWnd As IntPtr) As IntPtr
End Function End Function
<DllImport("user32.dll", ExactSpelling:=True)> <DllImport("user32.dll", ExactSpelling:=True)>
Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
End Function End Function
<DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)> <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function CreateCompatibleDC(ByVal hDC As IntPtr) As IntPtr Public Shared Function CreateCompatibleDC(ByVal hDC As IntPtr) As IntPtr
End Function End Function
<DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)> <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function DeleteDC(ByVal hdc As IntPtr) As Bool Public Shared Function DeleteDC(ByVal hdc As IntPtr) As Bool
End Function End Function
<DllImport("gdi32.dll", ExactSpelling:=True)> <DllImport("gdi32.dll", ExactSpelling:=True)>
Public Shared Function SelectObject(ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr Public Shared Function SelectObject(ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr
End Function End Function
<DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)> <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Bool Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Bool
End Function End Function
<DllImport("User32.dll")> <DllImport("User32.dll")>
Public Shared Function ReleaseCapture() As Boolean Public Shared Function ReleaseCapture() As Boolean
End Function End Function
<DllImport("User32.dll")> <DllImport("User32.dll")>
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function End Function
<DllImport("user32", EntryPoint:="AddClipboardFormatListener")>
Public Shared Function AddClipboardFormatListener(ByVal hWnd As IntPtr) As Boolean
End Function
<DllImport("user32", EntryPoint:="RemoveClipboardFormatListener")>
Public Shared Function RemoveClipboardFormatListener(ByVal hWnd As IntPtr) As Boolean
End Function
<DllImport("user32", EntryPoint:="SetClipboardViewer")>
Public Shared Function SetClipboardViewer(ByVal hWnd As IntPtr) As IntPtr
End Function
End Class End Class

View File

@ -0,0 +1,64 @@
Imports System.Runtime.InteropServices
Namespace ClipboardWatcher
Public Class Watcher
Inherits NativeWindow
Implements IDisposable
Public Event ClipboardChanged As EventHandler(Of IDataObject)
Public Shared Singleton As New Watcher
Private _Handle As IntPtr
Private Sub New()
MyBase.CreateHandle(New CreateParams)
_Handle = ClassWin32.SetClipboardViewer(Handle)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case ClassWin32.WM_DRAWCLIPBOARD
Dim oData As IDataObject = Clipboard.GetDataObject
RaiseEvent ClipboardChanged(Me, oData)
End Select
MyBase.WndProc(m)
End Sub
#Region "IDisposable Support"
' Für diese Klasse ist korrekte Ressourcenbereinigung besonders wichtig, da
' mit systemübergreifenden Ressourcen gearbeitet wird
' So ermitteln Sie überflüssige Aufrufe
Private _DisposedValue As Boolean = False
Protected Overridable Sub Dispose(ByVal pDisposing As Boolean)
If Not _DisposedValue Then
If pDisposing Then
' TODO: Verwaltete Ressourcen freigeben, wenn sie explizit
' aufgerufen werden
End If
MyBase.DestroyHandle()
Dim H As IntPtr = ClassWin32.SetClipboardViewer(_Handle)
End If
_DisposedValue = True
End Sub
' Dieser Code wird von Visual Basic hinzugefügt, um das Dispose-Muster
' richtig zu implementieren.
Public Sub Dispose() Implements IDisposable.Dispose
' Sie sollten diesen Code nicht ändern, sondern stattdessen ihren
' Bereinigungscode oben in
' Dispose(ByVal disposing As Boolean) einfügen.
Dispose(True)
System.GC.SuppressFinalize(Me)
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
Dispose(False)
End Sub
#End Region
End Class
End Namespace

View File

@ -112,7 +112,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="ApplicationEvents.vb" /> <Compile Include="ApplicationEvents.vb" />
<Compile Include="Base\BaseClass.vb" /> <Compile Include="Base\BaseClass.vb" />
<Compile Include="ClassClipboardWatcher.vb" /> <Compile Include="ClipboardWatcher\Watcher.vb" />
<Compile Include="ClassCommandlineArgs.vb" /> <Compile Include="ClassCommandlineArgs.vb" />
<Compile Include="Search\frmFlowSearch.Designer.vb"> <Compile Include="Search\frmFlowSearch.Designer.vb">
<DependentUpon>frmFlowSearch.vb</DependentUpon> <DependentUpon>frmFlowSearch.vb</DependentUpon>

View File

@ -33,7 +33,7 @@ Public Class frmFlowForm
' Events ' Events
Public Event ClipboardChanged As EventHandler(Of IDataObject) Public Event ClipboardChanged As EventHandler(Of IDataObject)
Private WithEvents Watcher As ClassClipboardWatcher = ClassClipboardWatcher.Singleton Private WithEvents Watcher As ClipboardWatcher.Watcher = ClipboardWatcher.Watcher.Singleton
Public Sub New() Public Sub New()
' Dieser Aufruf ist für den Designer erforderlich. ' Dieser Aufruf ist für den Designer erforderlich.
@ -89,6 +89,7 @@ Public Class frmFlowForm
' === Register As Event Listener === ' === Register As Event Listener ===
EventBus.Instance.Register(Me) EventBus.Instance.Register(Me)
' === Set Form Properties === ' === Set Form Properties ===
TopMost = True TopMost = True
AllowDrop = True AllowDrop = True
@ -105,6 +106,9 @@ Public Class frmFlowForm
AddHandler oControl.MouseLeave, AddressOf frmFlowForm_MouseLeave AddHandler oControl.MouseLeave, AddressOf frmFlowForm_MouseLeave
Next Next
AddHandler Watcher.ClipboardChanged, AddressOf Watcher_ClipboardChanged
' TODO: Clean up ' TODO: Clean up
Dim oSQL = My.Queries.Common.FNIDB_GET_SEARCH_PROFILES(My.Application.User.UserId, My.Application.User.Language) Dim oSQL = My.Queries.Common.FNIDB_GET_SEARCH_PROFILES(My.Application.User.UserId, My.Application.User.Language)
Dim oDatatable As DataTable = My.DatabaseIDB.GetDatatable(oSQL) Dim oDatatable As DataTable = My.DatabaseIDB.GetDatatable(oSQL)
@ -115,7 +119,7 @@ Public Class frmFlowForm
DTIDB_SEARCHES = oDatatable DTIDB_SEARCHES = oDatatable
PictureBoxSearch.Visible = True PictureBoxSearch.Visible = True
End If End If
If My.Application.ModulesActive.Contains(ClassConstants.MODULE_GLOBAL_INDEXER) Then If My.Application.ModulesActive.Contains(MODULE_GLOBAL_INDEXER) Then
FileDrop = New ClassFileDrop(My.LogConfig) FileDrop = New ClassFileDrop(My.LogConfig)
FileHandle = New ClassFilehandle(My.LogConfig) FileHandle = New ClassFilehandle(My.LogConfig)
Refresh_RegexTable() Refresh_RegexTable()
@ -124,6 +128,9 @@ Public Class frmFlowForm
Me.Cursor = Cursors.Default Me.Cursor = Cursors.Default
End Sub End Sub
Private Sub Watcher_ClipboardChanged(sender As Object, e As IDataObject)
Throw New NotImplementedException()
End Sub
Private Sub TimerRefreshData_Tick(sender As Object, e As EventArgs) Private Sub TimerRefreshData_Tick(sender As Object, e As EventArgs)
'TODO: Refresh Data 'TODO: Refresh Data