如何获取一个程序上的多个textbox控件的句柄和文本,这个问题困扰我很久,谁个指导指导,有vb源码参考最好
2个回答
展开全部
哈,用API就行了
加入4个label控件,1个timer控件
代码:
Private Declare Function WindowFromPoint Lib "user32" (ByVal a As Long, ByVal b As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal a As Long, ByVal b As String, ByVal c As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal a As Long, ByVal b As Long, ByVal c As Long, ByVal d As Any) As Long
Private Declare Function GetCursorPos Lib "user32" (a As b) As Long
Private Type b
x As Long
y As Long
End Type
Private Sub Form_Load()
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Dim a As b
Dim b As Long
Dim c As String * 255
Dim d As String
d = Space(255)
GetCursorPos a
b = WindowFromPoint(a.x, a.y)
Label1.Caption = b
GetClassName Label1.Caption, c, 255
Label3.Caption = c
Label4.Caption = "X:" & a.x & " Y:" & a.y
SendMessage b, &HD, 256, ByVal d
Label2.Caption = d
End Sub
label1是句柄
label2是内容
label3是类名
label4是指针坐标位置
鼠标指那块,就显示那块的
这是我以前做的,代码复制了下来
加入4个label控件,1个timer控件
代码:
Private Declare Function WindowFromPoint Lib "user32" (ByVal a As Long, ByVal b As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal a As Long, ByVal b As String, ByVal c As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal a As Long, ByVal b As Long, ByVal c As Long, ByVal d As Any) As Long
Private Declare Function GetCursorPos Lib "user32" (a As b) As Long
Private Type b
x As Long
y As Long
End Type
Private Sub Form_Load()
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Dim a As b
Dim b As Long
Dim c As String * 255
Dim d As String
d = Space(255)
GetCursorPos a
b = WindowFromPoint(a.x, a.y)
Label1.Caption = b
GetClassName Label1.Caption, c, 255
Label3.Caption = c
Label4.Caption = "X:" & a.x & " Y:" & a.y
SendMessage b, &HD, 256, ByVal d
Label2.Caption = d
End Sub
label1是句柄
label2是内容
label3是类名
label4是指针坐标位置
鼠标指那块,就显示那块的
这是我以前做的,代码复制了下来
更多追问追答
追问
这种方法不是我要找的,可不可以只用FindWindow FindWindowEx SendMessage 这三个函数实现
追答
也可以
获取记事本的内容
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal a As String, ByVal b As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal a As Long, ByVal b As Long, ByVal c As String, ByVal b As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal a As Long, ByVal b As Long, ByVal c As Long, ByVal b As Any) As Long
Private Sub Form_Load()
Dim a As String
a = Space(255)
SendMessage FindWindowEx(FindWindow(vbNullString, "无标题 - 记事本"), 0, "Edit", vbNullString), &HD, 256, ByVal a '"Edit"是类名
MsgBox a
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询