473,657 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

restore application from systray

Hi,

I have a problem regarding restoring previous instance of an
application minimized in systray.So that when I try to run the
application it should maximize its previous instance instead of
creating a new one.

The part of code is like -

I have one function which returns the instance of the
previous process as
Public Function GetProcess() As Process
'to get the process for the already running application
Dim processes() As Process
Dim procName As String

procName = Process.GetCurr entProcess.Proc essName
processes = Process.GetProc essesByName(pro cName)
For Each p As Process In processes
If p.Id <> Process.GetCurr entProcess.Id Then
Return p
End If
Next
End Function

In the below function I am trying to display the window but it
doesn't work the main window handle is 0 in this case.

Public Function MultipleInstanc esRunning() As Boolean
Dim pInstance As Process
pInstance = GetProcess()
If Not pInstance Is Nothing Then
Dim handle As IntPtr = pInstance.MainW indowHandle
If Not IntPtr.Zero.Equ als(handle) Then
ShowWindow(hand le, SW_SHOWMAXIMIZE D)
SetForegroundWi ndow(handle)
End If
Return True
Else
Return False
End If
End Function

Is anything wrong with this method? Do anybody knows any other
alternative?

Nov 21 '05 #1
3 1764
Please either attach your project or paste in the full form's code. That way
we (anyone in the newsgroup) can see the code you have so far. It will make
life easier for a solution

Me peronally would start a new application in the System Tray if one doesn't
exist. Then on double-click of the tray, do something like this:

Dim frm As Form1

If Not (frm Is Nothing) Then
frm.Show() 'or frm.ShowDialog( )
Else
frm = New Form1
frm.Show() ' or frm.ShowDialog( )
End If

(frm.Show() would be better. Although you are starting the program from a
module to run the tray & then the form. In this case you should use
ShowDialog())

An even better method would be to create a boolean value:

In Module (Declarions):

Dim blnDoesFormExis t As Boolean = False

Then behind the System Tray Icon double-click event():

If Not blnDoesFormExis t = True Then
blnDoesFormExis t = True
Dim frm As New Form1
frm.ShowDialog( )
Else
Me.Show()
End If

Do something like that & forget the ShowWindow or FindWindow API's. In a
nutshell: Why complicate things?

Either try my approach or paste in the code like I suggested firstly. It
would give everyone an good overall picture

---------------------------
If that's your real Gmail address then I suggest you spoof it to stop
SPAMMERS
---------------------------

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #2
On Fri, 17 Jun 2005 11:35:43 +0100, "Crouchie19 98" <cr**********@s pamcop.net>
wrote:
---------------------------
If that's your real Gmail address then I suggest you spoof it to stop
SPAMMERS
---------------------------

Gmail filtering is that good.
--
Liberty ...
-----------------------------------------------------------------
Liberty :Freedom is first earned
li************* @revolutionist. com :by demanding it. It's lost by
http://pages.sbcglobal.net/spiritof76 :forgetting its value.
-----------------------------------------------------------------
Nov 21 '05 #3
This code will take a program minimized into the system tray and restore it
to the screen with the focus instead of opening a new window.

Bobbo
_______________ _______________ ____________
Public Class Form1
Inherits System.Windows. Forms.Form

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

#Region " Windows Form Designer generated code "
#End Region

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Const SW_RESTORE As Integer = 9
Dim SearchText As String = Me.Text
If UBound(System.D iagnostics.Proc ess.GetProcesse sByName( _
System.Diagnost ics.Process.Get CurrentProcess. ProcessName)) > 0 Then
Me.Text = Me.Text & "X"
Dim Handle As IntPtr = FindWindow(Noth ing, SearchText)
ShowWindow(Hand le, SW_RESTORE)
End
End If
End Sub
End Class

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9105
by: Tim Morrison | last post by:
MSDE2000 I have an application in which I am running a TSQL command of BACKUP DATABASE and RESTORE DATABASE for the backup and restore commands for my application. For testing purposes, i did the following: 1) Ran a BACKUP DATABASE command to a file named C:\TEST.BAK. 2) Deleted the database completely. 3) Ran a RESTORE DATABASE on the same file (note, I did NOT recreate the database) Now I have the database back with all my data....
0
3680
by: charlesh3 | last post by:
Hi - I'd like to write a VB6 program to add a couple of text based clocks (for different time zones) to the systray so they'll always be visible. I can add an icon to the systray, but the API's to do that only support adding icons. I don't want to just put a window over the systray. Does anyone know how to do this properly?
11
13540
by: Chris | last post by:
I have searched this group for answers and tried the responses. I am trying to Use an full online backup from our production server and apply it to our test server. The Tablespaces in the productions server are on the d drive and my test server has no d drive. The restore command i am using is: RESTORE DATABASE CENTRAL FROM "C:\DB2Backups" TAKEN AT 20050620000000 INTO CENT0620 REDIRECT;
3
5489
by: Jon Bosker | last post by:
I have written an application that lives in the systray but when I try to close windows or logout it does not close my application and therefore prevents windows from shutting down or logging me out. It is essential that I solve this problem but I have run out of ideas can anyone help (please!) The application starts in Start.cs which kicks off the Systray form using this call: Application.Run(new Systray());
5
14591
by: christopher green | last post by:
I am writing a C# windows application but I don't want to display any forms, effectively I want it to be invisible on the desktop apart from an icon in the system tray. How can I do this? I know I can start an application minimised but I don't want to display any forms. Thanks for your assistance. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
3
2103
by: Erik Greene | last post by:
I have written an application that contains a notifyicon that will not dispose or end when Windows shutsdown. I have seen other posts where people are experiencing the same issue (see post in the csharp group), so I know that this is an issues for others as well. Does anyone know how to capture the Windows Exit/Shutdown event?
2
1214
by: shachar | last post by:
hi all. i have a small application that i want it to appear in the systray when it's minimized. any simple example for me?
8
2655
by: Rob R. Ainscough | last post by:
I have a VS 2005 Windows Service with a Installer project as part of my solution. The Service installs fine but I can't seem to make either of these work: 1. Have the service start after install 2. Have the service interact with the SysTray In my ProjectInstaller.vb Private Sub ServiceInstaller1_AfterInstall(ByVal sender As
3
5791
by: DaveL | last post by:
Hi All I have a windows application that needs to run 24/7 in the SysTray How to Start this on Start up When ever the machine is re-started etc I also need to run as a Different User that has Rights to do FileSystem and other work on this Server
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7333
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1957
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.