我用互斥体使得程序只可以运行一个实例,但是我想在有实例运行的情况下,在点击可执行文件时该执行文件标题闪烁(用FlashWindow)几下,以起到提示作用,该怎么办?
我想关键是在SUB MAIN 中触发定时器事件吧
假设程序的标题固定,且唯一,则可以由FindWindow找到其句柄.
请各位高手帮忙.

解决方案 »

  1.   

    你在sub main里面用个循环不行吗?
      

  2.   

    如果App.PrevInstance
    FindWindow然后FlashWindow就可以了~
      

  3.   

    用多媒体定时器吧。
    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
      

  4.   

    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
      

  5.   

    试试看~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