Verifier qu'un soft est ouvert

odan71 Messages postés 140 Date d'inscription mardi 8 juillet 2003 Statut Membre Dernière intervention 11 décembre 2007 - 29 juil. 2004 à 16:53
Yoseik Messages postés 11 Date d'inscription mercredi 7 juillet 2004 Statut Membre Dernière intervention 15 mars 2007 - 6 août 2004 à 16:53
slt à tous,
voila le pb: j'ouvre un soft à l'aide de l'instruction open, et j'aimerai executer du code quand ce soft se ferme; comment qui faut qu'je fait?
odan71

1 réponse

Yoseik Messages postés 11 Date d'inscription mercredi 7 juillet 2004 Statut Membre Dernière intervention 15 mars 2007
6 août 2004 à 16:53
J'ai une petite fonction qui utilise des API
Ma fonction block l'exécution de ton programme tant que le programme que tu ouvre n'a pas été fermé
J'ai faite ce code en VB6

Voici la fonction

Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

' Initialize the STARTUPINFO structure:
start.dwFlags = STARTF_USESHOWWINDOW
start.wShowWindow = SW_HIDE
start.cb = Len(start)

' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

' Wait for the shelled application to finish:
WaitForSingleObject proc.hProcess, INFINITE
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
End Function

Tu auras besoin des déclaration suivante:

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Const STARTF_USESHOWWINDOW As Long = 1
Const SW_HIDE As Long = 0
Const NORMAL_PRIORITY_CLASS = &H20&

En espérant que ça pourra t'aider et que je n'ai pas oublier des déclarations :P
0
Rejoignez-nous