Routine to restore program from system tray

R

Robert S. Liles

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.Diagnostics.Process.GetProcessesByName( _
System.Diagnostics.Process.GetCurrentProcess.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(Nothing, SearchText)
ShowWindow(Handle, SW_RESTORE)
sender.Text = SearchText
Return True
Else
Return False
End If
End Function
 
C

Crouchie1998

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:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3585&lngWId=10

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
 
R

Robert S. Liles

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top