vb 如何让exe运行文件只能同时运行一个

2025-02-25 06:28:52
推荐回答(2个)
回答1:

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Sub Main()
    Dim hwnd As Long
    If App.PrevInstance Then
        ShowWindow FindWindow(vbNullString, "Form1"), 1
        AppActivate "Form1"
        End
    Else
        Form1.Show
    End If
End Sub

模块代码,一定要放模块中,然后设置启动项为 main

回答2:

app对象有个参数就可以检测