Results 1 to 6 of 6

Thread: Accessing other apps

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    81

    Cool

    Hi everyone!

    My question is simple. The answer is probably less simple. Is it possible to access the text in a textbox in ANOTHER application? I need a method of converting the text in a textbox in another application to a string, and I can't for the life of me work out how to do it. I'm thick.

    Thanx in advance,

    Sam

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    It is possible. You would have to find the window handle (hWnd) of the application first (you have to know the ClassName or atleast the Caption of the application you're looking for), then find the Textbox in the application, then get the text from the textbox. This is "How to get the text from another app in a nut shell". Here's an example. This example will get the text from the Notepad. Add a Textbox (set it's Multiline proprety to True) and a Command button:
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
    Private Const WM_GETTEXT = &HD
    Private Const WM_GETTEXTLENGTH = &HE
    
    Private Sub Command1_Click()
        Dim lngHwnd As Long
        Dim lngTextbox As Long
        Dim strBuffer As String
        Dim lngTextLength As Long
        Dim lngResult As Long
        
        'Find Notepad window (the classname is "Notepad")
        lngHwnd = FindWindowEx(0, 0, "Notepad", vbNullString)
        'Find the textbox (the classname is "Edit")
        lngTextbox = FindWindowEx(lngHwnd, 0, "Edit", vbNullString)
        
        'Get the length of the text
        lngTextLength = SendMessage(lngTextbox, WM_GETTEXTLENGTH, 0, 0)
        'Prepare buffer's length
        strBuffer = Space(lngTextLength)
        'Get the text from the Notepad
        lngResult = SendMessageString(lngTextbox, WM_GETTEXT, lngTextLength, ByVal strBuffer)
    End Sub

  3. #3
    Lively Member Ishamel's Avatar
    Join Date
    Nov 1999
    Location
    Edinburgh, Scotland
    Posts
    112
    Serge,

    You seem to be pretty clued up on accessing external applications.

    Do you have any idea why myself and Nitro are having this problem??

    http://forums.vb-world.net/showthrea...threadid=19275

    Any help would be greatly appreciated.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    81

    Exclamation More questions

    Serge,

    that code is perfect, except for one thing - how do I find the ClassName of the text box that I want to access?

    Thanks tons,

    SamDV

  5. #5
    Guest
    To find class, a handle, or any basic need to use other windows, download an winapi spy. I recommend you use Patorjk's api spy: http://www.patorjk.com/downloads/apispy50.zip
    Works great.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    81

    Talking Nice...

    And what a clever little application it is as well!



    Cheers!

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