0

I'm trying to get information from a windows form of another application.

I can read data from textbox or label of this application but not from a PANEL,because this panel doesnt contain controls.

I need your suggestions.

Thanks in advance. Here the code that i'm using :

  For Each top As windowsAPIoutils.ApiWindow In enumerator.GetTopLevelWindows()
        For Each child As windowsAPIoutils.ApiWindow In enumerator.GetChildWindows(top.hWnd)
            If top.MainWindowTitle.StartsWith("TITLE_Of_APPLICATION") Then
               'The class name of the control
                If child.ClassName = "TEdit"  Then

                    textbox1.Text = child.MainWindowTitle 

                End If
            End If


        Next child
    Next top
vertebre
  • 19
  • 4
  • Please be a lot more precise. And give a code example. – Sebastian Mar 11 '13 at 10:43
  • i was using Win32API to get text content.It works but when i want to get text from panel,it's not possible. – vertebre Mar 11 '13 at 10:46
  • That doesn't help, you have to give some code. – Sebastian Mar 11 '13 at 10:47
  • I think that you can do a method that communicate with other method in some style. For example, a related post is http://www.vb-helper.com/howto_get_other_app_text.html. However, your question is very ambiguous and you must to decide how this two application communicate with each other. – Mihai8 Mar 11 '13 at 10:50
  • hello user1929959,I want to copy a displayed text from an application to a textbox.This can be possible when the displayed text is in a 'control' like (textbox,label,combobox),but impossible when it's in 'PANEL'.Thanks – vertebre Mar 11 '13 at 11:47

2 Answers2

4

The only way that you can use the Win32 API to do this is if the item whose text you want to grab is a Win32 control, backed by an actual window.

That's why it works fine if the other item is a textbox or a label, because those are both implemented using Win32 EDIT and STATIC controls, respectively.

I don't know exactly what you mean by a "panel", but my guess is that it has been custom drawn by the other application. You'll therefore need to ask that application for the text it contains. Windows cannot give it to you because it is not a standard Windows control. If you cannot ask the other application, for whatever reason, you will need to research alternative methods, like UI automation.

If by "panel", you mean a group box, well then that is just a standard Windows button control and it has a caption (displayed at the top). You can retrieve that in the same way you'd retrieve the caption of a label control. In Win32 terms, that means sending a WM_GETTEXT message to the control.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • Thank your for your help. The panel that i'm talking about is a "TPANEL" because the application is in Delphi.I'm trying using OCR,hope it will solve my problem – vertebre Mar 12 '13 at 15:29
0

Here is a solution that i used: Tesseract an open source OCR engine and here the link to get it : https://code.google.com/p/tesseract-ocr/

how to use it :

Imports System.IO
Imports System.Threading
Imports System.Collections.Specialized

Public class myClass

Private ProcessList As New Hashtable

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)     Handles Button.Click
Dim croppedFile as String = "C:\image.tif"
Dim OCRProcess As Process = New Process()
OCRProcess.StartInfo.FileName = "C:\tesseract\tesseract.exe"
OCRProcess.StartInfo.Arguments = croppedFile & " " & croppedFile & " -l eng"
OCRProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
OCRProcess.StartInfo.CreateNoWindow = True
OCRProcess.EnableRaisingEvents = True
AddHandler OCRProcess.Exited, AddressOf Me.ProcessExited
OCRProcess.Start()
ProcessList.Add(OCRProcess.Id.ToString, croppedFile & ".txt")
Do While Not OCRProcess.HasExited
    Application.DoEvents()
Loop
End Sub

Friend Sub ProcessExited(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Proc As DictionaryEntry
Dim oRead As StreamReader
Dim EntireFile As String = ""
For Each Proc In ProcessList
    If (sender.id.ToString = Proc.Key) Then
        oRead = File.OpenText(Proc.Value)
        EntireFile = oRead.ReadToEnd()
    End If
Next
MsgBox(EntireFile)
End Sub

End Class

Hope it will help someone

vertebre
  • 19
  • 4