|
-
May 16th, 2008, 10:25 AM
#1
Thread Starter
Lively Member
[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
-
May 16th, 2008, 10:39 AM
#2
Re: how call/send message to the app running?
Do you mean you want to stop the second instance from starting?
-
May 16th, 2008, 11:22 AM
#3
Thread Starter
Lively Member
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
-
May 16th, 2008, 11:40 AM
#4
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
-
May 17th, 2008, 04:56 AM
#5
Thread Starter
Lively Member
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?
-
May 17th, 2008, 05:13 AM
#6
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.
-
May 17th, 2008, 07:29 AM
#7
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|