Reading from a text field in another application's window

后端 未结 7 1236
逝去的感伤
逝去的感伤 2020-11-30 23:16

Is there a way for a Windows application to access another applications data, more specifically a text input field in GUI, and grab the text there for processing in our own

相关标签:
7条回答
  • 2020-12-01 00:10

    Yes it is possible in many ways (one way is to use WINAPI GetWindow and GetWindowText).

    First, get a handle to the textbox you want to retrieve text from (using FindWindow, EnumChildWindows and other APIs), then:

    Old VB6-codeexample, declaration of API:

    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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long  
    

    Code to extract text:

    Dim MyStr As String
    MyStr = String(GetWindowTextLength(TextBoxHandle) + 1, Chr$(0))
    GetWindowText TextBoxHandle, MyStr, Len(MyStr)
    MsgBox MyStr
    
    0 讨论(0)
提交回复
热议问题