我需要在 VB.NET MDI 窗体中打开一些外部应用程序,例如 notepad.exe,并且我需要确保始终只有一个副本在运行。
我使用了下面的代码,但它完全没有任何作用。它给出了错误 SetParent is not declared and findWindow is not declared
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,但它不检查以前的实例。所以每次我点击按钮它都会打开一个新的记事本