vb.net取控件句柄 vb获取窗口句柄

VB.net 获取控件句柄

Dim hwnd0 As Integer

创新互联2013年开创至今,先为武胜等服务建站,武胜等地企业,进行企业商务咨询服务。为武胜企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

Dim hwnd11 As Integer

第二个是你要生成EXE后 运行EXE

第三就是没好像没有文本框控件

vb中 如何获得窗体中所有控件的句柄?

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Private Const GW_HWNDFIRST = 0

Private Const GW_HWNDNEXT = 2

Private Const GW_CHILD = 5

Private Sub Command1_Click()

Call List1_Click

End Sub

Private Sub Command2_Click()

Dim hwnd As Long

Dim s As String, t As String

List1.Clear

hwnd = GetDesktopWindow()

s = String(256, Chr(0))

GetClassName hwnd, s, 255

s = Replace(s, Chr(0), "")

t = String(256, Chr(0))

GetWindowText hwnd, t, 255

t = Replace(t, Chr(0), "")

List1.AddItem "桌面:" hwnd " 类名:" s " 标题:" t vbCrLf

hwnd = GetWindow(hwnd, GW_CHILD Or GW_HWNDFIRST)

s = String(256, Chr(0))

GetClassName hwnd, s, 255

s = Replace(s, Chr(0), "")

t = String(256, Chr(0))

GetWindowText hwnd, t, 255

t = Replace(t, Chr(0), "")

List1.AddItem "窗口:" hwnd " 类名:" s " 标题:" t vbCrLf

While hwnd 0

hwnd = GetWindow(hwnd, GW_HWNDNEXT)

s = String(256, Chr(0))

GetClassName hwnd, s, 255

s = Replace(s, Chr(0), "")

t = String(256, Chr(0))

GetWindowText hwnd, t, 255

t = Replace(t, Chr(0), "")

List1.AddItem "窗口:" hwnd " 类名:" s "标题:" t vbCrLf

Wend

End Sub

Private Sub Form_Load()

Command1.Caption = "获取所有控件"

Command2.Caption = "遍历所有窗体"

End Sub

Private Sub EnumAllHandles(ByVal hwnd As Long)

Dim hn As Long

Dim firsthd As Long

Dim s As String, t As String

firsthd = GetWindow(hwnd, GW_CHILD)

firsthd = GetWindow(firsthd, GW_HWNDFIRST)

hn = firsthd

Do While hn 0

s = String(256, Chr(0))

GetClassName hn, s, 255

s = Replace(s, Chr(0), "")

t = String(256, Chr(0))

GetWindowText hn, t, 255

t = Replace(t, Chr(0), "")

Text1.Text = Text1.Text "句柄:" hn " 父句柄:" hwnd " 类名:" s "标题:" t vbCrLf

TreeView1.Nodes.Add "k" hwnd, tvwChild, "k" hn, "句柄:" hn " 类名:" s "标题:" t

EnumAllHandles hn

hn = GetWindow(hn, GW_HWNDNEXT)

If hn = firsthd Then Exit Do

Loop

End Sub

Private Sub List1_Click()

If List1.ListIndex = -1 Then Exit Sub

TreeView1.Nodes.Clear

TreeView1.Nodes.Add , , "k" Trim(Str(Val(Mid(List1.Text, 4)))), List1.Text

Text1.Text = ""

EnumAllHandles Val(Mid(List1.Text, 4))

TreeView1.Nodes("k" Trim(Str(Val(Mid(List1.Text, 4))))).Expanded = True

End Sub

'添加两个按钮一个文本框一个列表框和一个树形图

在VB中,如何获取鼠标所在的点处的控件句柄

Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Type POINTAPI

x As Long

y As Long

End Type

Private Sub Timer1_Timer()

Dim a As POINTAPI

GetCursorPos a

b = WindowFromPoint(a.x, a.y)

Me.Caption = b

End Sub

添加一个timer控件 代码如上 取得句柄在窗体标题处显示

VB 获取其他程序控件的句柄

一般是用钩子程序的。

比较复杂,只能说个大体思路,要花最少30分钟。分太少了。

API函数的声明就不说了。

先用findwindow找到窗体,用GetWindow和GetClassName获得其窗体内各对象的句柄,从而可以获得文本框的句柄。

最后用SendMessage函数想文本框发送文本。

tWnd = FindWindow(vbNullString, "窗口名")可以获得外部程序窗口的句柄twnd

bwnd = GetWindow(tWnd, GW_CHILD)可以获得该窗口子对象的集合句柄bwnd

Do Until bwnd = 0

GetClassName bwnd, sSave, 250

If InStr(1, UCase(sSave), "EDIT", vbTextCompare) 0 Then

editwnd = bwnd

Exit Do

End If

bwnd = GetWindow(bwnd, GW_HWNDNEXT)

Loop

以上代码可以读到该窗口中的第一个文本框的句柄editwnd

SendMessage editwnd, WM_SETTEXT, 6, "王小明"

以上代码向editwnd中写入“王小明”,6表示其长度。该方法写入时,文本框中原有内容全部覆盖。

VB 实现取得其他窗口中某控件的句柄

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long'查找控件

Private Declare Function GetForegroundWindow Lib "user32" () As Long'得到当前桌面窗体

当你桌面有程序激活时,句柄可以通过GetForegroundWindow得到

findWindowEx得到已知句柄窗体中某个控件

vb.net如何找到一个网页中的按钮的句柄

网页中的按钮没有句柄可言,只有控件id,你想要的到底是什么,找到按钮模拟点击按钮?

找到按钮不难,查找input,id是那个按钮的话就用DOM获取到,然后发送.click方法

也可以用附加js脚本的方式来实现点击那个按钮,js脚本里实现获取那个按钮并点击


网站题目:vb.net取控件句柄 vb获取窗口句柄
当前网址:http://hbruida.cn/article/hphhdo.html