API的难题.解决后给200分,要源代码!

dbcontrols 2001-12-21 09:44:32
如何得到用户光标所在位置的控件的句柄?我是指不知道他在操作什么程序的情况下!我可以用如下方法得到它的父类(或祖父类,反正是顶级)的句柄,也可以得到光标的坐标(用另外的方法)
Private Declare Function GetForegroundWindow& Lib "user32" ()
Private Declare Function GetWindowText& Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long)

Private Sub Command1_Click()
Dim dl1&, dl2&
Dim Canp As String * 255
dl1& = GetForegroundWindow&() `获取当前活动窗口的句柄
dl2& = GetWindowText&(dl1&, Canp$, 255) `获取窗口的标题
End Sub
...全文
49 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dbcontrols 2001-12-21
  • 打赏
  • 举报
回复
你这样只能得到你的程序所点的那个按钮的句柄.
dbcontrols 2001-12-21
  • 打赏
  • 举报
回复
我要的是光标位置,不是鼠标位置.谢谢你!
enmity 2001-12-21
  • 打赏
  • 举报
回复
Public Declare Function WindowFromPoint Lib "user32" _
(ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type

Private Sub Command1_Click()

Dim P As POINTAPI

GetCursorPos P

debug.print WindowFromPoint(P.x, P.y)

End Sub

1,486

社区成员

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

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