ATTENDRE L'OUVERTURE D'UN PROGRAMME POUR CONTINUER

Robert - 8 nov. 2000 à 11:13
cs_Loneloup Messages postés 9 Date d'inscription mardi 25 février 2003 Statut Membre Dernière intervention 1 février 2008 - 3 avril 2003 à 11:42
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/66-attendre-l-ouverture-d-un-programme-pour-continuer

cs_Loneloup Messages postés 9 Date d'inscription mardi 25 février 2003 Statut Membre Dernière intervention 1 février 2008
3 avril 2003 à 11:42
J ai trouve ca sur le msdn :
Dans un module on pose ca
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
Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Global Const NORMAL_PRIORITY_CLASS = &H20&
Global Const INFINITE = -1&
Declare Function CloseHandle Lib "kernel32" (hObject As Long) As Boolean
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, _
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 Long, lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long

Public Sub ExecuteAndWait(cmdline$)
Dim NameOfProc As PROCESS_INFORMATION
Dim NameStart As STARTUPINFO
Dim X As Long

NameStart.cb = Len(NameStart)
X = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, _
0&, 0&, NameStart, NameOfProc)
X = WaitForSingleObject(NameOfProc.hProcess, INFINITE)
X = CloseHandle(NameOfProc.hProcess)
End Sub


et sur le bouton click ca :
AppToLaunch = App.Path & " oto.exe"
Call ExecuteAndWait(AppToLaunch)
MsgBox "Fini",vbexclamation
Resultat : au clique sur le click du bouton un prog se lance, l utilisateur ne peut pas en sortir jusqu a la fin de son execution et le programme reprend son execution et affiche "Fini"
pokbizou Messages postés 13 Date d'inscription lundi 6 mai 2002 Statut Membre Dernière intervention 13 novembre 2003
6 mai 2002 à 14:47
Plante le projet entier...
Une solution??
Je lance 2 progs dans 2 fenêtre MsDos différents et je voudrais que la première soit totalement éxécuter avant de passer à la deuxième. Mais là avec ce programme, ben tout s'arrête dès la première fenêtre ! Help ! Merci ...
Je n'ai pas vérifier, mais je crois que ce code ne marche que dans le cas d'un programme qui possèderait une fenêtre principale et ce que l'on utilise iswindow ou iswindowenabled. Donc ce code ne serait pas LA solution ultime.
Pour que le code marche, l'API est en fait Iswindows cela devient donc:Declare Function IsWindow Lib "user32" Alias "IsWindow" ( ByVal hwnd As Long) As Long


Puis
Retour = Shell("calc.exe",1)
Do While IsWindow(Retour)=0
Loop
Marche pas ou manque d'explications...
Je n'arrive pas à faire tourner ces quelques lignes de code.
L'ouverture du programme appelé s'effectue normalement, mais le programme Vb plante à l'appel de la fonction.