Results 1 to 2 of 2

Thread: Get the hwnd of the window under the mouse

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Location
    Ohio
    Posts
    1
    can anyone tell me how to get the hwnd of whatever program happens to be under the mouse. say i have the mouse cursor over calc.exe when its running. how can i get the hwnd of it or of anything that the mouse is over? (must be with mouse over)

    -joel

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb make your own Spy++

    Are you going to make your own Spy++?

    I just something that sound like what you mention and hope it what you looking for.

    If you want the sample program, just email me and I'll send you a copy.

    Code:
    'Code under Basic Module
    Public Sub Get_WindowInfo()
    On Error GoTo Get_Info_Err
    Dim xhWnd As Long
    Dim xWndText As String
    Dim xWndClass As String
    Dim xReturn As String
        
        'GetWindows Handle
        GetCursorPos xPt
        xhWnd = WindowFromPoint(xPt.X, xPt.Y)
        'Get Windows Caption
        If xhWnd <> 0 Then
            frmMain.lblWindowHwnd.Caption = "Window hWnd: " & xhWnd
            xReturn = String(255, Chr(0))
            If GetWindowText(xhWnd, xReturn, 100) Then
                xWndText = Left(xReturn, InStr(1, xReturn, Chr(0), vbBinaryCompare) - 1)
            End If
        Else
            frmMain.lblWindowHwnd.Caption = "Window hWnd: Not Available"
        End If
        frmMain.lblWindowText.Caption = "Window Text: " & xWndText
        
        'GetWindowClass Name
        If xhWnd <> 0 Then
            xReturn = String(255, Chr(0))
            If GetClassName(xhWnd, xReturn, Len(xReturn)) <> 0 Then
                frmMain.lblClassName.Caption = "Window Class Name: " & Left(xReturn, InStr(1, xReturn, Chr(0), vbBinaryCompare) - 1)
            Else
                frmMain.lblClassName.Caption = "Window Class Name:"
            End If
        End If
    
    Exit Sub
    Get_Info_Err:
        frmMain.lblWindowText.Caption = "Window Caption:"
        frmMain.lblWindowHwnd.Caption = "Window hWnd:"
        frmMain.lblClassName.Caption = "Window Class Name:"
    End Sub
    
    'Code under Form
    Option Explicit
    Private Scan As Boolean
    Private Sub ImgScan_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        Scan = True
        Screen.MouseIcon = ImgScan.Picture
        Screen.MousePointer = vbCustom
    End If
    End Sub
    
    Private Sub ImgScan_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Scan Then Get_WindowInfo
    End Sub
    
    Private Sub ImgScan_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Scan = False
    Screen.MousePointer = vbDefault
    End Sub
    I just amended my code.



    [Edited by Chris on 06-17-2000 at 04:55 AM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width