用多媒体定时器吧。 Option ExplicitPublic lTimerId As Long Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As LongPrivate Sub TimerProc(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lTimerId As Long, ByVal lTime As Long) '写入你的代码 End SubPublic Sub StartTimer(lMinute As Long) lTimerId = SetTimer(0, 0, lMinute, AddressOf TimerProc) End SubPublic Function StopTimer(lTimerId As Long) As Long StopTimer = KillTimer(0, lTimerId) End Function
moudle1.basPublic Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function FlashWindow Lib "user32" (ByVal hWnd As Long, ByVal bInvert As Long) As Long Public Const FlashTime = 10 Public ft As Integer Sub Main() If FindWindow(vbNullString, "Myform") <> 0 Then ft = 1 Load Myform Myform.Timer1.Enabled = True Else Load Myform Myform.Show End If
End Subtimer控件:(初始值:timer1.enabled=false) Private Sub Timer1_Timer() Dim hWnd As Long hWnd = FindWindow(vbNullString, "myform") ft = ft + 1 Call FlashWindow(hWnd, True) If ft = FlashTime Then Call FlashWindow(hWnd, False) Timer1.Enabled = False Unload Me End If End Sub
试试看~Option ExplicitPublic Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function FlashWindow Lib "user32" (ByVal hWnd As Long, ByVal bInvert As Long) As Long Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Sub Main() If App.PrevInstance Then Dim hWnd As Long, i As Integer hWnd = FindWindow(vbNullString, "Form1") For i = 1 To 10 If FlashWindow(hWnd, True) Then Exit For Call Sleep(500) Next Call FlashWindow(hWnd, False) End Else Dim tForm As New Form1 tForm.Show End If End Sub
FindWindow然后FlashWindow就可以了~
Option ExplicitPublic lTimerId As Long
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As LongPrivate Sub TimerProc(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lTimerId As Long, ByVal lTime As Long)
'写入你的代码
End SubPublic Sub StartTimer(lMinute As Long)
lTimerId = SetTimer(0, 0, lMinute, AddressOf TimerProc)
End SubPublic Function StopTimer(lTimerId As Long) As Long
StopTimer = KillTimer(0, lTimerId)
End Function
Public Declare Function FlashWindow Lib "user32" (ByVal hWnd As Long, ByVal bInvert As Long) As Long
Public Const FlashTime = 10
Public ft As Integer
Sub Main()
If FindWindow(vbNullString, "Myform") <> 0 Then
ft = 1
Load Myform
Myform.Timer1.Enabled = True
Else
Load Myform
Myform.Show
End If
End Subtimer控件:(初始值:timer1.enabled=false)
Private Sub Timer1_Timer()
Dim hWnd As Long
hWnd = FindWindow(vbNullString, "myform")
ft = ft + 1
Call FlashWindow(hWnd, True)
If ft = FlashTime Then
Call FlashWindow(hWnd, False)
Timer1.Enabled = False
Unload Me
End If
End Sub
Public Declare Function FlashWindow Lib "user32" (ByVal hWnd As Long, ByVal bInvert As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Sub Main()
If App.PrevInstance Then
Dim hWnd As Long, i As Integer
hWnd = FindWindow(vbNullString, "Form1")
For i = 1 To 10
If FlashWindow(hWnd, True) Then Exit For
Call Sleep(500)
Next
Call FlashWindow(hWnd, False)
End
Else
Dim tForm As New Form1
tForm.Show
End If
End Sub