标签:
对于一直觉得科技就是要提高生产力的我这个硬件工程师来说,要编写这些更复杂的程序,真是件吃力不讨好的事,好在,我不需要赶时间,有空兴趣就搞一下,没空没心情完全可以不用理,最近,因为工作上又有了相关需要(非必要的需要、完全出于个人爱好),才又拾起心情,继续之前一直未完成的事情,这次,总算有了进展,一直未解决的问题,得到了解决。
本次实现如下功能:
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
标签:
原文地址:http://www.cnblogs.com/lefour/p/5464104.html