'  确定是否当前程序已经在运行。返回 0 没有，否则返回上1个进程ID
#Include  Once "win\tlhelp32.bi"
Function FF_PrevInstance() As uLong
   Dim p As WINBOOL
   Dim Proc as PROCESSENTRY32, hSnap as HANDLE
   hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, Null)
   If hSnap = 0 Then Return 0
   Proc.dwSize = SizeOf(PROCESSENTRY32)
   Dim ap As String = app.Path & app.EXEName, ab as String
   Dim appi as long = GetCurrentProcessId
   p = Process32Firsta(hSnap, @Proc)
   While p
      'If Proc.th32ProcessID >10 Then
      If Proc.th32ProcessID <> appi Then
         ab = AfxGetPathFromProcessId(Proc.th32ProcessID)
         if ap = ab then
            Function = Proc.th32ProcessID
            Exit While
         End if
      end if
      'End If
      p = Process32Next(hSnap, @Proc)
   Wend
   CloseHandle hSnap
   
End Function

