If App.PrevInstance = True Then
        MsgBox "本程序已经运行,不能多次运行!", vbExclamation, "警告"
        End
    End If

解决方案 »

  1.   

    如何调用已经启动的实例?hurry,hurry,friends!
      

  2.   

    Public Const SW_RESTORE As Long = 9&
    Public Const GW_CHILD As Long = 5&
    Public Const GW_HWNDNEXT As Long = 2&
    Public Declare Function GetDesktopWindow& Lib "user32" ()
    Public Declare Function GetWindow& Lib "user32" (ByVal hwnd&, ByVal wCmd&)
    Public Declare Function GetWindowText& Lib "user32" Alias "GetWindowTextA" _
                                        (ByVal hwnd&, ByVal lpString$, ByVal cch&)
    Public Declare Function ShowWindow& Lib "user32" (ByVal hwnd&, ByVal nCmdShow&)
    Public Declare Function GetWindowRect& Lib "user32" (ByVal hwnd&, lpRect As RECT)
    Public Declare Function MoveWindow& Lib "user32" (ByVal hwnd&, ByVal X&, _
                              ByVal Y&, ByVal nWidth&, ByVal nHeight&, ByVal bRepaint&)
    Public Declare Function SetForegroundWindow& Lib "user32" (ByVal hwnd&)
    Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
                                             (ByVal lpClassName$, ByVal lpWindowName$)
      Const sBaseCaption As String = "登录窗口" 
      Const sBaseCaption1 As String = "FileManager"
    '以上换成您的application的title  
      If App.PrevInstance = True Then
          
          Dim hAppWindow&, sTemp$
          hAppWindow = GetWindow(GetDesktopWindow(), GW_CHILD)
          
          Do
            sTemp = String$(180, False)
            Call GetWindowText(hAppWindow, sTemp, 179)
      
            If InStr(sTemp, sBaseCaption) Then
               ActivatePrevInstance (hAppWindow) '使以前的窗口活动
              Exit Do
            End If
            
            If InStr(sTemp, sBaseCaption1) Then
               ActivatePrevInstance (hAppWindow) '使以前的窗口活动
              Exit Do
            End If
      
            ' 获得下一个子窗体
            hAppWindow = GetWindow(hAppWindow, GW_HWNDNEXT)
          Loop
      Else    '第一次运行时
        frmLogin.Show
      End IfPrivate Sub ActivatePrevInstance(ByVal hAppWindow&)  Call ShowWindow(hAppWindow, SW_RESTORE)  '使窗口活动
      Call SetForegroundWindow(hAppWindow)
      
      
    End Sub
      

  3.   

    Thanks gump for your timely reply.
    I have added score for you.have you received 20 points?
      

  4.   

    Dim name0 As String
        If App.PrevInstance = True Then
            name0 = App.EXEName
      res = MsgBox("该程序已运行,不能再次装载!", vbExclamation, name0)
            If res = vbYes Then
            Unload Me
            End If
        End If
      

  5.   

    another method to handle this proplem is using the registry to record the run times,check the value when loading,also easy way.