防止重复运行程序并且激活当前正在运行的窗口

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

Private Sub Form_Load()
    Dim appCaption$, firstPopHWnd&
    If App.PrevInstance Then
        appCaption = Me.Caption
        Me.Caption = appCaption & " "
        firstPopHWnd = FindWindow("ThunderRT6FormDC", appCaption)
        SetForegroundWindow firstPopHWnd&
        End
    End If
End Sub

原文地址:https://www.cnblogs.com/sysdzw/p/1939381.html