VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



'Get handle of the window at mouse cursor position using WindowFromPoint API

by Karthikeyan (187 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Tue 23rd January 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

'Get handle of the window at mouse cursor position using WindowFromPoint API

API Declarations


x As Long
y As Long
End Type
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 Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
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

Rate 'Get handle of the window at mouse cursor position using WindowFromPoint API



'http://www.geocities.com/marskarthik
'http://marskarthik.virtualave.net
'Email: [email protected]
Private Sub Form_Load()
'Set window on top of all
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 1
Timer1.Enabled = True
Timer1.Interval = 10
End Sub

'Note: This program is very useful to developing spy programs
Private Sub Timer1_Timer()
Dim cname As String
Dim cp As POINTAPI
Dim rval As Long
Dim hwnd As Long
'Get current Cursor Position
rval = GetCursorPos(cp)
'Get the handle of the window at mouse cursor point
hwnd = WindowFromPoint(cp.x, cp.y)
cname = Space(128)
'Get Classname
rval = GetClassName(hwnd, cname, 128)
Form1.Caption = Left(cname, InStr(cname, Chr(0)) - 1)
Label1.Caption = "Classname = " & Left(cname, InStr(cname, Chr(0)) - 1) & _
Chr(13) & " Handle = " & hwnd
End Sub

Download this snippet    Add to My Saved Code

'Get handle of the window at mouse cursor position using WindowFromPoint API Comments

No comments have been posted about 'Get handle of the window at mouse cursor position using WindowFromPoint API. Why not be the first to post a comment about 'Get handle of the window at mouse cursor position using WindowFromPoint API.

Post your comment

Subject:
Message:
0/1000 characters