문제

So, I'm trying to capture a window which has 2 textboxes and send some text to both these textboxes. But both textboxes have no caption and the same class name "Edit". So far all I am able to do is capture the first textbox and thats it.

Pasted below is my code.

Imports System.Runtime.InteropServices
Imports System.Text

Public Class Form1

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
     ByVal lParam As String) As Integer

    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, _
     ByVal lpsz2 As String) As Integer

    Private Const WM_SETTEXT As Integer = &HC

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As  _
    System.EventArgs) Handles Button1.Click

        Dim hwnd As Integer
        Dim txt As Integer
        Dim text As String

            hwnd = FindWindow(vbNullString, "Description")
            If hwnd <> Nothing Then
                txt = FindWindowEx(hwnd, 0, "Edit", vbNullString)
                If txt <> Nothing Then
                    text = "00000"
                    SendMessage(txt, WM_SETTEXT, 0, text)
                End If
            End If

    End Sub

End Class
도움이 되었습니까?

해결책

Use the second parameter to FindWindowEx() called "hwndChildAfter":

A handle to a child window. The search begins with the next child window in the Z order. The child window must be a direct child window of hwndParent, not just a descendant window.

So you should be able to pass the first textbox handle in to get the next one like this:

txt2 = FindWindowEx(hwnd, txt, "Edit", vbNullString)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top