查下app有个属性,可以知道是否已运行了,

解决方案 »

  1.   

    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function SetForegroundWindow& Lib "user32" (ByVal hwnd&)
    Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As LongPrivate Const WA_ACTIVE = 1
    Private Const WA_CLICKACTIVE = 2
    Private Const WA_INACTIVE = 0
    Private Const WM_ACTIVATE = &H6
    Private Const WM_ACTIVATEAPP = &H1CPrivate Const WM_SHOWWINDOW = &H18Private Const SW_SHOW = 5
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_RESTORE = 9
    Private Sub Form_Load()
        Dim lIns As Long
        Dim lWnd As Long
        Dim lRet As Long
        
        Me.Caption = ""
        If App.PrevInstance = True Then
            Debug.Print App.hInstance
            lIns = App.hInstance
            lWnd = FindWindow(vbNullString, "Alive")
            lRet = SetWindowText(lWnd, "Alive")
            lRet = ShowWindow(lWnd, SW_SHOWNORMAL)
            lRet = SetForegroundWindow(lWnd)
            Unload Me
            Exit Sub
        End If
        Me.Caption = "Alive"    
    End Sub这个例子,可以唤醒已经运行的程序
    你说的判断是否有实例运行,是由App.PrevInstance完成的
      

  2.   

    If App.PrevInstance = True Then
       MsgBox "此程序正在运行!"
       ------ 
       Exit Sub
    End If"-----"处应该怎么写才能让应用程序处于最前端?