EnableExplicit

CompilerSelect #PB_Compiler_Thread
  CompilerCase #False
    CompilerError "L'option 'Activer la gestion des thread' doit etre activée."
  CompilerDefault
CompilerEndSelect

CompilerSelect #PB_Compiler_EnableExplicit
  CompilerCase #False
    CompilerError "EnableExplicit doit etre indiqué."
  CompilerDefault
CompilerEndSelect

CompilerSelect #PB_Compiler_ExecutableFormat
  CompilerCase #PB_Compiler_Executable
  CompilerDefault
    CompilerError "L'option 'Format de l'exécutable:' doit être positionnée sur 'Windows'"
CompilerEndSelect

OnErrorGoto(?ErrorHandler)

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  #PROCESSOR="(x86)"
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
  #PROCESSOR="(x64)"
CompilerEndIf

SetCurrentDirectory(GetPathPart(ProgramFilename()))

;;; https://msdn.microsoft.com/en-us/library/windows/desktop/cc144179%28v=vs.85%29.aspx
;;; https://learn.microsoft.com/fr-fr/windows/win32/shell/taskbar?redirectedfrom=MSDN
Global TB_Message = RegisterWindowMessage_("TaskbarCreated")

CompilerIf #PB_Compiler_Debugger
  ;;; Nous sommes dans l'IDE
  #WinApp = 999
CompilerElse
  #WinApp = 99
CompilerEndIf

Enumeration Menus
  #MenuApp
  #MenuAppPop1
  #MenuAppPop2
  #MenuTray
EndEnumeration

Enumeration FormMenu
  #KeyEnter
  #MenuAppDevice
  #MenuAppPaquet
  #MenuAppEdit
  #MenuAppQuit
  #MenuAppShow
  ;
  #MenuAppMsgTitle
  #MenuAppMsgClear
  #MenuAppMsgCopy
  #MenuAppMsgSave
  #MenuAppMsgEdit
  ;
  #MenuAppFile
  #MenuAppFileEnd=#MenuAppFile+9
  #MenuAppLink
  #MenuAppLinkEnd=#MenuAppLink+9
  #MenuAppNetw
  #MenuAppNetwEnd=#MenuAppNetw+9
  #MenuAppApps
  #MenuAppAppsEnd=#MenuAppApps+19
  #MenuAppHost
  #MenuAppHostEnd=#MenuAppHost+9
  ;
  #MenuAppPopup
  #MenuAppPopupEnd=#MenuAppPopup+9
EndEnumeration

Enumeration Gadgets
  #GadgetButtonPick ; Sélectionner une liste de commandes
  #GadgetButtonQuit ; Fermer l'application
  #GadgetButtonSend ; Exécuter la commande
  #GadgetCombo
  #GadgetStringCmde ; Ligne de commande
  #GadgetEditor
  #GadgetStatusBar
EndEnumeration

Enumeration Fonts
  #Font0 ; "Consolas"
EndEnumeration

DataSection ; Images
  Image_App:
  IncludeBinary "icones\myadbctrl.ico"
  Image_Web:
  IncludeBinary "icones\ie10.ico"
EndDataSection

Enumeration Images
  #Image_App
  #Image_Web
EndEnumeration

;UseGIFImageDecoder()
;UsePNGImageDecoder()

Global IconApp = CatchImage(#Image_App, ?Image_App)
Global IconWeb = CatchImage(#Image_Web, ?Image_Web)

#bgcolor  = 14474460 ; bgcolor = RGB(220,220,220)
#fgcolor  = 0        ; fcolor  = RGB(0,0,0)

Global serveur_adb
#server_adb_on$  = "serveur adb : actif"
#server_adb_off$ = "serveur adb : inactif"

#IP$  = "%IP%"
#APK$ = "%APK%"
#LOG$ = "%LOG%"
#PAQUET$ = "PAQUET  :  "
#DEVICE$ = "DEVICE  :  "

Global admin   = IsUserAnAdmin_()
Global elevate = #False
Global mode$
If admin
  mode$ = "Mode Admin"
Else
  mode$ = "Mode User"
EndIf

Global progr$, param$, foldr$, pflags.l
Structure program
  progr$
  param$
  foldr$
  pflags.l ; #PB_Program_Hide pour les utilitaires console
EndStructure
Global *Parameters.program
Global NewMap file.program()
Global NewMap link.s()
Global NewMap pop1.s()
Global NewMap pop2.s()
Global NewMap netw.program()
Global NewMap apps.program()
Structure host
  adress$
  comment$
EndStructure
Global NewMap host.host()

#WinAppWidth  = 700
#WinAppHeight = 450
#WinAppTitle  = "my adb control v23.08.01 "+#PROCESSOR

Define X,Y,i,N,IN,OUT

Declare.a initSysTray()
Declare   window_Callback(win, msg, wParam, lParam)
Declare.a hideAppWindow()
Declare.a showAppWindow()
Declare.a appQuit()
Declare.a fileExist(f$)
Declare.a cocher_menu_item(item)
Declare.a main()
Declare.a construire_app_main_menu()
Declare.a construire_app_tray_menu()
Declare.a construire_app_pop1_menu()
Declare.a construire_app_pop2_menu()
Declare.a construire_app_main_interface()
Declare.a documenter_app_combo_gadget(cmds$)
Declare.s tester_elevate(input$)
Declare.a envoyer_commande()
Declare.a lancer_programme(*parameters.program)
Declare   runAsAdmin(progr$=#Null$, param$=#Null$, foldr$=#Null$)
Declare.i getNamePID(ProcessName.s,*ptrPID)
Declare.a tester_serveur_adb(*v)
Declare.a onMouse(nCode,wParam,lParam)

Global paquet$
Global device$
#devices_file$   = "devices.txt"
#journal_file$   = "journal.txt"
#messages_files$ = "messages.txt"

If Not fileExist(#devices_file$)
  OUT = CreateFile(#PB_Any, #devices_file$, #PB_UTF8)
  If OUT
    WriteStringN(OUT, "192.168.1.18      # LENOVO-TAB-A7")
    WriteStringN(OUT, "192.168.1.19      # LENOVO-TAB-M10")
    WriteStringN(OUT, "192.168.1.20      # SMARTPHONE")
    WriteStringN(OUT, "192.168.1.21      # CHROMEBOOK-WIFI")
    WriteStringN(OUT, "192.168.1.22      # CHROMEBOOK-GE")
    WriteStringN(OUT, "192.168.1.23      # PLAYER-POP-FE")
    WriteStringN(OUT, "192.168.1.24      # PLAYER-POP-WIFI")
    CloseFile(OUT)
  EndIf
EndIf

If Not fileExist(#messages_files$)
  OUT = CreateFile(#PB_Any, #messages_files$, #PB_UTF8)
  If OUT
    CloseFile(OUT)
  EndIf
EndIf

Global menuFichier
Global menuLiens
Global menuApplications
Global menuReseau
Global menuDevice
Global menuPaquet
Global menuMessages
Global menuServeur

#sp1$ = " "  ; 1 espace
#sp2$ = "  " ; 2 espaces

;=====================================================================
;=== CONSTANTES A MODIFIER POUR CORRESPONDRE A VOTRE CONFIGURATION ===
;=====================================================================
#option_quit      = #True
;
;;; #editor$      = "notepad.exe"
#editor$          = "Y:\YH\TOOLS\NPP\notepad++.exe"
;
;;;#anlink        = "C:\Users\"+UserName()+"\appdata\roaming\anlink\anlink.exe"
#anlink$          = "shell:AppsFolder\ECOLINK.AnLink_6nqsq1n47svzt!ink.anl.AnLink"
;
#adbappcontrol$   = "Y:\ADB\ADBAppControl\ADBAppControl.exe"
;
#myphoneExplorer$ = "C:\Program Files (x86)\MyPhoneExplorer\MyPhoneExplorer.exe"
;
;;; #vysor$       = "C:\Users\"+UserName()+"\admin\AppData\Local\vysor\Vysor.exe"
#vysor$           = "Y:\ADB\Vysor\vysor.exe"
;
;;; #anydesk$     = "C:\Program Files (x86)\AnyDesk\AnyDesk.exe"
#anydesk$         = "Y:\YH\PAF\PortableApps\Anydesk+\AnyDesk7.0.14.exe"
;
#source_adb$      = "Y:\ADB\"
#source_apk$      = "Y:\ADB\APK\"
;=====================================================================

main()

ErrorHandler:

End

Procedure.a initSysTray()
  If FindWindow_("Progman", #NUL) <> 0
    AddSysTrayIcon(#WinApp, WindowID(#WinApp), IconApp)
    SysTrayIconToolTip(#WinApp, #WinAppTitle)
  EndIf
EndProcedure

Procedure window_Callback(win, msg, wParam, lParam)
  Protected Result = #PB_ProcessPureBasicEvents
  Select Msg
    Case TB_Message ; explorer crash
      initSysTray()
  EndSelect
  ProcedureReturn Result
EndProcedure

Procedure.a hideAppWindow()
  SetWindowState(#WinApp, #PB_Window_Minimize)
  HideWindow(#WinApp, #True)
EndProcedure

Procedure.a showAppWindow()
  HideWindow(#WinApp, #False)
  SetWindowState(#WinApp, #PB_Window_Normal)
EndProcedure

Procedure.a appQuit()
  Protected response, msgflags, message$
  response = #PB_MessageRequester_Yes
  msgflags = #PB_MessageRequester_YesNo|#PB_MessageRequester_Warning
  If #option_quit
      message$ = "Voulez vous fermer l'application ?"
      response = MessageRequester(#WinAppTitle,message$,msgflags)
  EndIf
  If response = #PB_MessageRequester_Yes
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure

Procedure.a fileExist(f$)
  If FileSize(f$) < 0
    ProcedureReturn #False
  Else
    ProcedureReturn #True
  EndIf
EndProcedure

Procedure.a cocher_menu_item(item)
  Protected Result, State
  Result = GetMenuItemState(#MenuApp, item)
  If Result
    State = #False
  Else
    State = #True
  EndIf
  SetMenuItemState(#MenuApp, item, State)
  ProcedureReturn State
EndProcedure

Procedure.a main()
  Protected X,Y
  ExamineDesktops()
  X = (DesktopWidth(0) -#WinAppWidth)/2
  Y = (DesktopHeight(0)-#WinAppHeight)/2
  
  Protected FLAGS = #PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_ScreenCentered
  
  If OpenWindow(#WinApp, X, Y, #WinAppWidth, #WinAppHeight, #WinAppTitle, FLAGS)
    
    SetWindowColor(#WinApp, #bgcolor)
    
    construire_app_main_menu()
    construire_app_tray_menu()
    construire_app_pop1_menu()
    construire_app_pop2_menu()
    construire_app_main_interface()
    documenter_app_combo_gadget("adb")
    
    AddKeyboardShortcut(#WinApp, #PB_Shortcut_Control|#PB_Shortcut_Q, #MenuAppQuit) ; quit
    AddKeyboardShortcut(#WinApp, #PB_Shortcut_Control|#PB_Shortcut_X, #MenuAppQuit) ; quit
    
    AddKeyboardShortcut(#WinApp, #PB_Shortcut_Return, #KeyEnter)
    
    Protected hInstance=GetModuleHandle_(#NUL)
    Protected lpdwProcessId=GetWindowThreadProcessId_(WindowID(#WinApp),#NUL)
    SetWindowsHookEx_(#WH_MOUSE,@onMouse(), hInstance, lpdwProcessId)
    
    CreateThread(@tester_serveur_adb(), #True)
    
    Protected i, N, OUT
    Protected Event, index, indexMenu, indexGadget, indexGadgetType, input$, msg$, response
    
    Repeat
      progr$=#Null$:param$=#Null$:foldr$=#Null$
      Event = WaitWindowEvent(20)
      Select Event
          ;====================
          ;=== EVENTS MENUS ===
          ;====================
        Case #PB_Event_Menu
          indexMenu = EventMenu()
          If indexMenu = #KeyEnter
            If GetActiveGadget() = #GadgetStringCmde
              If GetGadgetText(#GadgetStringCmde) <> #Empty$
                envoyer_commande()
                SetActiveGadget(#GadgetStringCmde)
              EndIf
            EndIf
            Continue
          EndIf
          Select indexMenu
            ;Popup1
            Case #MenuAppPopup To #MenuAppPopupEnd
              i=indexMenu-#MenuAppPopup
              documenter_app_combo_gadget(pop1(Str(i)))
            ;Fichier
            Case #MenuAppFile To #MenuAppFileEnd
              i=indexMenu-#MenuAppFile
              progr$=file(Str(i))\progr$
              param$=file(Str(i))\param$
              foldr$=file(Str(i))\foldr$
              pflags=file(Str(i))\pflags
              Select progr$
                Case "+" : construire_app_main_menu()
                Default  : RunProgram(progr$,param$,foldr$,pflags)
              EndSelect
            ;Liens
            Case #MenuAppLink To #MenuAppLinkEnd
              i=indexMenu-#MenuAppLink
              RunProgram(link(Str(i)),#Null$,#Null$)
            ;Réseau
            Case #MenuAppNetw To #MenuAppNetwEnd
              i=indexMenu-#MenuAppNetw
              progr$=netw(Str(i))\progr$
              param$=netw(Str(i))\param$
              If FindString(param$,"hosts",1,#PB_String_NoCase)
                runAsAdmin(progr$,param$)
              Else
                RunProgram(progr$,param$,#Null$)
              EndIf
            ;;Applications
            Case #MenuAppApps To #MenuAppAppsEnd
              i=indexMenu-#MenuAppApps
              progr$=apps(Str(i))\progr$
              param$=apps(Str(i))\param$
              foldr$=apps(Str(i))\foldr$
              RunProgram(progr$,param$,foldr$)
            ;;ADB:Device
            Case #MenuAppHost To #MenuAppHostEnd
              i=indexMenu-#MenuAppHost
              device$ = host(Str(i))\adress$
              For N=#MenuAppHost To #MenuAppHostEnd
                SetMenuItemState(#MenuApp, N, #False)
              Next
              cocher_menu_item(indexMenu)
              StatusBarText(#GadgetStatusBar, 0, #DEVICE$+device$)
              StatusBarText(#GadgetStatusBar, 1, host(Str(i))\comment$)
            ;;ADB:Device
            Case #MenuAppDevice
              device$ = InputRequester("Documenter une adresse IP", "Entrez une adresse IP (Ex: 192.168.1.21)", "192.168.1.")
              Define long = Len(device$)
              If CountString(device$,".") <> 3
                device$ = #Null$
              ElseIf long > 15
                device$ = #Null$
              Else
                For N = 1 To long
                  If Mid(device$,N,1) <> "."
                    If Mid(device$,N,1) > Chr(57) Or
                       Mid(device$,N,1) < Chr(48)
                      device$ = #Null$
                      Break
                    EndIf
                  EndIf
                Next
                For N = 1 To 4
                  If Bool(Val(StringField(device$, N, ".")) < 0) Or
                     Bool(Val(StringField(device$, N, ".")) > 255) Or
                     StringField(device$, N, ".") = ""
                    device$ = #Null$
                    Break
                  EndIf
                Next
                StatusBarText(#GadgetStatusBar, 0, #DEVICE$+device$)
                StatusBarText(#GadgetStatusBar, 1, "?")
              EndIf
            Case #MenuAppEdit
              RunProgram(#devices_file$)
            ;;ADB:Paquet
            Case #MenuAppPaquet
              paquet$ = OpenFileRequester("Sélectionner un paquet Android", #source_apk$, "*.apk", 0)
              paquet$ = Chr(34)+paquet$+Chr(34)
              StatusBarText(#GadgetStatusBar, 2, #PAQUET$+GetFilePart(paquet$))
            ;;Messages
            Case #MenuAppMsgClear
              ClearGadgetItems(#GadgetEditor)
            Case #MenuAppMsgCopy
              ClearClipboard()
              msg$ = GetGadgetText(#GadgetEditor)
              SetClipboardText(msg$)
            Case #MenuAppMsgSave
              OUT = CreateFile(#PB_Any, #messages_files$, #PB_UTF8)
              If OUT
                msg$ = GetGadgetText(#GadgetEditor)
                WriteStringN(OUT, msg$)
              EndIf
              CloseFile(OUT)
            Case #MenuAppMsgEdit
              RunProgram(#messages_files$)
            ;;Bouton Quit & Systray Fermer l'application
            Case #MenuAppQuit
              If appQuit() : Break : EndIf
            ;;SysTray Titre
            Case #MenuAppShow
              showAppWindow()
          EndSelect
          ;=====================
          ;=== EVENTS GADGET ===
          ;=====================
        Case #PB_Event_Gadget
          indexGadget     = EventGadget()
          indexGadgetType = EventType()
          Select indexGadget
            Case #GadgetButtonPick
              DisplayPopupMenu(#MenuAppPop1, WindowID(#WinApp))
            Case #GadgetButtonQuit
              If appQuit() : Break : EndIf
            Case #GadgetButtonSend
              envoyer_commande()
            Case #GadgetCombo
              Select indexGadgetType
                Case #PB_EventType_Change
                  index  = GetGadgetState(#GadgetCombo)
                  input$ = Trim(GetGadgetItemText(#GadgetCombo, index))
                  input$ = Trim(StringField(input$,1,"|"))
                  If index=0 Or input$=#Empty$ Or Left(input$,1)=">"
                    Continue
                  EndIf
                  For N=0 To 10 : WindowEvent() : Next
                  input$ = tester_elevate(input$) ; renvoi texte du menu sans * et elevate=true si (* en fin du menu et admin=true)
                  SetGadgetState(#GadgetCombo, 0)
                  progr$ = StringField(input$, 1, #sp1$)
                  param$ = #Empty$
                  For N = 2 To CountString(input$, #sp1$)+1
                    param$ + StringField(input$, N, #sp1$)+#sp1$
                  Next
                  param$ = Trim(StringField(param$,1,"|"))
                  For N=0 To 10 : WindowEvent() : Next
                  If FindString(param$, #IP$) And device$ <> #Null$
                    param$ = ReplaceString(param$, #IP$, device$)
                  EndIf
                  If FindString(param$, #APK$) And paquet$ <> #Null$
                    param$ = ReplaceString(param$, #APK$, paquet$)
                  EndIf
                  If FindString(param$, #LOG$)
                    param$ = ReplaceString(param$, #LOG$, #journal_file$)
                  EndIf
                  SetGadgetText(#GadgetStringCmde, #Empty$)
                  SetGadgetText(#GadgetStringCmde, progr$+#sp1$+param$)
              EndSelect
          EndSelect
          ;======================
          ;=== EVENTS SYSTRAY ===
          ;======================
        Case #PB_Event_SysTray
          Select EventType()
            Case #PB_EventType_RightClick
              DisplayPopupMenu(#MenuTray, WindowID(#WinApp))
              
            Case #PB_EventType_LeftClick
              If GetWindowState(#WinApp) = #PB_Window_Normal
                hideAppWindow()
              Else
                showAppWindow()
              EndIf
          EndSelect
          ;=======================
          ;=== EVENTS SYSTEMES ===
          ;=======================
        Case #PB_Event_CloseWindow
          ;Break
          SetWindowState(#WinApp, #PB_Window_Minimize)
      EndSelect
    ForEver
  EndIf

ErrorHandler:

End
EndProcedure

Procedure.a construire_app_main_menu()
  Protected i, m, IN, foo$
  ClearMap(file())
  ClearMap(link())
  ClearMap(netw())
  ClearMap(apps())
  ClearMap(host())
  If CreateImageMenu(#MenuApp, WindowID(#WinApp), #PB_Menu_ModernLook)
    ;;;================================================
    MenuTitle("Fichier")
    m=0
    menuFichier = m
    i=-1
    i+1:MenuItem(#MenuAppFile+i, "Éditer "+#devices_file$)
       ;file(Str(i))\progr$=#editor$
       ;file(Str(i))\param$=#devices_file$
        file(Str(i))\progr$=#devices_file$
    i+1:MenuItem(#MenuAppFile+i, "Relecture "+#devices_file$)
        file(Str(i))\progr$="+"
    i+1:MenuItem(#MenuAppFile+i, "Tuer process adb.exe ")
        file(Str(i))\progr$="taskkill.exe"
        file(Str(i))\param$="/f /im adb.exe"
        file(Str(i))\pflags=#PB_Program_Hide
    i+1:MenuItem(#MenuAppFile+i, "Ouvrir dossier application")
        file(Str(i))\progr$=GetPathPart(ProgramFilename())
    i+1:MenuItem(#MenuAppFile+i, "Ouvrir dossier des paquets")
        file(Str(i))\progr$=#source_apk$
    i+1:MenuItem(#MenuAppFile+i, "Ouvrir Invite de commandes")
        file(Str(i))\progr$="cmd.exe"
        file(Str(i))\foldr$=#source_adb$
    MenuBar()
    i+1:MenuItem(#MenuAppFile+i, "Variables d'environnement")
        file(Str(i))\progr$="rundll32.exe"
        file(Str(i))\param$="sysdm.cpl,EditEnvironmentVariables"
    MenuBar()
    MenuItem(#MenuAppQuit, "Fermer l'application"+Chr(9)+"Ctrl+Q")
    CompilerIf #PB_Compiler_Debugger
      If #MenuAppFile+i > #MenuAppFileEnd
        Debug #CRLF$+"#MenuAppFile > #MenuAppFileEnd"
        Debug #CRLF$+"#MenuAppFileEnd = #MenuAppFile + " + Str(i)
        End
      EndIf
    CompilerEndIf
    ;;;================================================
    MenuTitle("Liens")
    m+1
    menuLiens = m
    i=-1
    i+1:MenuItem(#MenuAppLink+i, "Télécharger ADB")
        DisableMenuItem(#MenuApp,#MenuAppLink+i,#True)
    i+1:MenuItem(#MenuAppLink+i, "Notes de version du composant SDK Platform Tools", IconWeb)
        link(Str(i))="https://developer.android.com/studio/releases/platform-tools?hl=fr"
    i+1:MenuItem(#MenuAppLink+i, "Télécharger la version Windows du composants SDK Platform-Tools", IconWeb)
        link(Str(i))="https://dl.google.com/android/repository/platform-tools-latest-windows.zip?hl=fr"
    i+1:MenuItem(#MenuAppLink+i, "Documentation en ligne ADB", IconWeb)
        link(Str(i))="https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/master/docs/user/adb.1.md"
    MenuBar()
    i+1:MenuItem(#MenuAppLink+i, "Google Play")
        DisableMenuItem(#MenuApp,#MenuAppLink+i,#True)
    i+1:MenuItem(#MenuAppLink+i, "Applications Android sur Google Play", IconWeb)
        link(Str(i))="https://play.google.com/store/apps/"
    CompilerIf #PB_Compiler_Debugger
      If #MenuAppLink+i > #MenuAppLinkEnd
        Debug #CRLF$+"#MenuAppLink > #MenuAppLinkEnd"
        Debug #CRLF$+"#MenuAppLinkEnd = #MenuAppLink + " + Str(i)
        End
      EndIf
    CompilerEndIf
    ;;;================================================
    MenuTitle("Réseau")
    m+1
    menuReseau = m
    i=-1
    i+1:MenuItem(#MenuAppNetw+i, "Propriétés système")
        netw(Str(i))\progr$="sysdm.cpl"
    i+1:MenuItem(#MenuAppNetw+i, "Connexions réseau")
        netw(Str(i))\progr$="ncpa.cpl"
    i+1:MenuItem(#MenuAppNetw+i, "Centre Réseau et partage")
        netw(Str(i))\progr$="control.exe"
        netw(Str(i))\param$="/name Microsoft.NetworkAndSharingCenter"
    i+1:MenuItem(#MenuAppNetw+i, "Tous les Panneaux de configuration")
        netw(Str(i))\progr$="control.exe"
    i+1:MenuItem(#MenuAppNetw+i, "Gestionnaire des tâches")
        netw(Str(i))\progr$="taskmgr.exe"
    i+1:MenuItem(#MenuAppNetw+i, "Gestionnaire de périphériques")
        netw(Str(i))\progr$="hdwwiz.cpl"
    MenuBar()
    i+1:MenuItem(#MenuAppNetw+i, "Éditer fichier /etc/hosts système *")
        netw(Str(i))\progr$=#editor$
        netw(Str(i))\param$="c:\windows\system32\drivers\etc\hosts"
    CompilerIf #PB_Compiler_Debugger
      If #MenuAppNetw+i > #MenuAppNetwEnd
        Debug #CRLF$+"#MenuAppNetw > #MenuAppNetwEnd"
        Debug #CRLF$+"#MenuAppNetwEnd = #MenuAppNetw + " + Str(i)
        End
      EndIf
    CompilerEndIf
    ;;;================================================
    MenuTitle("Applications")
    m+1
    menuApplications = m
    i+1:MenuItem(#MenuAppApps+i, "ADB AppControl")
        apps(Str(i))\progr$=#adbappcontrol$
    i+1:MenuItem(#MenuAppApps+i, "ADB AppControl accueil", IconWeb)
        apps(Str(i))\progr$="https://adbappcontrol.com/en/"
    MenuBar()
    i+1:MenuItem(#MenuAppApps+i, "AnLink")
        apps(Str(i))\progr$=#anlink$
       ;apps(Str(i))\progr$="c:\users\"+UserName()+"\appdata\roaming\anlink\anlink.exe"
    i+1:MenuItem(#MenuAppApps+i, "AnLink accueil", IconWeb)
        apps(Str(i))\progr$="https://anl.ink"
    MenuBar()
    i+1:MenuItem(#MenuAppApps+i, "MyPhoneExplorer")
        apps(Str(i))\progr$=#myphoneExplorer$
    i+1:MenuItem(#MenuAppApps+i, "MyPhoneExplorer accueil", IconWeb)
        apps(Str(i))\progr$="https://www.fjsoft.at/en/"
    i+1:MenuItem(#MenuAppApps+i, "MyPhoneExplorer forum", IconWeb)
        apps(Str(i))\progr$="https://www.fjsoft.at/en/Forum/"
    MenuBar()
    i+1:MenuItem(#MenuAppApps+i, "Vysor")
        apps(Str(i))\progr$=#vysor$
    i+1:MenuItem(#MenuAppApps+i, "Vysor accueil", IconWeb)
        apps(Str(i))\progr$="https://www.vysor.io"
    MenuBar()
    i+1:MenuItem(#MenuAppApps+i, "Anydesk")
        apps(Str(i))\progr$=#anydesk$
    i+1:MenuItem(#MenuAppApps+i, "Anydesk accueil", IconWeb)
        apps(Str(i))\progr$="https://anydesk.com/fr"
    CompilerIf #PB_Compiler_Debugger
      If #MenuAppApps+i > #MenuAppAppsEnd
        Debug #CRLF$+"#MenuAppApps > #MenuAppAppsEnd"
        Debug #CRLF$+"#MenuAppAppsEnd = #MenuAppApps + " + Str(i)
        End
      EndIf
    CompilerEndIf
    ;;;================================================
    MenuTitle("ADB:Device")
    m+1
    menuDevice = m
        MenuItem(#MenuAppDevice, "Documenter une adresse IP")
        MenuBar()
    If fileExist(#devices_file$)
      IN = OpenFile(#PB_Any, #devices_file$, #PB_UTF8)
      If IN
        i=-1
        While Eof(IN) = 0
          foo$ = Trim(ReadString(IN))
          If foo$ = #Null$
            Continue
          Else
            i+1:MenuItem(#MenuAppHost+i, foo$)
            host(Str(i))\adress$  = Trim(StringField(foo$, 1, "#"))
            host(Str(i))\comment$ = Trim(StringField(foo$, 2, "#"))
          EndIf
        Wend
        CloseFile(IN)
      EndIf
    EndIf
    MenuBar()
    MenuItem(#MenuAppEdit, "Éditer "+#devices_file$)
    CompilerIf #PB_Compiler_Debugger
      If #MenuAppHost+i > #MenuAppHostEnd
        Debug #CRLF$+"#MenuAppHost > #MenuAppHostEnd"
        Debug #CRLF$+"#MenuAppHostEnd = #MenuAppHost + " + Str(i)
        End
      EndIf
    CompilerEndIf
    ;;;================================================
    MenuTitle("ADB:Paquet")
    m+1
    menuPaquet = m
        MenuItem(#MenuAppPaquet, "Sélectionner un paquet")
    ;;;================================================
    MenuTitle("Messages")
    m+1
    menuMessages = m
        MenuItem(#MenuAppMsgClear, "Éffacer les messages")
        MenuItem(#MenuAppMsgCopy , "Copier les messages")
        MenuItem(#MenuAppMsgSave , "Enregistrer les messages")
        MenuItem(#MenuAppMsgEdit , "Éditer "+#messages_files$)
    ;;;================================================
    MenuTitle(#Empty$)
    m+1
    menuServeur = m
    EnableMenuItem_(GetMenu_(WindowID(#WinApp)),menuServeur,#MF_BYPOSITION|#MF_GRAYED)
    SetMenuDefaultItem_(MenuID(#MenuApp),menuServeur,#True)
  EndIf
EndProcedure

Procedure.a construire_app_main_interface()
  Protected X,Y,W,H
  
  CreateStatusBar(#GadgetStatusBar , WindowID(#WinApp))
  AddStatusBarField(#WinAppWidth*0.214) ; ~150
  AddStatusBarField(#WinAppWidth*0.226) ; ~160
  AddStatusBarField(#PB_Ignore)
  AddStatusBarField(#WinAppWidth*0.143) ; ~100
  StatusBarText(#GadgetStatusBar, 0, #DEVICE$)
  StatusBarText(#GadgetStatusBar, 1, #Null$)
  StatusBarText(#GadgetStatusBar, 2, #PAQUET$)
  StatusBarText(#GadgetStatusBar, 3, mode$, #PB_StatusBar_Center)
  
  X=1:Y=0:W=20:H=24
  
  ButtonGadget(#GadgetButtonPick, X, Y, W, H, "..")
  GadgetToolTip(#GadgetButtonPick, "Sélectionner une liste de commandes")
  
  X=W+2:Y=1:W=#WinAppWidth-(X+2):H=22:W-50
  
  ComboBoxGadget(#GadgetCombo, X, Y, W, H)
  SetGadgetColor(#GadgetCombo, #PB_Gadget_BackColor , #bgcolor)
  SetGadgetColor(#GadgetCombo, #PB_Gadget_FrontColor, #fgcolor)
  GadgetToolTip(#GadgetCombo, "Sélectionner une commande")
  
  X=W+23:Y=0:W=50:H=24
  ButtonGadget(#GadgetButtonQuit, X, Y, W, H, "Fermer")
  GadgetToolTip(#GadgetButtonQuit, "Fermer l'application")
  
  X=1:Y=24:W=#WinAppWidth-(X*2):H=#WinAppHeight-MenuHeight()-StatusBarHeight(#GadgetStatusBar)-(Y*2)-1;(Y*2)
  
  EditorGadget(#GadgetEditor, X, Y, W, H,#PB_Editor_ReadOnly)
  SetGadgetColor(#GadgetEditor, #PB_Gadget_BackColor , #bgcolor)
  SetGadgetColor(#GadgetEditor, #PB_Gadget_FrontColor, #fgcolor)
  
  X=1
  Y=GadgetHeight(#GadgetButtonPick)+GadgetHeight(#GadgetEditor)+1
  W=#WinAppWidth-80-2
  H=22
  StringGadget(#GadgetStringCmde, X, Y, W, H, #Empty$)
  GadgetToolTip(#GadgetStringCmde, "Ligne de commande")
  
  SetGadgetColor(#GadgetStringCmde, #PB_Gadget_BackColor , #bgcolor)
  SetGadgetColor(#GadgetStringCmde, #PB_Gadget_FrontColor, #fgcolor)
  
  X=W+1
  Y=GadgetHeight(#GadgetButtonPick)+GadgetHeight(#GadgetEditor)
  W=80:H=24
  ButtonGadget(#GadgetButtonSend, X, Y, W, H, "Envoyer")
  GadgetToolTip(#GadgetButtonSend, "Exécuter la commande")
  
;   If RegisterFontFile("Police.ttf")
;     If LoadFont(#Font0, "Police", 10)
;       SetGadgetFont(#GadgetCombo  , FontID(#Font0))
;       SetGadgetFont(#GadgetEditor , FontID(#Font0))
;     EndIf
;   EndIf
  
  If LoadFont(#Font0, "Consolas", 10)
    SetGadgetFont(#GadgetCombo  , FontID(#Font0))
    SetGadgetFont(#GadgetEditor , FontID(#Font0))
  EndIf
EndProcedure

Procedure.a construire_app_tray_menu()
  SetWindowCallback(@window_Callback(),#WinApp) ; crash explorer
  
  initSysTray()
  
  If CreatePopupImageMenu(#MenuTray, #PB_Menu_ModernLook)
    MenuItem(#MenuAppShow  , #WinAppTitle , IconApp)
    MenuBar()
    MenuItem(#MenuAppQuit  ,"Fermer l'application")
  EndIf
EndProcedure

Procedure.a construire_app_pop1_menu()
  Protected i
  ClearMap(pop1())
  If CreatePopupImageMenu(#MenuAppPop1, #PB_Menu_ModernLook)
    i=-1
    i+1:MenuItem(#MenuAppPopup+i, "Commandes:")
    DisableMenuItem(#MenuAppPop1, #MenuAppPopup+i, #True)
    i+1:MenuItem(#MenuAppPopup+i, "commandes adb")
    pop1(Str(i))="adb"
    i+1:MenuItem(#MenuAppPopup+i, "commandes adb logs")
    pop1(Str(i))="logs"
    MenuBar()
    i+1:MenuItem(#MenuAppPopup+i, "commandes réseaux")
    pop1(Str(i))="netw"
    MenuBar()
    MenuItem(#MenuAppQuit ,"Fermer l'application")
  EndIf
  CompilerIf #PB_Compiler_Debugger
    If #MenuAppPopup+i > #MenuAppPopupEnd
      Debug #CRLF$+"#MenuAppPopup > #MenuAppPopupEnd"
      Debug #CRLF$+"#MenuAppPopupEnd = #MenuAppPopup + " + Str(i)
      End
    EndIf
  CompilerEndIf
EndProcedure

Procedure.a construire_app_pop2_menu()
  Protected i
  If CreatePopupImageMenu(#MenuAppPop2, #PB_Menu_ModernLook)
    MenuItem(#MenuAppMsgTitle, "Messages:")
    MenuItem(#MenuAppMsgClear, "Éffacer les messages")
    MenuItem(#MenuAppMsgCopy , "Copier les messages")
    MenuItem(#MenuAppMsgSave , "Enregistrer les messages")
    MenuItem(#MenuAppMsgEdit , "Éditer messages.txt")
    MenuBar()
    MenuItem(#MenuAppDevice  , "Entrer une adresse IP")
    MenuItem(#MenuAppPaquet  , "Sélectionner un paquet")
    MenuBar()
    MenuItem(#MenuAppQuit    , "Fermer l'application")
    DisableMenuItem(#MenuAppPop2, #MenuAppMsgTitle, #True)
  EndIf
EndProcedure

Procedure.a documenter_app_combo_gadget(cmds$)
  ClearGadgetItems(#GadgetCombo)
  Select cmds$
  Case "netw"
  AddGadgetItem(#GadgetCombo, -1,"> Sélectionnez une commande (* nécessite les droits admin)")
  AddGadgetItem(#GadgetCombo, -1,"arp -a")
  AddGadgetItem(#GadgetCombo, -1,"getmac /v /fo list")
  AddGadgetItem(#GadgetCombo, -1,"ipconfig")
  AddGadgetItem(#GadgetCombo, -1,"ipconfig /all")
  AddGadgetItem(#GadgetCombo, -1,"ipconfig /displaydns")
  AddGadgetItem(#GadgetCombo, -1,"ipconfig /flushdns")
  AddGadgetItem(#GadgetCombo, -1,"ipconfig /registerdns *")
  AddGadgetItem(#GadgetCombo, -1,"ipconfig /release")
  AddGadgetItem(#GadgetCombo, -1,"ipconfig /renew")
  AddGadgetItem(#GadgetCombo, -1,"net share")
  AddGadgetItem(#GadgetCombo, -1,"netstat -rn")
  AddGadgetItem(#GadgetCombo, -1,"ping %IP%")
  AddGadgetItem(#GadgetCombo, -1,"route print")
  AddGadgetItem(#GadgetCombo, -1,"set")
  AddGadgetItem(#GadgetCombo, -1,"PATH")
  Case "adb"
  AddGadgetItem(#GadgetCombo, -1,"> Sélectionnez une commande ADB via Ethernet, Wifi ou USB")
  AddGadgetItem(#GadgetCombo, -1,"adb help                   | affiche l'aide d'adb")
  AddGadgetItem(#GadgetCombo, -1,"adb version                | affiche la version d'adb")
  AddGadgetItem(#GadgetCombo, -1,"adb start-server           | active le serveur adb")
  AddGadgetItem(#GadgetCombo, -1,"adb tcpip 5555             | écoute une connexion sur le port 5555")
  AddGadgetItem(#GadgetCombo, -1,"adb kill-server            | arrête le serveur adb")
  AddGadgetItem(#GadgetCombo, -1,"adb connect %IP%           | se connecte a l'adresse %IP%[:5555]")
  AddGadgetItem(#GadgetCombo, -1,"adb devices -l             | affiche la liste des appareils connectés")
  AddGadgetItem(#GadgetCombo, -1,"adb disconnect             | se déconnecte de l'adresse %IP%[:5555], ou de toutes")
  AddGadgetItem(#GadgetCombo, -1,"adb install %APK%          | installe le paquet %APK%")
  AddGadgetItem(#GadgetCombo, -1,"adb shell id               | identifie l'utilisateur courant uid=0(root) gid=0(root)")
  AddGadgetItem(#GadgetCombo, -1,"adb reboot                 | effectue un reboot de l'appareil")
  AddGadgetItem(#GadgetCombo, -1,"adb shell pm list packages | affiche les paquets installés")
  Case "logs"
  AddGadgetItem(#GadgetCombo, -1,"> Sélectionnez une commande ADB via Ethernet, Wifi ou USB")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat            | affiche le journal de l'appareil Android (Terminer par CRTL+C)")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat -b main    | affiche le journal principal")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat -b events  | affiche le journal des événements")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat -b radio   | affiche le journal de la radio/téléphonie")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat -b system  | affiche le journal systéme")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat -c         | efface le journal")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat -d         | affiche le journal a l'écran et se termine")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat -g         | affiche la taille du journal")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat *:V        | affiche le journal niveau Verbose")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat *:D        | affiche le journal niveau Debug")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat *:I        | affiche le journal niveau Info")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat *:W        | affiche le journal niveau Warning")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat *:E        | affiche le journal niveau Error")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat *:F        | affiche le journal niveau Fatal")
  AddGadgetItem(#GadgetCombo, -1,"adb logcat -d > %LOG% | sauvegarde le journal dans %LOG%")
  AddGadgetItem(#GadgetCombo, -1,"adb shell dumpsys                      | dump systéme")
  AddGadgetItem(#GadgetCombo, -1,"adb shell dumpsys battery              | dump batterie")
  AddGadgetItem(#GadgetCombo, -1,"adb shell dumpsys batterystats         | dump batterie statistiques")
  AddGadgetItem(#GadgetCombo, -1,"adb shell dumpsys batterystats --reset | dump batterie statistiques et remise à zéro")
  AddGadgetItem(#GadgetCombo, -1,"adb shell dumpsys meminfo              | dump mémoire")
  AddGadgetItem(#GadgetCombo, -1,"adb backup -all -f Android.backup      | backup complet de l'appareil")
  EndSelect
  SetGadgetState(#GadgetCombo, 0)
EndProcedure

Procedure.a envoyer_commande()
  Protected input$, msg$, N, response
  input$ = Trim(GetGadgetText(#GadgetStringCmde))
  If input$ = #Empty$
    ProcedureReturn 
  EndIf
  While CountString(input$, #sp2$) > 0
    input$ = ReplaceString(input$, #sp2$, #sp1$)
  Wend
  progr$ = StringField(input$, 1, #sp1$)
  param$ = #Empty$
  For N = 2 To CountString(input$, #sp1$)+1
    param$ + StringField(input$, N, #sp1$)+#sp1$
  Next
  param$ = Trim(StringField(param$,1,"|"))
  If FindString(param$, #IP$) And device$ <> #Null$
    param$ = ReplaceString(param$, #IP$, device$)
  EndIf
  If FindString(param$, #APK$) And paquet$ <> #Null$
    param$ = ReplaceString(param$, #APK$, paquet$)
  EndIf
  If FindString(param$, #LOG$)
    param$ = ReplaceString(param$, #LOG$, #journal_file$)
  EndIf
  SetGadgetText(#GadgetStringCmde, progr$+#sp1$+param$)
  *Parameters.program = AllocateMemory(SizeOf(program))
  *Parameters\progr$ = progr$
  *Parameters\param$ = param$
  *Parameters\foldr$ = foldr$
  msg$ = "Voulez vous éxécuter la commande :"+#CRLF$+#CRLF$
  msg$ + progr$+#sp1$+param$
  response = MessageRequester(#WinAppTitle,msg$,#PB_MessageRequester_YesNo)
  If response = #PB_MessageRequester_Yes
    CreateThread(@lancer_programme(), *Parameters)
  EndIf
  SetGadgetText(#GadgetStringCmde, #Empty$)
  For N=0 To 10 : WindowEvent() : Next
EndProcedure

Procedure.s tester_elevate(input$)
  input$ = Trim(input$)
  If Right(input$,1) = "*"
    elevate = #True
    input$ = ReplaceString(input$, "*", #Empty$)
  Else
    elevate = #False
  EndIf
  While CountString(input$, "  ") > 0
    input$ = ReplaceString(input$, "  ", " ")
  Wend
  ProcedureReturn Trim(input$)
EndProcedure

Procedure.a lancer_programme(*Parameters.program)
  Protected progr$ = *Parameters\progr$
  Protected param$ = *Parameters\param$
  Protected foldr$ = *Parameters\foldr$
  
  DisableGadget(#GadgetCombo     , #True)
  DisableGadget(#GadgetStringCmde, #True)
  DisableGadget(#GadgetButtonPick, #True)
  DisableGadget(#GadgetButtonQuit, #True)
  DisableGadget(#GadgetButtonSend, #True)
  
  param$ = Trim(StringField(param$,1,"|"))
  
  ClearClipboard()
 ;ClearGadgetItems(#GadgetEditor)
  SetGadgetAttribute(#GadgetEditor,#PB_Editor_WordWrap,#False)
 ;AddGadgetItem(#GadgetEditor, -1, #Null$)
  AddGadgetItem(#GadgetEditor, -1, "Commande : "+progr$ + #sp1$ + param$)
  AddGadgetItem(#GadgetEditor, -1, #Null$)
  
  If progr$ = #Empty$
    Goto Abandon
   ;ProcedureReturn #False
  EndIf
  
  If elevate And admin = #False
    elevate = #False
    AddGadgetItem(#GadgetEditor, -1, #Null$)
    AddGadgetItem(#GadgetEditor, -1, "L'opération demandée nécessite une élévation.")
    AddGadgetItem(#GadgetEditor, -1, #Null$)
    Goto Abandon
   ;ProcedureReturn #False
  EndIf
  
  If FindString(param$, #APK$)
    If paquet$ <> #Null$
      param$ = ReplaceString(param$, #APK$, paquet$)
      ClearGadgetItems(#GadgetEditor)
     ;AddGadgetItem(#GadgetEditor, -1, #Null$)
      AddGadgetItem(#GadgetEditor, -1, "Commande : "+progr$ + " " + param$)
    Else
     ;AddGadgetItem(#GadgetEditor, -1, #Null$)
      AddGadgetItem(#GadgetEditor, -1, "Vous devez dabord choisir un fichier *.apk")
      AddGadgetItem(#GadgetEditor, -1, #Null$)
      Goto Abandon
     ;ProcedureReturn #False
    EndIf
  EndIf
  
  If FindString(param$, #IP$)
    If device$ <> #Null$
      param$ = ReplaceString(param$, #IP$, device$)
     ;ClearGadgetItems(#GadgetEditor)
     ;AddGadgetItem(#GadgetEditor, -1, #Null$)
      AddGadgetItem(#GadgetEditor, -1, "Commande : "+progr$ + " " + param$)
    Else
     ;AddGadgetItem(#GadgetEditor, -1, #Null$)
      AddGadgetItem(#GadgetEditor, -1, "Vous devez dabord choisir une adresse de device dans le menu ADB:Device")
      AddGadgetItem(#GadgetEditor, -1, #Null$)
      Goto Abandon
     ;ProcedureReturn #False
    EndIf
  EndIf
  
  If FindString(param$, #LOG$)
    param$ = ReplaceString(param$, #LOG$, #journal_file$)
   ;AddGadgetItem(#GadgetEditor, -1, #Null$)
    AddGadgetItem(#GadgetEditor, -1, "Commande : "+progr$ + " " + param$)
  EndIf
  
  If progr$ = "adb" And Not serveur_adb
    Select param$
      Case "help", "version", "start-server", "kill-server"
      Default
     ;AddGadgetItem(#GadgetEditor, -1, #Null$)
      AddGadgetItem(#GadgetEditor, -1, "Vous devez dabord activer le serveur adb")
      Goto Abandon
     ;ProcedureReturn #False
    EndSelect
  EndIf
  
  If FindString(param$, "logcat")
    If FindString(param$, " -c") Or
       FindString(param$, " -d") Or
       FindString(param$, " -g")
    Else
      RunProgram("cmd.exe","/c "+progr$+#sp1$+param$,#Empty$)
      Goto Abandon
     ;ProcedureReturn #True
    EndIf
  EndIf
  
  elevate = #False
  
  Protected i, n, rc
  Protected foo$, search$
  Protected program$ = LCase(GetFilePart(progr$,#PB_FileSystem_NoExtension))
  
  Select program$
    Case "path" : search$ = "path:"
    Default     : search$ = #Empty$
  EndSelect
  
  Protected parameter$ = "/c "+progr$+" "+param$+" 2>&1|clip"
  
  program$ = "cmd.exe"
  
  EnableMenuItem_(GetMenu_(WindowID(#WinApp)),menuDevice  ,#MF_BYPOSITION | #MF_GRAYED)
  EnableMenuItem_(GetMenu_(WindowID(#WinApp)),menuPaquet  ,#MF_BYPOSITION | #MF_GRAYED)
  EnableMenuItem_(GetMenu_(WindowID(#WinApp)),menuMessages,#MF_BYPOSITION | #MF_GRAYED)
  
  SetWindowTitle(#WinApp, #WinAppTitle+Space(60)+"Veuillez patienter...")
  
  RunProgram(program$,parameter$,#Empty$,#PB_Program_Wait|#PB_Program_Hide)
  
 ;AddGadgetItem(#GadgetEditor, -1, #Null$)
  AddGadgetItem(#GadgetEditor, -1, GetClipboardText())
  
  If search$ = "path:"
    search$ = GetClipboardText()
    If FindString(search$,"path=",1,#PB_String_NoCase)
      search$ = StringField(search$,2,"=")
      foo$ = search$
      i = 0
      n = CountString(search$, ";")+1
      While i < n
        i+1
        foo$ = StringField(search$,i,";")
        AddGadgetItem(#GadgetEditor, -1, foo$)
      Wend
    EndIf
  EndIf
  
Abandon:

  ClearClipboard()
  
  ClearStructure(*Parameters, program)
  FreeMemory(*Parameters)
  
  DisableGadget(#GadgetCombo     , #False)
  DisableGadget(#GadgetStringCmde, #False)
  DisableGadget(#GadgetButtonPick, #False)
  DisableGadget(#GadgetButtonQuit, #False)
  DisableGadget(#GadgetButtonSend, #False)
  
  EnableMenuItem_(GetMenu_(WindowID(#WinApp)),menuDevice  ,#MF_BYPOSITION)
  EnableMenuItem_(GetMenu_(WindowID(#WinApp)),menuPaquet  ,#MF_BYPOSITION)
  EnableMenuItem_(GetMenu_(WindowID(#WinApp)),menuMessages,#MF_BYPOSITION)
  
  SetWindowTitle(#WinApp, #WinAppTitle)
  
  ProcedureReturn #True
EndProcedure

Procedure   runAsAdmin(progr$=#Null$,param$=#Null$,foldr$=#Null$)
  Protected shExecInfo.SHELLEXECUTEINFO
  With shExecInfo
    \cbSize       = SizeOf(SHELLEXECUTEINFO)
    \lpVerb       = @"runas" ;;; @"open"
    \lpParameters = @param$
    \lpFile       = @progr$
    \lpDirectory  = @foldr$
    \nShow        = #SW_NORMAL
  EndWith
  ProcedureReturn ShellExecuteEx_(shExecInfo)
EndProcedure

Procedure.i getNamePID(ProcessName.s,*ptrPID)
  Protected HSnap.l,Prec.processentry32,result.l=#False
  HSnap=CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS,0)
  If HSnap=#INVALID_HANDLE_VALUE
    ProcedureReturn result
  EndIf
  Prec\dwSize=SizeOf(prec)
  If Not Process32First_(HSnap,Prec)
    ProcedureReturn result
  EndIf
  Repeat
    If LCase(GetFilePart(PeekS(@Prec\szexefile)))=LCase(ProcessName)
      PokeL(*ptrPID,Prec\th32ProcessID)
      result=#True
      Break
    EndIf
  Until Not Process32Next_(HSnap,Prec)
  CloseHandle_(HSnap)
  ProcedureReturn result
EndProcedure

Procedure.a tester_serveur_adb(*v)
  Protected space$ = Space(20)
  Protected ptrPID = 0
  Repeat
    ptrPID = 0
    If getNamePID("adb.exe",@ptrPID)
      serveur_adb = #True
      If IsMenu(#MenuApp)
        SetMenuTitleText(#MenuApp, menuServeur, space$+#server_adb_on$)
      EndIf
    Else
      serveur_adb = #False
      If IsMenu(#MenuApp)
        SetMenuTitleText(#MenuApp, menuServeur, space$+#server_adb_off$)
      EndIf
    EndIf
    If IsMenu(#MenuApp)
      EnableMenuItem_(GetMenu_(WindowID(#WinApp)),menuServeur,#MF_BYPOSITION|#MF_GRAYED)
    EndIf
    Delay(3000)
  ForEver
EndProcedure

Procedure.a onMouse(nCode,wParam,lParam)
  Select wParam
    Case #WM_RBUTTONDOWN
      DisplayPopupMenu(#MenuAppPop2, WindowID(#WinApp))
      ProcedureReturn 1
  EndSelect
  ProcedureReturn 0
EndProcedure

; IDE Options = PureBasic 6.00 LTS (Windows - x64)
; CursorPosition = 843
; FirstLine = 438
; Folding = PAC+4HLm7
; EnableThread
; EnableXP
; CompileSourceDirectory
; EnablePurifier