Results 1 to 4 of 4

Thread: Control Handles

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    2

    Question

    I know I can find the Handle for any windows application using the FindWindow API. What I don't know how to do is find the handle for a specific control in any running Windows application. I have written a simple VB program that gives me all the handles for the controls within an app in a list box. I can select an handle and see the child controls the list box. This usually works but is very tediuos.

    I have a friend who uses Delphi which came with a program called WinSight and he can see the handle of a controll by looking at the Messeages in WinSight when he clicks on it. I am wondering if there is some way using VB to capture the handle of a contol when it is clicked.

  2. #2
    Guest
    Maybe this thread will help?

  3. #3
    Guest
    Add to a Form with a Timer and 3 Labels. They will be used to display the ClassName, WindowName and handle.
    Code:
    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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    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 Type POINTAPI
        x As Long
        y As Long
    End Type
    
    Private Sub Form_Load()
        Timer1.Interval = 1
    End Sub
    
    Private Sub Timer1_Timer()
        Dim hWnd_Window As Long
        Dim sClassName As String * 255
        Dim sWindowName As String * 255
        Dim iLength As Integer
        Dim PT As POINTAPI
        
        GetCursorPos PT
        hWnd_Window = WindowFromPoint(PT.x, PT.y)
        iLength = GetClassName(hWnd_Window, sClassName, 255)
        sClassName = Left(sClassName, InStr(1, sClassName, vbNullChar))
        iLength = GetClassName(hWnd_Window, sWindowName, 255)
        sWindowName = Left(sWindowName, InStr(1, sWindowName, vbNullChar))
        
        Label1 = hWnd_Window        'Display the hWnd
        Label2 = sClassName         'Display the class name
        Label3 = sWindowName        'Display the window name
    End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    2
    OK, that worked. I can see the handle of the contol that the mouse is over in the label. Now if I take that specific handle and write it in text box called txtHandle, I should be able to use API to send a click event to that contol. I thought I knew how to do that but I guess I don't. I used the loops og i and j to make certain that it was not a specific location on the control that I needed to click. I don't get any response from the control.

    Private Sub cmdClickSpecific_Click()
    Dim hItemHandle As Long
    Dim PT As POINTAPI
    Dim retval As Long
    Dim i As Long
    Dim j As Long
    On Error GoTo err:
    For i = 1 To 1000 Step 1
    For j = 1 To 1000 Step 1
    hItemHandle = CLng(txtHandle.Text)
    PT.X = i
    PT.Y = j
    retval = SendMessage(hItemHandle, WM_LBUTTONDOWN, ByVal CLng(MK_LBUTTON), ByVal PT)
    retval = SendMessage(hItemHandle, WM_LBUTTONUP, ByVal CLng(0), ByVal PT)
    retval = SendMessage(hItemHandle, BM_SETSTATE, 1, ByVal 0&)
    DoEvents
    Next j
    Next i
    err:
    End Sub

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