System tray help

T

trialproduct2004

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.
 
T

trialproduct2004

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.
 
D

Dragon

Hi,
You can use FindWindow API function to find main window of previous
instance, and call ShowWindow with SW_SHOWMAXIMIZED.
 
T

trialproduct2004

Hi once again.
thanks for you help.

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

Thanks in advance.
 
D

Dragon

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.
 
C

Crouchie1998

I wouldn't use IntPtr myself, but convert it to Integer instead

Crouchie1998
BA (HONS) MCP MCSE
 
R

Robert S. Liles

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.GetProcessesByName( _
System.Diagnostics.Process.GetCurrentProcess.ProcessName)) > 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
 
T

trialproduct2004

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.
 

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