-
VB.NET自动操作其他程序(1)--相关引用及常量定义
对于一直觉得科技就是要提高生产力的我这个硬件工程师来说,要编写这些更复杂的程序,真是件吃力不讨好的事,好在,我不需要赶时间,有空兴趣就搞一下,没空没心情完全可以不用理,最近,因为工作上又有了相关需要(非必要的需要、完全出于个人爱好),才又拾起心情,继续之前一直未完成的事情,这次,总算有了进展,一直未解决的问题,得到了解决。
本次实现如下功能:
1、捕获其他程序窗口句柄
2、单击其他程序的菜单
3、读取其他软件listview控件的内容
4、设置其他程序的下拉框的选择
5、设置其他程序Edit框的值
6、单击其他程序按钮
1、添加相关引用:
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.IO
Imports System.Drawing
Imports System.Linq
Imports System.Text
'Imports System.Threading.Tasks
Imports System.Threading.Thread
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
2、首先定义相关常量(相关常量的定义,可以从c语言的头文件windows.h 、winbase.h 、commdlg.h 、commctrl.h 、winuser.h 等中找到):
Private Const LVIS_SELECTED As UInteger = &H2
Private Const LVM_FIRST As UInteger = &H1000
Private Const HDM_FIRST As UInteger = &H1200 '// Header messages
Private Const HDM_GETITEMA As UInteger = (HDM_FIRST + 3)
Private Const HDM_GETITEMW As UInteger = (HDM_FIRST + 11)
Private Const HDM_GETITEM As UInteger = HDM_GETITEMW
'获取列表头内的内容
Private Const LVM_GETHEADER As UInteger = LVM_FIRST + 31
Private Const LVM_GETITEMCOUNT As UInteger = LVM_FIRST + 4
'获取列表行数
Private Const LVM_GETITEMTEXT As UInteger = LVM_FIRST + 45
'获取列表内的内容
Private Const LVM_GETITEMW As UInteger = LVM_FIRST + 75
Private Const LVM_SETITEMSTATE As UInteger = LVM_FIRST + 43
Private Const HDM_GETITEMCOUNT As UInteger = &H1200
'获取列表列数
Private Const PROCESS_VM_OPERATION As UInteger = &H8
'允许函数VirtualProtectEx使用此句柄修改进程的虚拟内存
Private Const PROCESS_VM_READ As UInteger = &H10
'允许函数访问权限
Private Const PROCESS_VM_WRITE As UInteger = &H20
'允许函数写入权限
Private Const MEM_COMMIT As UInteger = &H1000
'为特定的页面区域分配内存中或磁盘的页面文件中的物理存储
Private Const MEM_RELEASE As UInteger = &H8000
Private Const MEM_RESERVE As UInteger = &H2000
'保留进程的虚拟地址空间,而不分配任何物理存储
Private Const PAGE_READWRITE As UInteger = 4
Public WithEvents ListView1 As System.Windows.Forms.ListView
Friend WithEvents Button1 As System.Windows.Forms.Button
Private LVIF_TEXT As Integer = &H1
Private LVIF_IMAGE As Integer = &H2
Private LVIF_PARAM As Integer = &H4
Private LVIF_STATE As Integer = &H8
Private Const HDI_TEXT = &H2
Private Const LVM_SETITEMTEXTA As UInteger = LVM_FIRST + 46
Private Const LVM_SETITEMTEXTW As UInteger = LVM_FIRST + 116
Private Const LVM_SETITEMTEXT As UInteger = LVM_SETITEMTEXTW
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Private Const LVIS_STATEIMAGEMASK As UInteger = &HF000
'#define LVM_SETITEMTEXTA (LVM_FIRST + 46)
'#define LVM_SETITEMTEXTW (LVM_FIRST + 116)
'#ifdef UNICODE
'#define LVM_SETITEMTEXT LVM_SETITEMTEXTW
'#else
'#define LVM_SETITEMTEXT LVM_SETITEMTEXTA
'#End If
Private Const WM_SYSCOMMAND = &H112
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Private components As System.ComponentModel.IContainer
Private Const WM_COMMAND = &H111
Private Const WM_SETTEXT = &HC
Private Const BM_CLICK = &HF5
Private Const CB_SETCURSEL = &H14E
Dim headerhwnd As Integer
'listview控件的列头句柄
Private hwnd As Integer
'窗口句柄
Private process As Integer
'进程句柄
Private pointer As Integer
出处:https://www.cnblogs.com/lefour/p/5464104.html
本次实现如下功能:
1、捕获其他程序窗口句柄
2、单击其他程序的菜单
3、读取其他软件listview控件的内容
4、设置其他程序的下拉框的选择
5、设置其他程序Edit框的值
6、单击其他程序按钮
1、添加相关引用:
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.IO
Imports System.Drawing
Imports System.Linq
Imports System.Text
'Imports System.Threading.Tasks
Imports System.Threading.Thread
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
2、首先定义相关常量(相关常量的定义,可以从c语言的头文件windows.h 、winbase.h 、commdlg.h 、commctrl.h 、winuser.h 等中找到):
Private Const LVIS_SELECTED As UInteger = &H2
Private Const LVM_FIRST As UInteger = &H1000
Private Const HDM_FIRST As UInteger = &H1200 '// Header messages
Private Const HDM_GETITEMA As UInteger = (HDM_FIRST + 3)
Private Const HDM_GETITEMW As UInteger = (HDM_FIRST + 11)
Private Const HDM_GETITEM As UInteger = HDM_GETITEMW
'获取列表头内的内容
Private Const LVM_GETHEADER As UInteger = LVM_FIRST + 31
Private Const LVM_GETITEMCOUNT As UInteger = LVM_FIRST + 4
'获取列表行数
Private Const LVM_GETITEMTEXT As UInteger = LVM_FIRST + 45
'获取列表内的内容
Private Const LVM_GETITEMW As UInteger = LVM_FIRST + 75
Private Const LVM_SETITEMSTATE As UInteger = LVM_FIRST + 43
Private Const HDM_GETITEMCOUNT As UInteger = &H1200
'获取列表列数
Private Const PROCESS_VM_OPERATION As UInteger = &H8
'允许函数VirtualProtectEx使用此句柄修改进程的虚拟内存
Private Const PROCESS_VM_READ As UInteger = &H10
'允许函数访问权限
Private Const PROCESS_VM_WRITE As UInteger = &H20
'允许函数写入权限
Private Const MEM_COMMIT As UInteger = &H1000
'为特定的页面区域分配内存中或磁盘的页面文件中的物理存储
Private Const MEM_RELEASE As UInteger = &H8000
Private Const MEM_RESERVE As UInteger = &H2000
'保留进程的虚拟地址空间,而不分配任何物理存储
Private Const PAGE_READWRITE As UInteger = 4
Public WithEvents ListView1 As System.Windows.Forms.ListView
Friend WithEvents Button1 As System.Windows.Forms.Button
Private LVIF_TEXT As Integer = &H1
Private LVIF_IMAGE As Integer = &H2
Private LVIF_PARAM As Integer = &H4
Private LVIF_STATE As Integer = &H8
Private Const HDI_TEXT = &H2
Private Const LVM_SETITEMTEXTA As UInteger = LVM_FIRST + 46
Private Const LVM_SETITEMTEXTW As UInteger = LVM_FIRST + 116
Private Const LVM_SETITEMTEXT As UInteger = LVM_SETITEMTEXTW
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Private Const LVIS_STATEIMAGEMASK As UInteger = &HF000
'#define LVM_SETITEMTEXTA (LVM_FIRST + 46)
'#define LVM_SETITEMTEXTW (LVM_FIRST + 116)
'#ifdef UNICODE
'#define LVM_SETITEMTEXT LVM_SETITEMTEXTW
'#else
'#define LVM_SETITEMTEXT LVM_SETITEMTEXTA
'#End If
Private Const WM_SYSCOMMAND = &H112
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Private components As System.ComponentModel.IContainer
Private Const WM_COMMAND = &H111
Private Const WM_SETTEXT = &HC
Private Const BM_CLICK = &HF5
Private Const CB_SETCURSEL = &H14E
Dim headerhwnd As Integer
'listview控件的列头句柄
Private hwnd As Integer
'窗口句柄
Private process As Integer
'进程句柄
Private pointer As Integer
出处:https://www.cnblogs.com/lefour/p/5464104.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.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式