我需要在VB.NET MDI窗体中打开一些外部应用程序,例如notepad.exe,并且我还需要确保始终只有一个此运行的副本。在VB.NET MDI窗体中打开外部应用程序表单
我使用下面的代码,但它完全没有。它给出了错误的setparent不宣而FindWindow函数未声明
Dim myProcess As Process = New Process()
Dim MyHandle As IntPtr
myProcess.StartInfo.FileName = "Notepad.exe"
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myProcess.Start()
MyHandle = FindWindow(vbNullString, "C:\Windows\Notepad.exe")
SetParent(MyHandle, Me.Handle)
myProcess.WaitForExit()
这是我用来验证只有一个实例运行
If (System.Diagnostics.Process.GetProcesses.Equals("notepad.exe")) Then
MsgBox("Only One Instance!")
Else
Dim p As New System.Diagnostics.Process
p.StartInfo.FileName = "notepad.exe"
p.Start()
End If
此代码是开放的notepad.exe的代码,但它不检查以前的实例。所以每次点击按钮,它都会打开一个新的记事本