我有一个在我的电脑上工作的应用程序。我可以获得该应用程序的每个细节(句柄、主窗口句柄等)
那个应用程序有很多标签,我想在我自己的应用程序中读取那个标签和 msgbox 那个字符串。
你可以试试这个(pinvoke已经很好地覆盖了):
<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