所以,我试图捕捉一个有 2 个文本框的窗口,并向这两个文本框发送一些文本。但是两个文本框都没有标题和相同的类名“编辑”。到目前为止,我所能做的就是捕获第一个文本框,仅此而已。
下面粘贴的是我的代码。
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
ByVal lParam As String) As Integer
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Integer
Private Const WM_SETTEXT As Integer = &HC
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
Dim hwnd As Integer
Dim txt As Integer
Dim text As String
hwnd = FindWindow(vbNullString, "Description")
If hwnd <> Nothing Then
txt = FindWindowEx(hwnd, 0, "Edit", vbNullString)
If txt <> Nothing Then
text = "00000"
SendMessage(txt, WM_SETTEXT, 0, text)
End If
End If
End Sub
End Class