Routine to restore program from system tray

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert S. Liles

    #1

    Routine to restore program from system tray

    Following the advice of several members, especially Dragon, I have gotten
    this routine to work. If you double click on your program's icon to load
    it, and it is already running minimized into the sysem tray, it will just
    reopen the running instance, not create another instance. Put this Function
    into a Module in a DLL and call it like

    If NoLoad(Me) then END

    in your Form1.Load routine. This function returns TRUE if an instance is
    already running, and False if this is the first instance to be loaded.

    Bobbo
    _______________ _______________ _________

    Declare Auto Function FindWindow Lib "user32.dll " _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

    Declare Auto Function ShowWindow Lib "user32.dll " _
    (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean

    Public Function NoLoad(ByRef sender As System.Object) As Boolean
    If UBound(System.D iagnostics.Proc ess.GetProcesse sByName( _
    System.Diagnost ics.Process.Get CurrentProcess. ProcessName)) > 0 Then
    Const SW_RESTORE As Integer = 9
    Dim SearchText As String = sender.Text
    sender.Text = sender.Text & "X"
    Dim Handle As IntPtr = FindWindow(Noth ing, SearchText)
    ShowWindow(Hand le, SW_RESTORE)
    sender.Text = SearchText
    Return True
    Else
    Return False
    End If
    End Function


  • Crouchie1998

    #2
    Re: Routine to restore program from system tray

    You see the information in this routine?

    I gave you a link to a Previous Existance function, which you said was no
    good, yet this uses the same thing & you say it works. That doesn't make any
    sense.

    Here's that link again:



    Next, you don't need to use ShowWindow because there is AppActivate or
    Me.Show etc.

    You are making an easy task harder. I have many applications running on
    startup (no form) & display a form it it doesn't exist & I don't ever use
    ShowWindow or any other API to display it.

    Crouchie1998
    BA (HONS) MCP MCSE


    Comment

    • Robert S. Liles

      #3
      Re: Routine to restore program from system tray

      That wasn't me. I was following the thread, but had not participated in it
      until I got this routine to work. Sorry for any confusion that I caused by
      participating.

      Bobbo


      Comment

      Working...