VB and VBA Users Source Code: Returning the windows handle of a dialog at a specified point
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Returning the windows handle of a dialog at a specified point
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, June 27, 2001
Hits:
1002
Category:
Windows API
Article:
The following code demonstrates how to return the windows handle of the form/dialog at a specific location on the screen. Option Explicit Private Declare Function WindowFromPointA Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long 'Purpose : Returns the windows handle of the window which is at the specified location 'Inputs : X The X coordinate of the window ' Y The Y coordinate of the window 'Outputs : Returns the handle of the window at the specified location, else returns 0. 'Author : Andrew Baker 'Date : 25/05/2001 'Notes : Function WindowFromPoint(X As Long, Y As Long) As Long WindowFromPoint = WindowFromPointA(X, Y) End Function 'Purpose : Returns the window caption of a specified window. 'Inputs : lHwnd The handle of the window to determine the caption of. 'Outputs : Returns the window caption of a specified window. 'Author : Andrew Baker 'Date : 26/02/2001 21:21 'Notes : 'Assumptions : Function DialogGetCaption(lHwnd As Long) As String Const clMaxLen As Long = 255 Dim lLen As Long, sValue As String * clMaxLen lLen = GetWindowText(lHwnd, sValue, clMaxLen) If lLen Then DialogGetCaption = Left$(sValue, lLen) End If End Function 'Demonstration routine Sub Test() Dim lHwnd As Long lHwnd = WindowFromPoint(100, 100) If lHwnd Then Debug.Print "The window at point 100, 100 has the caption: " Debug.Print DialogGetCaption(lHwnd) End If End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder