By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,326 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,326 IT Pros & Developers. It's quick & easy.

System tray help

P: n/a
Hi all.

I am having application in vb.net.

I am having module and one form. From module i am opening form.
On main itself i am checking whether another instance of application is
running or not. I am also providing faclity of minimizing application
to system tray.
What i want is after clicking on exe of my application, it should check
whether my app is already running or not. If yes i don;t want to create
new instance but want to bring current instance in focus(that is
maxmimzing current application which is there is system tray).

Does any one is having any idea about it.
Please help me.
Thanks in advance.

Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Try this:

http://www.planet-source-code.com/vb...3585&lngWId=10

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #2

P: n/a
Hi.
thanks for your reply.
But i want currently running process to be in focus.
I used process class to find out whethere there is any instance of
application running or not. And if yes i want to maximize that
application. My problem is when my application is in system tray
through another application i want that application to be maximised. I
am not getting how to set that application in foreground.
Please help me if you know anything about this.
Thanks.

Nov 21 '05 #3

P: n/a
Hi,
You can use FindWindow API function to find main window of previous
instance, and call ShowWindow with SW_SHOWMAXIMIZED.

<tr**************@yahoo.com> ???????/???????? ? ???????? ?????????:
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi.
thanks for your reply.
But i want currently running process to be in focus.
I used process class to find out whethere there is any instance of
application running or not. And if yes i want to maximize that
application. My problem is when my application is in system tray
through another application i want that application to be maximised. I
am not getting how to set that application in foreground.
Please help me if you know anything about this.
Thanks.

Nov 21 '05 #4

P: n/a
Hi once again.
thanks for you help.

can you tell me how to use findwindow in vb.net application.

Thanks in advance.

Nov 21 '05 #5

P: n/a
<tr**************@yahoo.com> ???????/???????? ? ???????? ?????????:
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi once again.
thanks for you help.

can you tell me how to use findwindow in vb.net application.

Thanks in advance.


Hi,
How to use it? Like you use it in non-vb .net applications:
~
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA"
(ByVal lpClassName As IntPtr, ByVal lpWindowName As String) As IntPtr
....
Dim myWindowHandle as IntPtr = FindWindow(New IntPtr(0), "Your main window
title goes here")
~
If you are not sure if there isn't another window with same caption you can
replace "lpClassName As IntPtr" with "lpClassName As String" and "New
IntPtr(0)" with "WindowsForms10.Window.8.app3" (VB .NET forms' window
class), so you won't activate a non-.NET application instead of yours.
Nov 21 '05 #6

P: n/a
I wouldn't use IntPtr myself, but convert it to Integer instead

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #7

P: n/a
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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Const SW_RESTORE As Integer = 9
Dim SearchText As String = Me.Text
If UBound(System.Diagnostics.Process.GetProcessesByNa me( _
System.Diagnostics.Process.GetCurrentProcess.Proce ssName)) > 0 Then
Me.Text = Me.Text & "X"
Dim Handle As IntPtr = FindWindow(Nothing, SearchText)
ShowWindow(Handle, SW_RESTORE)
End
End If
End Sub
End Class
Nov 21 '05 #8

P: n/a
Hi
thanks for your reply.
But this solution is not working in my case.
Because i have main from which i am displaying main form.
And in main sub itself i want to check whether previous instance of my
application is runnign or not.
And in main i am not able to set me.text property. Because i haven;t
created object of my form at the begining.
So can u tell me without chaging text of form restoring previous
instance.

Please help me.

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.