Results 1 to 8 of 8

Thread: Read text of a label from anther app?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Read text of a label from anther app?

    Hey!

    Is it possible to read a label's text property of another app?
    I know how to get the handle of the main window, and i got the code for the child.

    But the problem is that there's like 20 other labels on the window and when i use winID to get it's class, it's just "Edit", and it's the same for all the labels. And the title is the value of the labels text property.

    Any help?
    Attached Images Attached Images  

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Read text of a label from anther app?

    Take a look at the code I posted in this thread:

    http://www.vbforums.com/showthread.php?t=522896

    In particular, notice the repeated calls to FindWindowEx. The basic idea is that if you have 20 labels, and the one you want is label N, then it will ALWAYS be label N. You can then use FindWindowEx passing in the first handle, then the next handle, and so on for N-1 tries, and the next call will return the handle for label N. In the code I posted in that thread, the textbox I wanted was the third one, or something like that, and with so few, I just unrolled the loop and called FindWindowEx three times, but if N was higher, it would probably be easier to run the code in a loop.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Re: Read text of a label from anther app?

    Hello Shaggy.

    Well i have been studying the code, but i just don't see how i'm going to use it.
    What i understand (pretty sure it's wrong), is that it loops through all the labels by using the retrieved handle into a new FindWindowEx call? Or how?

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Read text of a label from anther app?

    I was hoping you wouldn't ask that, as the code was written about six years ago, and I have forgotten too much about it. Have you used Spy++ to take a look at the form in question? The target tool in Spy++ is neat, but not necessarily all that useful in this case. However, the treeview display of all the windows classes should be useful. I was using this display to design the code in that post. I saw that under a certain form, there were a string of controls that appeared to all have the same class type (that ATLfpOCXComboBox30). I then looped a call to FindWindowEx that passed in the last handle returned (from the last iteration of the loop) as the second argument. I can't currently find a reference for FindWindowEx, but I assume that the second argument tells FindWindowEx where to start looking for a class with the name that is passed in the third argument.

    If you use Spy++, you should see that each label is a window, and see many labels with the same class type. If you can figure out which of those is the one you want (perhaps the target tool would help with that), then you can perform a similar loop to the one I had to make, to find the correct instance of the label class.

    Does that help?
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Re: Read text of a label from anther app?

    Well i started up spy++ instead of winID, and there's a lot of other properties, but not anyone i can think of can be used. Only one was the control id, but i don't think it can be used....

  6. #6
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Read text of a label from anther app?

    What i did was write the labels text to a textfile on closing the form and then simply read the textfile for the second app to use.

    But maybe that will not suit your circumstance

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Re: Read text of a label from anther app?

    No it won't, because i didn't write the app

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Re: Read text of a label from anther app?

    bump

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