双进程互相监控-vb

前端之家收集整理的这篇文章主要介绍了双进程互相监控-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

'无敌版.....

猜你在找的VB相关文章