=> ollivier , en effet je n'ai pas appris du coup je ne sais pas m'en servir, merci pour le lien
=> Marc56 , ça tourne bien avec le flag, le thread se ferme correctement et libère les ressources, je veux pas être pénible mais ça fonctionne pour les 3 itérations du ping standard, si on spécifie un -n 1500 par exemple , le thread ne se fermera que lorsqu'on on aura repris la main .....
c'est pour une question d'affichage et de lisibilité, le gadget edit incrémente les lignes en mettant la dernière reçue en première position
j'ai rajouté un 2 ème thread pour un multi-ping avec changement de couleur quand l'ip n'est pas ou plus joignable , par contre , à quoi donc sert le 23 dans le
Code : Tout sélectionner
;ping tool
;free code
;use at your own risks
Enumeration
#FEN1
#FEN1_Edit_Ip
#FEN1_Txt_Ip
#FEN1_Ping
#FEN1_Edit_2
#FEN1_Stop
;-------------------------------------------;
#FEN1_Edit_Ip2
#FEN1_Txt_Ip2
#FEN1_Ping2
#FEN1_Edit_3
#FEN1_Stop2
EndEnumeration
Global ID_ThreadPing
Global ID_ThreadPing2
Global Run.c
Global Run2.c
OpenWindow(#FEN1, 320, 200, 1200, 650,
"Ping_Test Jmg@2016 Press ESC to Quit",
#PB_Window_SystemMenu |
#PB_Window_ScreenCentered)
LoadFont(1,"Arial",11)
SetWindowColor(#FEN1,RGB(0,0,0))
TextGadget(#FEN1_Txt_Ip, 20, 50, 80, 28, " Adresse Ip :")
SetGadgetColor(#FEN1_Txt_Ip, #PB_Gadget_BackColor, RGB(0,0,0))
SetGadgetColor(#FEN1_Txt_Ip, #PB_Gadget_FrontColor, RGB(255,255,255))
SetGadgetFont(#FEN1_Txt_Ip, FontID(1))
EditorGadget(#FEN1_Edit_Ip, 120, 50, 150, 20)
SetGadgetFont(#FEN1_Edit_Ip, FontID(1))
SetGadgetColor(#FEN1_Edit_Ip, #PB_Gadget_BackColor, RGB(0,0,0))
SetGadgetColor(#FEN1_Edit_Ip, #PB_Gadget_FrontColor, RGB(255,255,255))
SetGadgetText(#FEN1_Edit_Ip,"8.8.8.8")
EditorGadget(#FEN1_Edit_2, 50, 150, 500, 250)
SetGadgetFont(#FEN1_Edit_2, FontID(1))
SetGadgetColor(#FEN1_Edit_2, #PB_Gadget_BackColor, RGB(0,0,0))
SetGadgetColor(#FEN1_Edit_2, #PB_Gadget_FrontColor, RGB(255,255,255))
ButtonGadget(#FEN1_Ping, 320, 50, 90, 23, " Ping ")
SetGadgetFont(#FEN1_Ping, FontID(1))
ButtonGadget(#FEN1_Stop, 420, 50, 90, 23, " Stop ")
SetGadgetFont(#FEN1_Stop, FontID(1))
;-------------------------------------------------------------------------------------
TextGadget(#FEN1_Txt_Ip2, 620, 50, 80, 28, " Adresse Ip :")
SetGadgetFont(#FEN1_Txt_Ip2, FontID(1))
SetGadgetColor(#FEN1_Txt_Ip2, #PB_Gadget_BackColor, RGB(0,0,0))
SetGadgetColor(#FEN1_Txt_Ip2, #PB_Gadget_FrontColor, RGB(255,255,255))
EditorGadget(#FEN1_Edit_Ip2, 740, 50, 150, 20)
SetGadgetFont(#FEN1_Edit_Ip2, FontID(1))
SetGadgetColor(#FEN1_Edit_Ip2, #PB_Gadget_BackColor, RGB(0,0,0))
SetGadgetColor(#FEN1_Edit_Ip2, #PB_Gadget_FrontColor, RGB(255,255,255))
SetGadgetText(#FEN1_Edit_Ip2,"8.8.8.8")
EditorGadget(#FEN1_Edit_3, 650, 150, 500, 250)
SetGadgetColor(#FEN1_Edit_3, #PB_Gadget_BackColor, RGB(0,0,0))
SetGadgetColor(#FEN1_Edit_3, #PB_Gadget_FrontColor, RGB(255,255,255))
SetGadgetFont(#FEN1_Edit_3, FontID(1))
ButtonGadget(#FEN1_Ping2, 940, 50, 90, 23, " Ping ")
SetGadgetFont(#FEN1_Ping2, FontID(1))
ButtonGadget(#FEN1_Stop2, 1040, 50, 90, 23, " Stop ")
SetGadgetFont(#FEN1_Stop2, FontID(1))
;-------------------------------------------------------------------------------------
Procedure ping(*Valeur)
Protected ping
Protected out$
Repeat
ping = RunProgram("ping.exe",
GetGadgetText(#FEN1_Edit_Ip) ,
"",
#PB_Program_Open | #PB_Program_Read | #PB_Program_Hide | #PB_Program_Ascii)
While ProgramRunning(ping)
If Run = 0
CloseProgram(ping)
ProcedureReturn
EndIf
out$ = ReadProgramString(ping)
AddGadgetItem(#FEN1_Edit_2, 0, out$)
position = FindString(out$, "attente")
position2 = FindString(out$, "TTL")
For r =1 To 100
If position = r
SetGadgetColor(#FEN1_Edit_2, #PB_Gadget_FrontColor, RGB(255,00,00))
EndIf
If position2 = r
SetGadgetColor(#FEN1_Edit_2, #PB_Gadget_FrontColor, RGB(255,255,255))
EndIf
Next
Wend
ForEver
EndProcedure
Procedure ping2(*Valeur)
Protected ping2
Protected out2$
Repeat
ping2 = RunProgram("ping.exe",
GetGadgetText(#FEN1_Edit_Ip2) ,
"",
#PB_Program_Open | #PB_Program_Read | #PB_Program_Hide | #PB_Program_Ascii)
While ProgramRunning(ping2)
If Run2 = 0
CloseProgram(ping2)
ProcedureReturn
EndIf
out2$ = ReadProgramString(ping2)
AddGadgetItem(#FEN1_Edit_3, 0, out2$)
position3 = FindString(out2$, "attente")
position4 = FindString(out2$, "TTL")
For g= 1 To 100
If position3 = g
SetGadgetColor(#FEN1_Edit_3, #PB_Gadget_FrontColor, RGB(255,00,00))
EndIf
If position4 = g
SetGadgetColor(#FEN1_Edit_3, #PB_Gadget_FrontColor, RGB(255,255,255))
EndIf
Next
Wend
ForEver
EndProcedure
Repeat
Select WaitWindowEvent(50)
Case #PB_Event_Gadget
Select EventGadget()
Case #FEN1_Ping
Run = 1
ID_ThreadPing = CreateThread(@ping(), 23)
Case #FEN1_Stop
Run = 0
Case #FEN1_Ping2
Run2 = 1
ID_ThreadPing2 = CreateThread(@ping2(), 1)
Case #FEN1_Stop2
Run2 = 0
EndSelect
Case #PB_Event_CloseWindow
Break
EndSelect
Until GetAsyncKeyState_(#VK_ESCAPE)
End