' This Visual Basic 6 project requires a textbox called Text1 and a timer called Timer1 Private Type POINTAPI X As Long Y As Long End Type Private Type RECT Left As Long Top As Long Right As Long Bottom 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 ExtTextOut Lib "gdi32" Alias "ExtTextOutA" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal wOptions As Long, ByVal lpRect As Any, ByVal lpString As String, ByVal nCount As Long, lpDx As Long) As Long Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As POINTAPI) As Long Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd 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 Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long Private Sub Form_Load() Timer1.Interval = 100 Timer1.Enabled = True End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim pt As POINTAPI, mwnd As Long, WR As RECT, nDC As Long Dim TextSize As POINTAPI, CX As Long, CY As Long Dim s As String 'Get the current cursor position GetCursorPos pt 'Get the window under the cursor mwnd = WindowFromPoint(pt.X, pt.Y) 'Get the window's position GetWindowRect mwnd, WR 'Get the window'zs device context nDC = GetWindowDC(mwnd) 'Get the height and width of our text s = "ExtTextOut" GetTextExtentPoint32 nDC, s, Len(s), TextSize For CX = 1 To WR.Right - WR.Left Step TextSize.X For CY = 1 To WR.Bottom - WR.Top Step TextSize.Y 'Draw the text on the window ExtTextOut nDC, CX, CY, 0, ByVal 0&, s, Len(s), ByVal 0& Next Next End Sub Private Sub Form_Paint() Me.CurrentX = 0 Me.CurrentY = 0 Me.Print "Click on this form, hold the mouse button," & vbCrLf & _ "drag the mouse over another window and release the mouse button." + vbCrLf & _ "Move mouse on the screen to see the title of other windows." End Sub Private Sub Timer1_Timer() On Error Resume Next Dim pt As POINTAPI Dim mwnd As Long Dim s As String ' get the cursor pos GetCursorPos pt 'Get the window under the cursor mwnd = WindowFromPoint(pt.X, pt.Y) s = String(200, " ") GetWindowText mwnd, s, 100 s = Trim(Left$(s, InStr(s, Chr$(0)) - 1)) Text1.Text = CStr(pt.X) & "," & CStr(pt.Y) & ": " & s If Len(s) > 0 Then SetWindowText Me.hwnd, "Mouse over: " & s End Sub