-
VB.NET自动操作其他程序(2)--声明DLL相关函数
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
出处:https://www.cnblogs.com/lefour/p/5464106.html
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
出处:https://www.cnblogs.com/lefour/p/5464106.html
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式