[VB6] API

API [VB6] - Programmation

Marsh Posté le 02-04-2001 à 09:51:48    

Voici mon code :
 
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 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??? :(:(:(:(:(

Reply

Marsh Posté le 02-04-2001 à 09:51:48   

Reply

Marsh Posté le 02-04-2001 à 10:18:12    

Personne...:(
 
C'est vrai que c'est bizarre comme comportement, et je ne vois pas du tout d'où ça peut venir....

Reply

Marsh Posté le 02-04-2001 à 11:31:24    

J'essayé ton code, ca me fais pareil.
Voici ce que j'ai trouvé qui marche (faut le convertir pour que ca fasse la même chose)
 
Private Declare Function RecupLaFenetre Lib "user32" Alias "GetWindow" _
                        (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function RecupLePidDuPapa Lib "user32" Alias "GetParent" _
                                              (ByVal hwnd As Long) As Long
Private Declare Function RecupLaLongueurDeLeTexte Lib "user32" Alias _
                   "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function RecupLeTexte Lib "user32" Alias "GetWindowTextA" _
  (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function ModifLeTexte Lib "user32" Alias "SetWindowTextA" _
                     (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
   (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessageA Lib "user32" (ByVal hwnd As Integer, _
      ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
 
 
Sub LoadTaskList()
 Dim CurrWnd As Long
 Dim LongueurDeLeNom As Long
 Dim TaskName As String
 Dim Parent As Long
 
 CurrWnd = RecupLaFenetre(frm_principale.hwnd, 0)
 gIndex = 0
 While CurrWnd <> 0
  Parent = RecupLePidDuPapa(CurrWnd)
  LongueurDeLeNom = RecupLaLongueurDeLeTexte(CurrWnd)
  TaskName = Space$(LongueurDeLeNom + 1)
  Length = RecupLeTexte(CurrWnd, TaskName, LongueurDeLeNom + 1)
  TaskName = Left$(TaskName, Len(TaskName) - 1)
  If Length > 0 And gIndex < 200 Then
   'If TaskName <> Me.Caption Then
   frm_principale.List1.AddItem TaskName
   gIndex = gIndex + 1
  End If
  CurrWnd = RecupLaFenetre(CurrWnd, 2)
  DoEvents
 Wend
End Sub

Reply

Marsh Posté le 02-04-2001 à 11:34:47    

La seul différence ca à l'air d'être :
 
CurrWnd = RecupLaFenetre(frm_principale.hwnd, 0)

Reply

Marsh Posté le 02-04-2001 à 11:47:50    

Thx, j'vais tester ça...

Reply

Marsh Posté le 02-04-2001 à 14:37:34    

C'est bon, en employant juste l'API "FindWindow" j'ai juste ce qu'il me faut, ça marche avec l'exécutable et il y a moins de ligne de code...;)
 
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 
if FindWindow(vbNullString, "Mon appli" ) = 0 then Launch

Reply

Marsh Posté le 02-04-2001 à 19:59:24    

pq tu ne prends pas Me.parent.hwnd   tu as le handle parent de ta fenetre pas besoin de passer par des api...

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed