Results 1 to 7 of 7

Thread: [RESOLVED] how call/send message to the app running?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    97

    Resolved [RESOLVED] how call/send message to the app running?

    hi,
    imagine that i have a app running and i try to launch that app again by click in the exe file, there is any way to restore,call,send a message to the app that is already running instead add a new app running?
    thanks a lot for your help

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: how call/send message to the app running?

    Do you mean you want to stop the second instance from starting?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    97

    Re: how call/send message to the app running?

    hi,
    i want stop the secund instance and maximize the other instance that is already running

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: how call/send message to the app running?

    Try this
    Code:
    Private Sub Form_Load()
    'this should go in your startup form
    If App.PrevInstance = True Then
       MsgBox "Application Is Already Running", vbInformation + vbOKOnly, "Only One Instance Allowed"
          End   'yes, the dreaded end - the only place I've ever found a use for it
    End If
    End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    97

    Re: how call/send message to the app running?

    yes this solve the first problem but don´t restore/maximize the other app
    how can i call the other app that is running in first place?

  6. #6
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: how call/send message to the app running?

    You can do something like this...

    ' Main form...
    Code:
    Option Explicit
    
    Private terminate_app As Boolean 
    Private Const SW_MAXIMIZE = 3
    Private Const SW_SHOW = 5
    
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Code:
    Private Sub PrevInstance(FrmToShow As Form)
    ' Call this sub from your start-up form.
    ' Restores the 1st instance of your program by Hwnd.
    
    Dim Lng As Long
      
    If App.PrevInstance Then
        Lng = GetSetting("MyCompanyNameHere", App.Title, "Hwnd", 0)
        If Lng > 0 then
           ShowWindow Lng, SW_SHOW
           ShowWindow Lng, SW_MAXIMIZE
           SetForegroundWindow Lng
           terminate_app = True
           Exit Sub
        End If
    Else
         SaveSetting "MyCompanyNameHere", App.Title, "Hwnd", FrmToShow.hwnd
    End If
    
    End Sub
    Code:
    Private Sub Form_Load()
    
        PrevInstance Me                  ' is a copy already running?
        If terminate_app = True Then ' if true then exit!
            Unload Me
            Exit Sub
        End If
    
    End Sub
    In the form unload you can then check terminate_app , if it's = True then don't save any user settings.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    97

    Re: how call/send message to the app running?

    hi,
    thanks a lot this work as i needed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width