The program only runs an instance and activates the previous one.

zhaozj2021-02-16  41

(for reference only)

Option ExplicitPrivate Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias ​​"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As LongConst SW_RESTORE = 9Private Const OPEN_APPLICATION = 0Private Const SINGLE_INSTANCE_OPEN = 1Sub Main () Dim MultiInstResult As IntegerMultiInstResult = MultiInstIf MultiInstResult = OPEN_APPLICATION Then Form1.Show ElseIf MultiInstResult = SINGLE_INSTANCE_OPEN Then EndEnd IfEnd SubPrivate Function MultiInst () As IntegerDim hwndFound As Long Dim strWindowName strWindowName = App.TitleApp.Title = "temp title" hwndFound = FindWindow (vbNullString, strWindowName) If hwndFound Then MultiInst = SINGLE_INSTANCE_OPEN MsgBox " A instance of the application is already OP en. "& vbCrLf & vbCrLf &" Only one open instance allowed. ", vbOKOnly vbExclamation," App Name "If IsIconic (hwndFound) Then ShowWindow hwndFound, SW_RESTORE SetForegroundWindow hwndFound Else SetForegroundWindow hwndFound End IfElseIf hwndFound = 0 Then App.Title = Strwindowname MultiInst = Open_ApplicationInd IFEND FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-24800.html

New Post(0)