⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.vb

📁 防止重载多个实例的实用源代码(Prevent Multiple Instances of a 32-bit VB Application)(VB or VB.NET)
💻 VB
字号:
Module Main
    ''Declarations of Windows API functions
    Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As Long
    Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long


    Sub ActivatePrevInstance(ByVal argStrAppToFind As String)
        Dim PrevHndl As Long
        Dim result As Long

        Dim objProcess As New Process 'Variable to hold individual Process
        Dim objProcesses() As Process 'Collection of all the Processes running on local machine
        objProcesses = Process.GetProcesses() ''Get all processes into the collection()

        For Each objProcess In objProcesses
            ''Check and exit if we have SMS running already
            If UCase(objProcess.MainWindowTitle) = UCase(argStrAppToFind) Then
                MsgBox("Another instance of " & argStrAppToFind & " is already running on this machine. You cannot run TWO instances at a time.Please use the other instance.")
                PrevHndl = objProcess.MainWindowHandle.ToInt32()
                Exit For
            End If
        Next
        If PrevHndl = 0 Then Exit Sub 'if No previous instance found exit the application.
        ''If found
        result = OpenIcon(PrevHndl) 'Restore the program.
        result = SetForegroundWindow(PrevHndl) 'Activate the application.

        End 'End the current instance of the application.
    End Sub

End Module

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -