對於一直覺得科技就是要提高生產力的我這個硬件工程師來說,要編寫這些更復雜的程序,真是件吃力不討好的事,好在,我不需要趕時間,有空興趣就搞一下,沒空沒心情完全可以不用理,最近,因為工作上又有了相關需要(非必要的需要、完全出於個人愛好),才又拾起心情,繼續之前一直未完成的事情,這次,總算有了進展,一直未解決的問題,得到了解決。
本次實現如下功能:
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
