Vb.net 从不同的应用程序读取标签中的文本

Vb.net 从不同的应用程序读取标签中的文本,vb.net,gettext,handle,hwnd,Vb.net,Gettext,Handle,Hwnd,我的电脑里有一个应用程序。 我可以获得该应用程序的每个细节(句柄、mainwindowhandle等) 该应用程序有很多标签,我想在我自己的应用程序中读取该标签和msgbox字符串。您可以尝试以下内容(已经很好地介绍了): _ 私有共享函数GetWindowText(ByVal hwnd作为IntPtr,ByVal lpString作为StringBuilder,ByVal cch作为Integer)作为整数 端函数 _ 私有共享函数GetWindowTextLength(ByVal hwnd作

我的电脑里有一个应用程序。 我可以获得该应用程序的每个细节(句柄、mainwindowhandle等)

该应用程序有很多标签,我想在我自己的应用程序中读取该标签和msgbox字符串。

您可以尝试以下内容(已经很好地介绍了):

_
私有共享函数GetWindowText(ByVal hwnd作为IntPtr,ByVal lpString作为StringBuilder,ByVal cch作为Integer)作为整数
端函数
_
私有共享函数GetWindowTextLength(ByVal hwnd作为IntPtr)作为整数
端函数
私有子按钮1\u单击(发送者作为对象,e作为事件参数)处理按钮2。单击
作为整数的Dim长度=GetWindowTextLength(其他ApplabelHandle)
将sb调整为新的StringBuilder(长度+1)
GetWindowText(其他ApplabelHandle、sb、sb容量)
MessageBox.Show(sb.ToString())
端接头
您可以尝试以下方法(已详细介绍):

_
私有共享函数GetWindowText(ByVal hwnd作为IntPtr,ByVal lpString作为StringBuilder,ByVal cch作为Integer)作为整数
端函数
_
私有共享函数GetWindowTextLength(ByVal hwnd作为IntPtr)作为整数
端函数
私有子按钮1\u单击(发送者作为对象,e作为事件参数)处理按钮2。单击
作为整数的Dim长度=GetWindowTextLength(其他ApplabelHandle)
将sb调整为新的StringBuilder(长度+1)
GetWindowText(其他ApplabelHandle、sb、sb容量)
MessageBox.Show(sb.ToString())
端接头

我将如何从另一个应用程序中获取标签的句柄?@sarkolata你的帖子说你拥有该应用程序的所有细节,包括句柄。你有什么细节?啊,对不起,我的帖子,我看它有误解。我可以获取mainwindowhandle、mainwindowtitle等(所有属性都来自system.Diagistics.process类)我已经从我的vb.net程序启动了应用程序。我将如何从另一个应用程序中获取标签句柄?@sarkolata你的帖子说你拥有应用程序的所有细节,包括句柄。你有什么细节?啊,对不起,我的帖子,我看它有误解。我可以获取mainwindowhandle、mainwindowtitle等(所有属性都来自system.Diagistics.process类),我已经从vb.net程序启动了应用程序。
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer
End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button2.Click
  Dim length As Integer = GetWindowTextLength(otherAppLabelHandle)
  Dim sb As New StringBuilder(length + 1)
  GetWindowText(otherAppLabelHandle, sb, sb.Capacity)
  MessageBox.Show(sb.ToString())
End Sub