1
我在我的电脑上运行了一个应用程序。 我可以得到该应用程序的每一个细节(手柄,mainwindowhandle等)从不同的应用程序中读取标签中的文本
而且该应用程序有很多的标签,我想阅读标签和MSGBOX在我自己的应用程序的字符串。
我在我的电脑上运行了一个应用程序。 我可以得到该应用程序的每一个细节(手柄,mainwindowhandle等)从不同的应用程序中读取标签中的文本
而且该应用程序有很多的标签,我想阅读标签和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
和我如何会得到一个标签的手柄从另一个应用程序? – sarkolata
@sarkolata你的文章说你有应用程序的每一个细节,包括手柄。你有什么细节? – LarsTech
对我的帖子感到抱歉,我看到它的误解。 我可以得到主窗口句柄,主窗口标题等。 (所有从system.diagonistics.process类获取属性) 我已经从我的vb.net程序启动应用程序。 – sarkolata