views:

115

answers:

2

Hey all, i am trying to figure out how to go about finding this window's label when the control name is the same as all the other labels on the program.

WindowsForms10.STATIC.app.0.378734a
WindowsForms10.STATIC.app.0.378734a
WindowsForms10.STATIC.app.0.378734a

All 3 labels are named the same. The one i am most interested in is a progress % counter (1%, 2%, 3%, etc..)

How can i get the value (using a timer of course) from that label without knowing the caption of it at any given time??

Any help would be great! :o)

David

A: 

The obvious answer would be to get the text from all three labels and check which one looks like "1%", "55%" etc.

If strText Like "#%" Or strText Like "##%" Or strText = "100%" Then
' ...

The less obvious answer (if the Windows API is too cumbersome for your requirements) would be to use the Microsoft UI Automation API.

Hugh Allen
Hum, the problem with you're soluction is that i am unable to find the text in the first place in the other application since all 3 text labels are named the same name **WindowsForms10.STATIC.app.0.378734a**
StealthRT
"WindowsForms10.STATIC.app.0.378734a" is surely the class name, not the window text? (GetClassName vs GetWindowText)
Hugh Allen
@StealthRT: sorry, forgot to address my comment "@" you.
Hugh Allen
A: 

Not sure if you're just looking for a more complete code sample, but here you go.

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    'This block of code creates a list of all the labels on my form.
    'Replace this with code to get a list of labels on the form you are scraping
    Dim LblList As New List(Of Label)

    For Each ctrl As Control In Me.Controls
        If TypeOf ctrl Is Label Then
            LblList.Add(CType(ctrl, Label))
        End If
    Next
    'End

    Dim ProgressLblTxt As String = String.Empty
    For Each lbl As Label In LblList
        If lbl.Text.Contains("%") Then 'You could use several different criteria here as mentioned in the previous answer
            ProgressLblTxt = lbl.Text
        End If

        If ProgressLblTxt <> String.Empty Then Exit For
    Next

    'Do something with ProgressLblTxt
    MsgBox(ProgressLblTxt)
End Sub
brad.huffman
It's not on the same form! its a septate program running!
StealthRT
I understand that. That's why I commented that you should replace my block of code that gets the labels in to that list with your own code that scrapes the screen of the other app.
brad.huffman