System tray help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • trialproduct2004@yahoo.com

    #1

    System tray help

    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.

  • Crouchie1998

    #2
    Re: System tray help

    Try this:



    Crouchie1998
    BA (HONS) MCP MCSE


    Comment

    • trialproduct2004@yahoo.com

      #3
      Re: System tray help

      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.

      Comment

      • Dragon

        #4
        Re: System tray help

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

        <trialproduct20 04@yahoo.com> ???????/???????? ? ???????? ?????????:
        news:1118822377 .165330.34510@g 49g2000cwa.goog legroups.com...[color=blue]
        > 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.
        >[/color]


        Comment

        • trialproduct2004@yahoo.com

          #5
          Re: System tray help

          Hi once again.
          thanks for you help.

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

          Thanks in advance.

          Comment

          • Dragon

            #6
            Re: System tray help

            <trialproduct20 04@yahoo.com> ???????/???????? ? ???????? ?????????:
            news:1118924866 .885728.37580@g 49g2000cwa.goog legroups.com...[color=blue]
            > Hi once again.
            > thanks for you help.
            >
            > can you tell me how to use findwindow in vb.net application.
            >
            > Thanks in advance.
            >[/color]

            Hi,
            How to use it? Like you use it in non-vb .net applications:
            ~
            Private Declare Function FindWindow Lib "user32.dll " Alias "FindWindow A"
            (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 "lpClassNam e As IntPtr" with "lpClassNam e 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.


            Comment

            • Crouchie1998

              #7
              Re: System tray help

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

              Crouchie1998
              BA (HONS) MCP MCSE


              Comment

              • Robert S. Liles

                #8
                Re: System tray help -- IT WORKS!

                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


                Comment

                • trialproduct2004@yahoo.com

                  #9
                  Re: System tray help -- IT WORKS!

                  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.

                  Comment

                  Working...