Results 1 to 4 of 4

Thread: Reading text from a foreign control...

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Unhappy Reading text from a foreign control...

    I haven't used Visual Basic since high school and I am a little rusty. I require the api code that will let me read a label on a foreign program and save it into a variable. Basically, I need my program to do what spy++ does, but only with a specific program and a specific label. Any guidance would be much appreciated.

    Thank you.

    Justin V.

  2. #2
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Reading text from a foreign control...

    do some searches in these forums, there are many examples.
    Use findwindow, findwindowex and sendmessage WM_GETTEXT

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,242

    Re: Reading text from a foreign control...

    Use spy++ first off. FindWindow and FindWindowEx will help you get the correct control, but first off you want to figure out what to look for. Since you mention spy++, I would assume you have already used it a few times. You may have noticed that whenever you open the program, you can figure out which window you will need based on the caption, or the window type (less reliable, since it could be duplicated).

    Then you will want these functions:

    VB Code:
    1. Declare Ansi Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    2.     Declare Ansi Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Integer, ByVal lpString As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer
    3.     Declare Ansi Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Integer, ByVal hWndChildAfter As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

    However, this is from VB.NET, not vb6. If you are using VB6, you will want to use Longs in place of the Integers.

    That's a start. If you want an example, I could post one.
    My usual boring signature: Nothing

  4. #4
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Reading text from a foreign control...

    shaggy hiker could u show me a working example of getting text from external window that we know itss caption and class name using vb6?Thanks

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