如何捕捉窗体内的控件的句柄?

76ers 2001-09-09 12:07:55
请执教。
...全文
129 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
htu 2001-09-09
  • 打赏
  • 举报
回复
这个没问题了吧?
顺便说一下,你给的分也太少了吧 1分
Declare Function EnumWindows& Lib "user32" ( _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long)

【说 明】

枚举窗口列表中的所有父窗口(顶级和被所有窗口)
76ers 2001-09-09
  • 打赏
  • 举报
回复
是的,这个api函数可以,捕捉子窗口的句柄,
但是,两不同的应用程序,不存在父子关系呀!
htu 2001-09-09
  • 打赏
  • 举报
回复
第三种根据鼠标的位置
Declare Function WindowFromPoint& Lib "user32" ( _
ByVal X As Long, _
ByVal Y As Long)

【说 明】

返回包含了指定点的窗口的句柄。忽略屏蔽、隐藏以及透明窗口

建议使用EnumChildWindows枚举子窗口
例子:
'in a form
Private Sub Form_Load()
Me.AutoRedraw = True
EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0&
End Sub
'in a module
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
'Get the windowtext length
sSave = Space$(GetWindowTextLength(hwnd) + 1)
'get the window text
GetWindowText hwnd, sSave, Len(sSave)
'remove the last Chr$(0)
sSave = Left$(sSave, Len(sSave) - 1)
If sSave <> "" Then Form1.Print sSave
'continue enumeration
EnumChildProc = 1
End Function
htu 2001-09-09
  • 打赏
  • 举报
回复
也可以用
Declare Function EnumChildWindows& Lib "user32" ( _
ByVal hWndParent As Long, _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long)

【说 明】

为指定的父窗口枚举子窗口
76ers 2001-09-09
  • 打赏
  • 举报
回复
up,能行吗?
htu 2001-09-09
  • 打赏
  • 举报
回复
dim h&
Sub Text1_GotFocus()
'h就是text1的hwnd
h& = GetFocus&()
End Sub
76ers 2001-09-09
  • 打赏
  • 举报
回复
类似spy++
我不太清楚。
Ninputer 2001-09-09
  • 打赏
  • 举报
回复
根据鼠标的位置吗?还是其他
76ers 2001-09-09
  • 打赏
  • 举报
回复
我想用一个应用程序来捕捉其他应用程序中的控件的句柄!
Ninputer 2001-09-09
  • 打赏
  • 举报
回复
Controlname.hWnd
76ers 2001-09-09
  • 打赏
  • 举报
回复
我的可用分布多,请见谅!

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧