VB 已知窗体句柄,如何取各控件的句柄,各控件没有标题,类名均为WindowsForms10.EDIT.app.0.378734a,
1个回答
展开全部
参考如下代码:
Option Explicit
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hWnd As Long, ByVal wFlag As Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDLAST = 1
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDPREV = 3
Private Const GW_OWNER = 4
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Function GetChild(ByVal hWnd As Long) As Long
Dim L1 As Long, L2 As Long, s As String
L2 = GetNextWindow(hWnd, GW_CHILD)
If L2 = 0 Then Exit Function
With Form1.List1
Do
L1 = 255: s = String(L1, Chr(0))
L1 = GetClassName(L2, s, L1): s = Left(s, L1)
.AddItem CStr(L2) & ":" & s
L1 = L2: L2 = GetChild(L2)
L2 = GetNextWindow(L1, GW_HWNDNEXT)
If L2 = 0 Then Exit Do
Loop
End With
End Function
Option Explicit
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hWnd As Long, ByVal wFlag As Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDLAST = 1
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDPREV = 3
Private Const GW_OWNER = 4
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Function GetChild(ByVal hWnd As Long) As Long
Dim L1 As Long, L2 As Long, s As String
L2 = GetNextWindow(hWnd, GW_CHILD)
If L2 = 0 Then Exit Function
With Form1.List1
Do
L1 = 255: s = String(L1, Chr(0))
L1 = GetClassName(L2, s, L1): s = Left(s, L1)
.AddItem CStr(L2) & ":" & s
L1 = L2: L2 = GetChild(L2)
L2 = GetNextWindow(L1, GW_HWNDNEXT)
If L2 = 0 Then Exit Do
Loop
End With
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询