vb怎么判断当前程序是否正在运行?
我已经生成了一个exe文件,现在想实现功能:第一次运行后,再次双击exe文件,不再开始运行新的程序,而是打开已经运行的exe程序的窗口。就像电脑里面的其他大部分软件一样。...
我已经生成了一个exe文件,现在想实现功能:
第一次运行后,再次双击exe文件,不再开始运行新的程序,而是打开已经运行的exe程序的窗口。就像电脑里面的其他大部分软件一样。可以实现吗? 展开
第一次运行后,再次双击exe文件,不再开始运行新的程序,而是打开已经运行的exe程序的窗口。就像电脑里面的其他大部分软件一样。可以实现吗? 展开
3个回答
展开全部
Private Sub Form_Load()
If App.PrevInstance = True Then
MsgBox "程序已经在运行", , "工程一"
Unload Me
End
End If
End Sub
If App.PrevInstance = True Then
MsgBox "程序已经在运行", , "工程一"
Unload Me
End
End If
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const WinTxt = "Form1" '修改成自己程序窗口的标题
Private Sub Form_Load()
Dim ChildHwnd As Long, Tmp As String * 255
If App.PrevInstance Then
ChildHwnd = GetWindow(GetDesktopWindow, 5)
Do While ChildHwnd <> 0&
If IsWindowVisible(ChildHwnd) Then
GetWindowText ChildHwnd, Tmp, 255
If InStr(Tmp, WinTxt) > 0 Then
ShowWindow ChildHwnd, 9
SetForegroundWindow ChildHwnd
End If
End If
ChildHwnd = GetWindow(ChildHwnd, 2)
Loop
End
End If
End Sub
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const WinTxt = "Form1" '修改成自己程序窗口的标题
Private Sub Form_Load()
Dim ChildHwnd As Long, Tmp As String * 255
If App.PrevInstance Then
ChildHwnd = GetWindow(GetDesktopWindow, 5)
Do While ChildHwnd <> 0&
If IsWindowVisible(ChildHwnd) Then
GetWindowText ChildHwnd, Tmp, 255
If InStr(Tmp, WinTxt) > 0 Then
ShowWindow ChildHwnd, 9
SetForegroundWindow ChildHwnd
End If
End If
ChildHwnd = GetWindow(ChildHwnd, 2)
Loop
End
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
vb.net中就可以直接设置选项,只运行一个实例吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询