Sous VB ça marche et pas avec l'exe

Bendes - 2 avril 2001 à 13:05
 Muad-Dib - 10 avril 2001 à 14:42
Voici un code que j'ai trouvé sur ce site et que j'ai remis à ma sauce :

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long

Public Function TaskExists(ByVal strCheckTask As String) As Boolean
Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
TaskExists = False
CurrWnd = GetActiveWindow()
Do While (CurrWnd <> 0)
Length = GetWindowTextLength(CurrWnd)
TaskName = Space(Length + 1)
Length = GetWindowText(CurrWnd, TaskName, Length + 1)
TaskName = Left(TaskName, Len(TaskName) - 1)
If (Length > 0) Then
If InStr(1, TaskName, strCheckTask, vbTextCompare) <> 0 Then
TaskExists = True
Exit Do
End If
End If CurrWnd GetWindow(CurrWnd, 2) '\2 next window handle
Loop
End Function

Cette fonction permet de savoir si mon l'application est déjà démarrer ou pas (via API)

Le prob est que sous environement VB ça marche nickel, ms qd je créé l'exécutable, ça marche plus, POURQUOIIII???

4 réponses

Tu sais... il y a une commande pour le savoir :

 if app.PrevInstance = True then
  msgbox "Le prog. tourne déja!"
 end if


Mémère
0
Pour finir le l'ai fais avec l'API "FindWindow", ms je connaissais pas. Merci
0
ça marche pas aussi bien en tout cas, g testé...
0
Tu sais, c la magie de vb ca .. j'avais fait un exe dont le source est ici qui cherchait récursivement les fichier .. et ben, en développement la recherche à partir d'un lecteur racine fonctionnait niquel, mais dès que je le lançait en exe fiou! le prog disparaissait sans meme générer une erreur... :question) :question) :question)

Muad
0
Rejoignez-nous