开发者

Read data from form

This is a strange question, I've never tried to do this before.

I have a repetitive process requiring that I copy and paste data from text boxes in one program into another program for further processing. I'd like to automate this process using VB .NET. The application from which the data is gathered isn't mine, so I don't have ActiveX-like access to its controls.

How would you write an application to gain access to a form from another application, to be able to find the controls on the form, and gather the values from them?

Just experimenting, I've used the following code. This resulted in only the name of the form to which this code belongs. It didn't find the names of any other forms开发者_JAVA百科 I have open, and I have a lot open to choose from. This is frustrating because it's only step one of what I'll need to do to make my life easier...

Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As CallBack, ByVal lParam As Integer) As Integer
Public Delegate Function CallBack(ByVal hwnd As IntPtr, ByVal lParam As IntPtr) As Boolean


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim cb As New CallBack(AddressOf MyCallBack)
    EnumWindows(cb, 8)
End Sub

Public Function MyCallBack(ByVal hwnd As Long, ByVal lparam As Long) As Boolean
    Dim frm As System.Windows.Forms.Control
    frm = System.Windows.Forms.Form.FromHandle(hwnd)
    If frm Is Nothing Then Return True

    If frm.Text <> "" Then
        TextBox1.Text += frm.Text & ", "
    End If

    Return True
End Function

Does anyone have a recommendation?

Thanks, SH


System.Windows.Forms.Form represents only .NET forms, whereas most Win32 applications use native windows. You will have to use native Win32 functions to work with Win32 windows. If you want to get the window title, just pass the window handle directly to the Win32 GetWindowText function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜