Attribute VB_Name = "mSubMain"
Option Explicit

Public gMe_Caption As String

Sub Main()
    ' ___________
       InitError  ' Fire up Error management
    ' ŻŻŻŻŻŻŻŻŻŻŻ
    If InAnExe Then On Error GoTo ErrHandler

    Dim s As String
    s = " Zip Search " & App.Major & "." & App.Minor
    If App.Revision Then s = s & "." & App.Revision
    gMe_Caption = s

    If App.PrevInstance Then

        ' Set focus to previous instance
        Dim Prev_hWnd As Long, cnt As Long
        ' The caption passed to GetWindowHandle can be the first
        ' part, or all of, the target window's titlebar caption
        Do ' Allow for previous instance still loading?
            DoEvents
            Prev_hWnd = GetWindowHandle(gMe_Caption)
            cnt = cnt + 1
        Loop Until (Prev_hWnd <> 0) Or (cnt > 20)

        If (Prev_hWnd <> 0) Then
            ' Make sure the main form is visible
            Dim CurState As WindowState
            CurState = GetWindowState(Prev_hWnd)
            If (CurState = SW_SHOWMINIMIZED) Then
                CurState = SW_SHOWNORMAL
            End If

            Call SetWindowToTop(Prev_hWnd, CurState)
            Call SetWindowFront(Prev_hWnd)

            If (LenB(Command$) <> 0) Then
                SendString Prev_hWnd, Command$
                'Command$() returns the argument portion of the command line
            End If
        End If
        End ' End this instance!
    End If

    Load frmZipSearch
    Load frmTerms
    DoEvents
    frmZipSearch.Show

    If InAnExe Then MsgLink.Hook frmZipSearch.hWnd
    ' MUST Unhook in frmZipSearch's Unload event!

ErrHandler:
    If (Err) Then AlertError "Sub Main"
End Sub
