vb获取窗口句柄并获取鼠标焦点

2025-03-09 20:21:15
推荐回答(1个)
回答1:

使用系统API

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, 200, 0, conSwpNoActivate Or conSwpShowWindow
End Sub
Private Sub Timer1_Timer()
Dim xy As POINTAPI
GetCursorPos xy
ahwnd = WindowFromPointXY(xy.x, xy.y)
Me.Caption = "Handler : " & ahwnd
End Sub