1 如何避免一程序重复运行?
2 当一程序已经运行,如何再点击那个程序时,不再运行这个程序,而是将已运行的程序调出来。比如FrontPage或FoxMail。

解决方案 »

  1.   

    If App.PrevInstance Then
            MsgBox ("程序已经运行,不能再次装载。"), vbExclamation
            End
        End If
      

  2.   

    If App.PrevInstance Then
            msgbox "程序已运行!"
        End If
      

  3.   

    关于避免重复执行的问题:
      1。如楼上的。(只能控制在同一路径下同一个程序,如果把该程序拷贝到不同路径就不行了 )
      2。通过API:(缺陷:该方法必须要求有界面,并且知道主界面的标题)
         for example:
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPublic Declare Function BringWindowToTop Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As Long) As LongPublic Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long  dim whether_run as boolean
      whether_run =findwindow(0,"Main Form's title")
       if  whether_run<>0 then
          bringwindowtotop(whether_run)
          showwindow(whether_run ,3)
       end if
      

  4.   

    If App.PrevInstance Then End
      

  5.   

    2 当一程序已经运行,如何再点击那个程序时,不再运行这个程序,而是将已运行的程序调出来。比如FrontPage或FoxMail。