ZooFlow: Remove ClassWin32, replace with Modules.Windows

This commit is contained in:
Jonathan Jenne 2021-10-26 11:29:11 +02:00
parent 2b6e06c3fa
commit 0197835eee
5 changed files with 42 additions and 126 deletions

View File

@ -1,116 +0,0 @@
Imports System.Runtime.InteropServices
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
[False] = 0
[True]
End Enum
<StructLayout(LayoutKind.Sequential)>
Public Structure WINDOWPOS
Public hwnd As IntPtr
Public hwndInsertAfter As IntPtr
Public x As Integer
Public y As Integer
Public cx As Integer
Public cy As Integer
Public flags As Integer
End Structure
<StructLayout(LayoutKind.Sequential)>
Public Structure Point
Public x As Int32
Public y As Int32
Public Sub New(ByVal x As Int32, ByVal y As Int32)
Me.x = x
Me.y = y
End Sub
End Structure
<StructLayout(LayoutKind.Sequential)>
Public Structure Size
Public cx As Int32
Public cy As Int32
Public Sub New(ByVal cx As Int32, ByVal cy As Int32)
Me.cx = cx
Me.cy = cy
End Sub
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1)>
Structure ARGB
Public Blue As Byte
Public Green As Byte
Public Red As Byte
Public Alpha As Byte
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1)>
Public Structure BLENDFUNCTION
Public BlendOp As Byte
Public BlendFlags As Byte
Public SourceConstantAlpha As Byte
Public AlphaFormat As Byte
End Structure
<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
End Function
<DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function GetDC(ByVal hWnd As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", ExactSpelling:=True)>
Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
End Function
<DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function CreateCompatibleDC(ByVal hDC As IntPtr) As IntPtr
End Function
<DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function DeleteDC(ByVal hdc As IntPtr) As Bool
End Function
<DllImport("gdi32.dll", ExactSpelling:=True)>
Public Shared Function SelectObject(ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr
End Function
<DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Bool
End Function
<DllImport("User32.dll")>
Public Shared Function ReleaseCapture() As Boolean
End Function
<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
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

View File

@ -1,4 +1,5 @@
Imports System.Runtime.InteropServices Imports System.Runtime.InteropServices
Imports DigitalData.Modules.Windows
Namespace ClipboardWatcher Namespace ClipboardWatcher
Public Class Watcher Public Class Watcher
@ -12,12 +13,12 @@ Namespace ClipboardWatcher
Private Sub New() Private Sub New()
MyBase.CreateHandle(New CreateParams) MyBase.CreateHandle(New CreateParams)
_Handle = ClassWin32.SetClipboardViewer(Handle) _Handle = NativeMethods.SetClipboardViewer(Handle)
End Sub End Sub
Protected Overrides Sub WndProc(ByRef m As Message) Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg Select Case m.Msg
Case ClassWin32.WM_DRAWCLIPBOARD Case NativeMethods.WM_DRAWCLIPBOARD
Dim oData As IDataObject = Clipboard.GetDataObject Dim oData As IDataObject = Clipboard.GetDataObject
RaiseEvent ClipboardChanged(Me, oData) RaiseEvent ClipboardChanged(Me, oData)
End Select End Select
@ -38,7 +39,7 @@ Namespace ClipboardWatcher
' aufgerufen werden ' aufgerufen werden
End If End If
MyBase.DestroyHandle() MyBase.DestroyHandle()
Dim H As IntPtr = ClassWin32.SetClipboardViewer(_Handle) Dim H As IntPtr = NativeMethods.SetClipboardViewer(_Handle)
End If End If
_DisposedValue = True _DisposedValue = True
End Sub End Sub

View File

@ -246,7 +246,6 @@
<Compile Include="Globix\ClassFilehandle.vb" /> <Compile Include="Globix\ClassFilehandle.vb" />
<Compile Include="ClassInit.vb" /> <Compile Include="ClassInit.vb" />
<Compile Include="ClassLayout.vb" /> <Compile Include="ClassLayout.vb" />
<Compile Include="ClassWin32.vb" />
<Compile Include="ClipboardWatcher\State.vb" /> <Compile Include="ClipboardWatcher\State.vb" />
<Compile Include="ClassIDBData.vb" /> <Compile Include="ClassIDBData.vb" />
<Compile Include="DSIDB_Stammdaten.Designer.vb"> <Compile Include="DSIDB_Stammdaten.Designer.vb">

View File

@ -104,9 +104,8 @@ Public Class frmFlowForm
Try Try
' Marshal the LPARAM value which is a WINDOWPOS struct ' Marshal the LPARAM value which is a WINDOWPOS struct
Dim NewPosition As New ClassWin32.WINDOWPOS Dim NewPosition As New NativeMethods.WINDOWPOS
NewPosition = CType(Marshal.PtrToStructure( NewPosition = CType(Marshal.PtrToStructure(LParam, GetType(NativeMethods.WINDOWPOS)), NativeMethods.WINDOWPOS)
LParam, GetType(ClassWin32.WINDOWPOS)), ClassWin32.WINDOWPOS)
If NewPosition.y = 0 OrElse NewPosition.x = 0 Then If NewPosition.y = 0 OrElse NewPosition.x = 0 Then
Return ' Nothing to do! Return ' Nothing to do!
@ -372,8 +371,8 @@ Public Class frmFlowForm
Private Sub frmFlowForm_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove, PictureBoxDragDrop.MouseMove Private Sub frmFlowForm_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove, PictureBoxDragDrop.MouseMove
If e.Button = MouseButtons.Left Then If e.Button = MouseButtons.Left Then
ClassWin32.ReleaseCapture() NativeMethods.ReleaseCapture()
ClassWin32.SendMessage(Handle, ClassWin32.WM_NCLBUTTONDOWN, ClassWin32.HTCAPTION, 0) NativeMethods.SendMessage(Handle, NativeMethods.WM_NCLBUTTONDOWN, NativeMethods.HTCAPTION, 0)
End If End If
End Sub End Sub

View File

@ -4,16 +4,21 @@ Imports System.Text
Public Class NativeMethods Public Class NativeMethods
Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Int32) As Integer Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Int32) As Integer
Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer
<DllImport("Shell32", CharSet:=CharSet.Auto, SetLastError:=True)> <DllImport("Shell32", CharSet:=CharSet.Auto, SetLastError:=True)>
Public Shared Function ShellExecuteEx(ByRef lpExecInfo As ShellExecuteInfo) As Boolean Public Shared Function ShellExecuteEx(ByRef lpExecInfo As ShellExecuteInfo) As Boolean
End Function End Function
<DllImport("user32", EntryPoint:="SetClipboardViewer")>
Public Shared Function SetClipboardViewer(ByVal hWnd As IntPtr) As IntPtr
End Function
<DllImport("user32.dll")> <DllImport("user32.dll")>
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")> <DllImport("user32.dll")>
Public Shared Function ReleaseDC(ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr Public Shared Function ReleaseDC(ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr
End Function End Function
<DllImport("User32.dll")>
Public Shared Function ReleaseCapture() As Boolean
End Function
<DllImport("user32.dll")> <DllImport("user32.dll")>
Public Shared Function GetWindowRect(ByVal hWnd As HandleRef, ByRef lpRect As RectangleAPI) As Boolean Public Shared Function GetWindowRect(ByVal hWnd As HandleRef, ByRef lpRect As RectangleAPI) As Boolean
End Function End Function
@ -101,6 +106,7 @@ Public Class NativeMethods
Public Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal Atom As Short) As Short Public Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal Atom As Short) As Short
Public Const STANDARD_RIGHTS_REQUIRED As Integer = &HF0000 Public Const STANDARD_RIGHTS_REQUIRED As Integer = &HF0000
Public Const SECTION_QUERY As Short = &H1 Public Const SECTION_QUERY As Short = &H1
Public Const SECTION_MAP_WRITE As Short = &H2 Public Const SECTION_MAP_WRITE As Short = &H2
Public Const SECTION_MAP_READ As Short = &H4 Public Const SECTION_MAP_READ As Short = &H4
@ -108,10 +114,12 @@ Public Class NativeMethods
Public Const SECTION_EXTEND_SIZE As Short = &H10 Public Const SECTION_EXTEND_SIZE As Short = &H10
Public Const SECTION_ALL_ACCESS As Integer = STANDARD_RIGHTS_REQUIRED Or SECTION_QUERY Or SECTION_MAP_WRITE Or SECTION_MAP_READ Or SECTION_MAP_EXECUTE Or SECTION_EXTEND_SIZE Public Const SECTION_ALL_ACCESS As Integer = STANDARD_RIGHTS_REQUIRED Or SECTION_QUERY Or SECTION_MAP_WRITE Or SECTION_MAP_READ Or SECTION_MAP_EXECUTE Or SECTION_EXTEND_SIZE
Public Const FILE_MAP_ALL_ACCESS As Integer = SECTION_ALL_ACCESS Public Const FILE_MAP_ALL_ACCESS As Integer = SECTION_ALL_ACCESS
Public Const PROCESS_VM_OPERATION As Short = &H8 Public Const PROCESS_VM_OPERATION As Short = &H8
Public Const PROCESS_VM_READ As Short = &H10 Public Const PROCESS_VM_READ As Short = &H10
Public Const PROCESS_VM_WRITE As Short = &H20 Public Const PROCESS_VM_WRITE As Short = &H20
Public Const PROCESS_ALL_ACCESS As Long = &H1F0FFF Public Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Public Const MEM_COMMIT As Short = &H1000 Public Const MEM_COMMIT As Short = &H1000
Public Const MEM_RESERVE As Short = &H2000 Public Const MEM_RESERVE As Short = &H2000
Public Const MEM_DECOMMIT As Short = &H4000 Public Const MEM_DECOMMIT As Short = &H4000
@ -120,12 +128,26 @@ Public Class NativeMethods
Public Const MEM_PRIVATE As Integer = &H20000 Public Const MEM_PRIVATE As Integer = &H20000
Public Const MEM_MAPPED As Integer = &H40000 Public Const MEM_MAPPED As Integer = &H40000
Public Const MEM_TOP_DOWN As Integer = &H100000 Public Const MEM_TOP_DOWN As Integer = &H100000
Public Const INVALID_HANDLE_VALUE As Integer = -1 Public Const INVALID_HANDLE_VALUE As Integer = -1
Public Const SW_SHOW As Short = 5 Public Const SW_SHOW As Short = 5
Public Const SEE_MASK_INVOKEIDLIST = &HC Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Const SEE_MASK_NOCLOSEPROCESS = &H40 Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SEE_MASK_FLAG_NO_UI = &H400 Public Const SEE_MASK_FLAG_NO_UI = &H400
Public Const ULW_COLORKEY As Integer = &H1
Public Const ULW_ALPHA As Integer = &H2
Public Const ULW_OPAQUE As Integer = &H4
Public Const AC_SRC_OVER As Byte = &H0
Public Const AC_SRC_ALPHA As Byte = &H1
Public Const HTCAPTION As Integer = &H2
Public Const WM_NCLBUTTONDOWN As Integer = &HA1
Public Const WM_HOTKEY As Integer = &H312 Public Const WM_HOTKEY As Integer = &H312
Public Const WM_DRAWCLIPBOARD As Integer = &H308
Public Enum PageProtection As UInteger Public Enum PageProtection As UInteger
NoAccess = &H1 NoAccess = &H1
@ -148,6 +170,17 @@ Public Class NativeMethods
CWP_SKIPTRANSPARENT CWP_SKIPTRANSPARENT
End Enum End Enum
<StructLayout(LayoutKind.Sequential)>
Public Structure WINDOWPOS
Public hwnd As IntPtr
Public hwndInsertAfter As IntPtr
Public x As Integer
Public y As Integer
Public cx As Integer
Public cy As Integer
Public flags As Integer
End Structure
Public Structure RectangleAPI Public Structure RectangleAPI
Public Left As Integer Public Left As Integer
Public Top As Integer Public Top As Integer