Results 1 to 5 of 5

Thread: multiple instances of program

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Germany
    Posts
    1

    Exclamation multiple instances of program

    how to suppress multiple instances of any program by (too) fast a double click ???

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Here the sample code

    Code:
    Option Explicit
    '//WIN32API Function
    Private Declare Function SetForegroundWindow 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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
    
    '//WIN32API Constant
    Private Const SW_RESTORE = 9
    
    Sub Main()
        Dim hwnd As Long
        
        '//Check for Previous Instance
        If App.PrevInstance Then
            hwnd = FindWindow(0&, "App Window Title Here")
            If hwnd <> 0 Then
                SetForegroundWindow hwnd
                ShowWindow hwnd, SW_RESTORE
                End
            End If
        End If
        
        '//Continue load the Main Form
        Load frmMain
        frmMain.Show
    End Sub
    Attached Files Attached Files

  3. #3
    Megatron
    Guest
    Or you can use the PrevInstance property of the App.
    Code:
    If App.PrevInstance = True Then Unload Me

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Meg, i think it will be better if make the previous instance become the active window. like what I did in my posted code?

  5. #5
    Megatron
    Guest
    That's not of the matter though. I was only demonstrating a simpler way of achieveing the same thing (checking for the previous instance).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width