Author:水如烟
Imports
System.Runtime.InteropServices
Imports System.Text
Namespace LzmTW.uSystem.uWindows.SafeNative
Friend Class SafeNativeMethods
Sub New ()
End Sub
' -------------------------------------
' 枚举窗体,激活窗体
Public Declare Function EnumWindows Lib " user32.dll " _
Alias " EnumWindows " ( ByVal callback As Win32API.EnumWindowsCallback, _
ByVal lParam As Integer ) As Integer
< DllImport( " user32.dll " , EntryPoint: = " EnumWindows " , SetLastError: = True , _
CharSet: = CharSet.Ansi, ExactSpelling: = True , _
CallingConvention: = CallingConvention.StdCall) > _
Public Shared Function EnumWindowsDllImport( ByVal callback As Win32API.EnumWindowsCallback, _
ByVal lParam As Integer ) As Integer
End Function
Public Declare Auto Function FindWindow Lib " user32.dll " _
Alias " FindWindow " ( ByVal lpClassName As String , _
ByVal lpWindowName As String ) As Integer
Public Declare Auto Function FindWindowAny Lib " user32.dll " _
Alias " FindWindow " ( ByVal lpClassName As Integer , _
ByVal lpWindowName As Integer ) As Integer
Public Declare Auto Function FindWindowNullClassName Lib " user32.dll " _
Alias " FindWindow " ( ByVal lpClassName As Integer , _
ByVal lpWindowName As String ) As Integer
Public Declare Auto Function FindWindowNullWindowCaption Lib " user32.dll " _
Alias " FindWindow " ( ByVal lpClassName As String , _
ByVal lpWindowName As Integer ) As Integer
Public Declare Function GetClassName Lib " user32.dll " _
Alias " GetClassNameA " ( ByVal hwnd As Integer , _
ByVal lpClassName As StringBuilder, _
ByVal cch As Integer ) As Integer
Public Declare Function GetParent Lib " user32.dll " _
Alias " GetParent " ( ByVal hwnd As Integer ) As Integer
Public Declare Function GetWindow Lib " user32.dll " _
Alias " GetWindow " ( ByVal hwnd As Integer , _
ByVal wCmd As Integer ) As Integer
Public Declare Function GetWindowLong Lib " user32.dll " _
Alias " GetWindowLongA " ( ByVal hwnd As Integer , _
ByVal nIndex As Integer ) As Integer
Public Declare Sub GetWindowText Lib " user32.dll " _
Alias " GetWindowTextA " ( ByVal hWnd As Integer , _
ByVal lpString As StringBuilder, _
ByVal nMaxCount As Integer )
Public Declare Function IsIconic Lib " user32.dll " _
Alias " IsIconic " ( ByVal hwnd As Integer ) As Boolean
Public Declare Function IsPwrHibernateAllowed Lib " Powrprof.dll " _
Alias " IsPwrHibernateAllowed " () As Integer
Public Declare Function IsWindowVisible Lib " user32.dll " _
Alias " IsWindowVisible " ( ByVal hwnd As Integer ) As Boolean
Public Declare Function SetForegroundWindow Lib " user32.dll " _
Alias " SetForegroundWindow " ( ByVal hwnd As Integer ) As Integer
Public Declare Function SetSuspendState Lib " Powrprof.dll " _
Alias " SetSuspendState " ( ByVal Hibernate As Integer , _
ByVal ForceCritical As Integer , _
ByVal DisableWakeEvent As Integer ) As Integer
Public Declare Function ShowWindow Lib " user32.dll " _
Alias " ShowWindow " ( ByVal hwnd As Integer , ByVal nCmdShow As Integer ) As Integer
' -------------------------------------------
' 鼠标和键盘钩子
Public Delegate Function HookProc( ByVal nCode As Integer , ByVal wParam As Integer , ByVal lParam As IntPtr) As Integer
' //封送结构
< StructLayout(LayoutKind.Sequential) > _
Public Class POINT
Public x As Integer
Public y As Integer
End Class
< StructLayout(LayoutKind.Sequential) > _
Public Class MouseHookStruct
Public pt As POINT
Public hWnd As Integer
Public wHitTestCode As Integer
Public dwExtraInfo As Integer
End Class
< StructLayout(LayoutKind.Sequential) > _
Public Class KeyboardHookStruct
Public vkCode As Integer ' 1到254间的虚似键盘码
Public scanCode As Integer ' 扫描码
Public flags As Integer
Public time As Integer
Public dwExtraInfo As Integer
End Class
< DllImport( " user32.dll " , CallingConvention: = CallingConvention.StdCall, CharSet: = CharSet.Auto) > _
Public Shared Function SetWindowsHookEx( ByVal idHook As Integer , ByVal lpfn As HookProc, ByVal hInstance As IntPtr, ByVal threadId As Integer ) As Integer
End Function
< DllImport( " user32.dll " , CallingConvention: = CallingConvention.StdCall, CharSet: = CharSet.Auto) > _
Public Shared Function UnhookWindowsHookEx( ByVal idHook As Integer ) As Boolean
End Function
< DllImport( " user32.dll " , CallingConvention: = CallingConvention.StdCall, CharSet: = CharSet.Auto) > _
Public Shared Function CallNextHookEx( ByVal idHook As Integer , ByVal nCode As Integer , ByVal wParam As Integer , ByVal lParam As IntPtr) As Integer
End Function
< DllImport( " user32 " ) > _
Public Shared Function ToAscii( ByVal uVirtKey As Integer , ByVal uScanCode As Integer , ByVal lpbKeyState As Byte (), ByVal lpwTransKey As Byte (), ByVal fuState As Integer ) As Integer
End Function
< DllImport( " user32 " ) > _
Public Shared Function GetKeyboardState( ByVal pbKeyState As Byte ()) As Integer
End Function
Public Declare Function GetKeyState Lib " user32 " Alias " GetKeyState " ( ByVal nVirtKey As Integer ) As Integer
Public Declare Function SetParent Lib " user32 " Alias " SetParent " ( ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
End Class
End Namespace
Imports System.Text
Namespace LzmTW.uSystem.uWindows.SafeNative
Friend Class SafeNativeMethods
Sub New ()
End Sub
' -------------------------------------
' 枚举窗体,激活窗体
Public Declare Function EnumWindows Lib " user32.dll " _
Alias " EnumWindows " ( ByVal callback As Win32API.EnumWindowsCallback, _
ByVal lParam As Integer ) As Integer
< DllImport( " user32.dll " , EntryPoint: = " EnumWindows " , SetLastError: = True , _
CharSet: = CharSet.Ansi, ExactSpelling: = True , _
CallingConvention: = CallingConvention.StdCall) > _
Public Shared Function EnumWindowsDllImport( ByVal callback As Win32API.EnumWindowsCallback, _
ByVal lParam As Integer ) As Integer
End Function
Public Declare Auto Function FindWindow Lib " user32.dll " _
Alias " FindWindow " ( ByVal lpClassName As String , _
ByVal lpWindowName As String ) As Integer
Public Declare Auto Function FindWindowAny Lib " user32.dll " _
Alias " FindWindow " ( ByVal lpClassName As Integer , _
ByVal lpWindowName As Integer ) As Integer
Public Declare Auto Function FindWindowNullClassName Lib " user32.dll " _
Alias " FindWindow " ( ByVal lpClassName As Integer , _
ByVal lpWindowName As String ) As Integer
Public Declare Auto Function FindWindowNullWindowCaption Lib " user32.dll " _
Alias " FindWindow " ( ByVal lpClassName As String , _
ByVal lpWindowName As Integer ) As Integer
Public Declare Function GetClassName Lib " user32.dll " _
Alias " GetClassNameA " ( ByVal hwnd As Integer , _
ByVal lpClassName As StringBuilder, _
ByVal cch As Integer ) As Integer
Public Declare Function GetParent Lib " user32.dll " _
Alias " GetParent " ( ByVal hwnd As Integer ) As Integer
Public Declare Function GetWindow Lib " user32.dll " _
Alias " GetWindow " ( ByVal hwnd As Integer , _
ByVal wCmd As Integer ) As Integer
Public Declare Function GetWindowLong Lib " user32.dll " _
Alias " GetWindowLongA " ( ByVal hwnd As Integer , _
ByVal nIndex As Integer ) As Integer
Public Declare Sub GetWindowText Lib " user32.dll " _
Alias " GetWindowTextA " ( ByVal hWnd As Integer , _
ByVal lpString As StringBuilder, _
ByVal nMaxCount As Integer )
Public Declare Function IsIconic Lib " user32.dll " _
Alias " IsIconic " ( ByVal hwnd As Integer ) As Boolean
Public Declare Function IsPwrHibernateAllowed Lib " Powrprof.dll " _
Alias " IsPwrHibernateAllowed " () As Integer
Public Declare Function IsWindowVisible Lib " user32.dll " _
Alias " IsWindowVisible " ( ByVal hwnd As Integer ) As Boolean
Public Declare Function SetForegroundWindow Lib " user32.dll " _
Alias " SetForegroundWindow " ( ByVal hwnd As Integer ) As Integer
Public Declare Function SetSuspendState Lib " Powrprof.dll " _
Alias " SetSuspendState " ( ByVal Hibernate As Integer , _
ByVal ForceCritical As Integer , _
ByVal DisableWakeEvent As Integer ) As Integer
Public Declare Function ShowWindow Lib " user32.dll " _
Alias " ShowWindow " ( ByVal hwnd As Integer , ByVal nCmdShow As Integer ) As Integer
' -------------------------------------------
' 鼠标和键盘钩子
Public Delegate Function HookProc( ByVal nCode As Integer , ByVal wParam As Integer , ByVal lParam As IntPtr) As Integer
' //封送结构
< StructLayout(LayoutKind.Sequential) > _
Public Class POINT
Public x As Integer
Public y As Integer
End Class
< StructLayout(LayoutKind.Sequential) > _
Public Class MouseHookStruct
Public pt As POINT
Public hWnd As Integer
Public wHitTestCode As Integer
Public dwExtraInfo As Integer
End Class
< StructLayout(LayoutKind.Sequential) > _
Public Class KeyboardHookStruct
Public vkCode As Integer ' 1到254间的虚似键盘码
Public scanCode As Integer ' 扫描码
Public flags As Integer
Public time As Integer
Public dwExtraInfo As Integer
End Class
< DllImport( " user32.dll " , CallingConvention: = CallingConvention.StdCall, CharSet: = CharSet.Auto) > _
Public Shared Function SetWindowsHookEx( ByVal idHook As Integer , ByVal lpfn As HookProc, ByVal hInstance As IntPtr, ByVal threadId As Integer ) As Integer
End Function
< DllImport( " user32.dll " , CallingConvention: = CallingConvention.StdCall, CharSet: = CharSet.Auto) > _
Public Shared Function UnhookWindowsHookEx( ByVal idHook As Integer ) As Boolean
End Function
< DllImport( " user32.dll " , CallingConvention: = CallingConvention.StdCall, CharSet: = CharSet.Auto) > _
Public Shared Function CallNextHookEx( ByVal idHook As Integer , ByVal nCode As Integer , ByVal wParam As Integer , ByVal lParam As IntPtr) As Integer
End Function
< DllImport( " user32 " ) > _
Public Shared Function ToAscii( ByVal uVirtKey As Integer , ByVal uScanCode As Integer , ByVal lpbKeyState As Byte (), ByVal lpwTransKey As Byte (), ByVal fuState As Integer ) As Integer
End Function
< DllImport( " user32 " ) > _
Public Shared Function GetKeyboardState( ByVal pbKeyState As Byte ()) As Integer
End Function
Public Declare Function GetKeyState Lib " user32 " Alias " GetKeyState " ( ByVal nVirtKey As Integer ) As Integer
Public Declare Function SetParent Lib " user32 " Alias " SetParent " ( ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
End Class
End Namespace