双进程互相监控-vb

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal

lpWindowName As String) As Long

Private Sub Form_Load()
Me.Caption = "APPa"
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
If FindWindow(vbNullString,"APPb") = 0 Then Shell "APPb.exe",vbnormalFocus
End Sub

'用以上代码生成“APPa.exe”
'=========================================================================
'用以下代码生成“APPb.exe”

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal

lpWindowName As String) As Long

Private Sub Form_Load()
Me.Caption = "APPb"
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
If FindWindow(vbNullString,"APPa") = 0 Then Shell "APPa.exe",vbnormalFocus
End Sub

'两个exe放在同一路径下,从此“APPa”和“APPb”一起过着幸福快乐的日子^_^

以上使用了timer.

一个没有使用timer

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Long


Private Sub Form_Load()
Dim Doloop As Boolean
Me.Caption = "APPa"

Do
DoEvents
If FindWindow(vbNullString,vbnormalFocus
Loop Until Doloop = True

End Sub


'用以上代码生成“APPa.exe”
'=========================================================================
'用以下代码生成“APPb.exe”
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Long


Private Sub Form_Load()
Dim Doloop As Boolean
Me.Caption = "APPb"

Do
DoEvents
If FindWindow(vbNullString,vbnormalFocus
Loop Until Doloop = True

End Sub

'无敌版.....

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...