程序只运行一个实例,再次双击时把前一个激活的功能怎么实现?谢谢最好能给出代码,谢谢了

解决方案 »

  1.   

    app对象里有一个属性是判断是不是有实例运行的,用过吗?
      

  2.   

    If App.PrevInstance = True Then
    Dim cap As String
    cap = Me.Caption
    Me.Caption = Me.Caption & "1"
    MsgBox "程序已经在运行"
    AppActivate cap, True
    Unload MeExit Sub
    End If
      

  3.   

    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As LongConst SW_RESTORE = 9Private Const OPEN_APPLICATION = 0
    Private Const SINGLE_INSTANCE_OPEN = 1Sub Main()
    Dim MultiInstResult As IntegerMultiInstResult = MultiInstIf MultiInstResult = OPEN_APPLICATION Then
         Form1.Show  
    ElseIf MultiInstResult = SINGLE_INSTANCE_OPEN Then
        End
    End If
    End SubPrivate Function MultiInst() As IntegerDim hwndFound As Long   
    Dim strWindowName       strWindowName = App.Title
    App.Title = "temp title"  
    hwndFound = FindWindow(vbNullString, strWindowName)If hwndFound Then
         MultiInst = SINGLE_INSTANCE_OPEN
         MsgBox "A instance of the application is already open." & vbCrLf & vbCrLf & "Only one open instance allowed.", vbOKOnly + vbExclamation, "App Name"     If IsIconic(hwndFound) Then
              ShowWindow hwndFound, SW_RESTORE
              SetForegroundWindow hwndFound
         Else
              SetForegroundWindow hwndFound
        End If
    ElseIf hwndFound = 0 Then
        App.Title = strWindowName
        MultiInst = OPEN_APPLICATION
    End If
    End Function
      

  4.   

    又是api 我一见他头就大!! 可不用还不行!!??
      

  5.   

    在下面的帖子上,我用DDE来实现的,不过我还是认为用API 比较好
    http://expert.csdn.net/Expert/topic/2689/2689086.xml?temp=.5642053
      

  6.   

    参考:
    http://expert.csdn.net/Expert/topic/2683/2683490.xml?temp=.7050135
    自己加上对命令行的处理