Newsgroup: it.comp.lang.visual-basic
Titolo: Applicazione in esecuzione

Gia' detto miliardi di volte ma non riesco a ritrovarlo, scusate...
Come faccio a sapere se l'applicazione e' gia' in esecuzione
ed eventualmente passare a quella attiva?
Grazie
_____________________________________________
James Tiberius Kirk, matricola SC 937-076 CEC
  Nato a Riverside, nello Iowa, USA, Terra
            il 1277.1 (26/03/2233)

ed eventualmente passare a quella attiva?
Sul Sito Comune trovi un esempio su come enumerare le applicazioni attive; trova quella che ti
interessa e poi, se non ricordo male, dovresti usare l'API SetForegroundWindow, passandogli come
parametro, l'handle della finestra.
Ciao,
Moreno
#sirri#@#morenosoft#.com
(togliete "#" dall'indirizzo)
Moreno Sirri VB Site - 
http://www.morenosoft.com/MSVBSite/
---------------------------------------------------------------------------
Le risposte alle tue domande le trovi sul Sito Comune di questo NewsGroup:
 
http://www.murialdo.it/it_lang_vb
---------------------------------------------------------------------------


direttamente da MSDN:
HOWTO: Prevent Multiple Instances of a 32-bit VB Application
----------------------------------------------------------------------------
----
The information in this article applies to:
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for
Windows, version 6.0
Microsoft Visual Basic Control Creation, Learning, Professional, and
Enterprise Editions for Windows, version 5.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions,
32-bit only, for Windows, version 4.0
----------------------------------------------------------------------------
----
SUMMARY
This article describes how to avoid loading a second instance of an
application when the user already has one instance running. It also sets the
focus to the first instance of the Visual Basic application when you attempt
to start a second instance of the same application.
MORE INFORMATION
Step-by-Step Example
Create a new Visual Basic project.
Go into Project Properties and set the Startup Object (or Startup Form in
VB4) to be Sub Main.
Add a Standard Module to the Project.
Paste the following code into the module:
      Option Explicit
      Public Const GW_HWNDPREV = 3
      Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As Long
      Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) _
         As Long
      Declare Function GetWindow Lib "user32" _
        (ByVal hwnd As Long, ByVal wCmd As Long) As Long
      Declare Function SetForegroundWindow Lib "user32" _
        (ByVal hwnd As Long) As Long
      Private Sub Form_Load()
            If App.PrevInstance Then
               ActivatePrevInstance
            End If
         End Sub
      Sub ActivatePrevInstance()
         Dim OldTitle As String
         Dim PrevHndl As Long
         Dim result As Long
         'Save the title of the application.
         OldTitle = App.Title
         'Rename the title of this application so FindWindow
         'will not find this application instance.
         App.Title = "unwanted instance"
         'Attempt to get window handle using VB4 class name.
         PrevHndl = FindWindow("ThunderRTMain", OldTitle)
         'Check for no success.
         If PrevHndl = 0 Then
            'Attempt to get window handle using VB5 class name.
            PrevHndl = FindWindow("ThunderRT5Main", OldTitle)
         End If
         'Check if found
         If PrevHndl = 0 Then
         'Attempt to get window handle using VB6 class name
         PrevHndl = FindWindow("ThunderRT6Main", OldTitle)
         End If
         'Check if found
         If PrevHndl = 0 Then
            'No previous instance found.
            Exit Sub
         End If
         'Get handle to previous window.
         PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV)
         'Restore the program.
         result = OpenIcon(PrevHndl)
         'Activate the application.
         result = SetForegroundWindow(PrevHndl)
         'End the application.
         End
      End Sub
Compile the project into an EXE.
Exit Visual Basic.
Run the executable you created.
Repeat step 7.
RESULT: The first instance of the program is given focus and the second
instance is closed. If the first instance of the application was minimized,
it will be restored to a normal window automatically.
REFERENCES
For information about preventing multiple instances of a Visual Basic 4.0
16-bit application, please see the following article in the Microsoft
Knowledge Base:
Q142937 : How to Prevent Multiple Instances of a VB Application
Additional query words: kbSDKWin32 kbAPI kbdSupport kbdsd kbVBp400 kbVBp500
kbVBp600 kbVBp
Keywords : kbGrpVB
Version : WINDOWS:4.0,5.0,6.0
Platform : WINDOWS
Issue type : kbhowto
Technology :
Last Reviewed: February 16, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
----------------------------------------------------------------------------
----
Send feedback to MSDN.Look here for MSDN Online resources.

Grazie a tutti e due.
