VB .NET |与另一个程序的互动

时间:2013-11-01 23:38:21

标签: vb.net

如何与另外一个VB外部的程序“互动”? 例如。假设我想改变正在运行的程序的标题,例如Firefox或最小化/最大化它,是否可以这样做?

2 个答案:

答案 0 :(得分:3)

最有可能的情况是,您需要使用SendMessagePostMessage将Windows消息发送到其他窗口。

SendMessage的文档位于:http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx。这将告诉您可以使用SendMessage的所有不同方式。

PInvoke.NET将SendMessage函数的VB.NET签名显示为:

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
End Function

您可以在此处找到有关如何在VB.NET中使用SendMessage和PostMessage的更多信息:http://www.codeproject.com/Articles/19740/Send-strings-to-another-application-by-using-Windo

答案 1 :(得分:1)

所以,为了回答你的问题(再次,我认为罗伯特哈维有更彻底的答案),你需要做这样的事情:

Imports System.Diagnostics

Public Class ProcessWrapper

 Public Sub New() // This will likely be different for you, or you won't need it at all.
    MyBase.New()
 End Sub

 Public Function Start(ByVal someProcess As String) As ProcessInfo // Define process here.
    Dim p As Process = Process.Start(someProcess)  // Invoke your process here.
    Return New ProcessInfo(p)  // Return your ProcessInfo object here.
 End Function

End Class

快乐编码,欢迎来到SO!