3、声明DLL相关函数 Declare Auto Function SetForegroundWindow Lib "USER32.DLL" (ByVal hWnd As IntPtr) As Boolean Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Integer) As Integer Private Declare Function GetDlgItem Lib "user32" (ByVal hwnd As Integer, ByVal nIDDlgItem As Integer) As Integer 'GetCaretPos Declare Auto Function GetMenu Lib "USER32.DLL" (ByVal hWnd As Integer) As Integer Declare Auto Function GetSubMenu Lib "USER32.DLL" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer Declare Auto Function GetMenuItemCount Lib "USER32.DLL" (ByVal hMenu As Integer) As Integer Declare Auto Function GetMenuItemID Lib "USER32.DLL" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer Declare Auto Function RemoveMenu Lib "USER32.DLL" (ByVal hMenu As Integer, ByVal nPos As Integer, ByVal uFlag As Integer) As Integer 'uFlag is MF_BYCOMMAND or MF_BYPOSITION Declare Auto Function DeleteMenu Lib "USER32.DLL" (ByVal hMenu As Integer, ByVal nPos As Integer, ByVal uFlag As Integer) As Integer 'uFlag is MF_BYCOMMAND or MF_BYPOSITION Declare Auto Function GetMenuState Lib "USER32.DLL" (ByVal hMenu As Integer, ByVal nPos As Integer, ByVal uFlag As Integer) As Integer 'uFlag is MF_BYCOMMAND or MF_BYPOSITION Declare Auto Function GetMenuString Lib "USER32.DLL" (ByVal hMenu As Integer, ByVal uIDItem As Integer, ByVal lpString As String, ByValnMaxCount As Integer, ByVal uFlag As Integer) As Integer 'uFlag is MF_BYCOMMAND or MF_BYPOSITION Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch AsInt32) As Integer Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, _ ByVal wParam As Integer, ByVal lParam As String) As Integer '查找窗口 '窗口类名 <DllImport("user32.dll")> _ Private Shared Function FindWindow(ByVal strClassName As String, ByVal strWindowName As String) As Integer '窗口标题 End Function '在窗口列表中寻找与指定条件相符的第一个子窗口 ' handle to parent window ' handle to child window '窗口类名 <DllImport("user32.dll")> _ Private Shared Function FindWindowEx(ByVal hwndParent As Integer, ByVal hwndChildAfter As Integer, ByVal className As String, ByValwindowName As String) As Integer ' 窗口标题 End Function <DllImport("user32.DLL")> _ Private Shared Function SendMessage(ByVal hWnd As Integer, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) AsInteger End Function '找出某个窗口的创建者(线程或进程),返回创建者的标志符 <DllImport("user32.dll")> _ Private Shared Function GetWindowThreadProcessId(ByVal hwnd As Integer, ByRef processId As Integer) As Integer End Function '打开一个已存在的进程对象,并返回进程的句柄 <DllImport("kernel32.dll")> _ Private Shared Function OpenProcess(ByVal dwDesiredAccess As UInteger, ByVal bInheritHandle As Boolean, ByVal processId As Integer) AsInteger End Function '为指定的进程分配内存地址:成功则返回分配内存的首地址 <DllImport("kernel32.dll")> _ Private Shared Function VirtualAllocEx(ByVal hProcess As Integer, ByVal lpAddress As IntPtr, ByVal dwSize As UInteger, ByVal flAllocationTypeAs UInteger, ByVal flProtect As UInteger) As Integer End Function '从指定内存中读取字节集数据 '被读取者的进程句柄 '开始读取的内存地址 '数据存储变量 '要写入多少字节 <DllImport("kernel32.dll")> _ Private Shared Function ReadProcessMemory(ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As IntPtr, ByVal nSizeAs Integer, ByRef vNumberOfBytesRead As UInteger) As Boolean '读取长度 End Function '将数据写入内存中 '由OpenProcess返回的进程句柄 '要写的内存首地址,再写入之前,此函数将先检查目标地址是否可用,并能容纳待写入的数据 '指向要写的数据的指针 '要写入的字节数 <DllImport("kernel32.dll")> _ Private Shared Function WriteProcessMemory(ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As IntPtr, ByVal nSizeAs Integer, ByRef vNumberOfBytesRead As UInteger) As Boolean End Function <DllImport("kernel32.dll")> _ Private Shared Function CloseHandle(ByVal handle As Integer) As Boolean End Function '在其它进程中释放申请的虚拟内存空间 '目标进程的句柄,该句柄必须拥有PROCESS_VM_OPERATION的权限 '指向要释放的虚拟内存空间首地址的指针 <DllImport("kernel32.dll")> _ Private Shared Function VirtualFreeEx(ByVal hProcess As Integer, ByVal lpAddress As Integer, ByVal dwSize As UInteger, ByVal dwFreeType AsUInteger) As Boolean '释放类型 End Function Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch AsInt32) As Integer ''' <summary> ''' LVITEM结构体,是列表视图控件的一个重要的数据结构 ''' 占空间:(int)x7=28个byte ''' </summary> Private Structure LVITEM '结构体 Public mask As Integer '说明此结构中哪些成员是有效的 Public iItem As Integer '项目的索引值(可以视为行号)从开始 Public iSubItem As Integer '子项的索引值(可以视为列号)从开始 Public state As Integer '子项的状态 Public stateMask As Integer '状态有效的屏蔽位 Public pszText As IntPtr '主项或子项的名称 Public cchTextMax As Integer 'pszText所指向的缓冲区大小 End Structure Private Structure HDITEM Dim mask As Integer Dim cxy As Integer Dim pszText As IntPtr Dim hbm As Integer Dim cchTextMax As Integer Dim fmt As Integer Dim lParam As Integer Dim iImage As Integer Dim iOrder As Integer End Structure |
|