Results 1 to 4 of 4

Thread: Run Only one?? How?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    52

    Question

    If i am using both the Win.ini and registry to boot an application, how can i make it so that only one instance of the application will run?

    Essentially i want it to check if the app is already open, if so unload itself, if not continue to load itself.


    Can i set this to happen on splash screen ini?

    Any help would be appreciated.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    If App.PrevInstance Then
        Unload Me
    End If
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    52
    Thankyou for that.

    Works a treat.


    Regards
    M.

  4. #4
    Lively Member
    Join Date
    Jul 2000
    Location
    Lost in the Mojave Desert
    Posts
    82

    here is one step further

    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd&, ByVal nCmdShow&) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd&) As Long
    Private Const SW_RESTORE = 9

    Public Sub Main()

    Dim sTitle$
    Dim lRetVal&, hwnd&

    If App.PrevInstance Then 'only allows 1 instance of app to be open at a time
    sTitle = mdiMain.Caption
    App.Title = "newcopy"
    mdiMain.Caption = "newcopy"

    hwnd = FindWindow(vbNullString, sTitle)

    If hwnd <> 0 Then
    lRetVal = ShowWindow(hwnd, SW_RESTORE)
    lRetVal = SetForegroundWindow(hwnd)
    End If
    End
    Else
    mdiMain.Show
    End If

    End Sub

    Don't go away mad, just go away.

    Bam-Bam

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