Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <DateTimeConstants.au3>
Global $hGUI, $idListview, $Heigh=400, $Width=600, $aUser, $iDate, $bOK, $bAdd, $bClose
Global $IndexItemListView, $Computer
Opt("GUIOnEventMode", 1)
_Ini()
_Main()
While GUIGetMsg() <> -3
WEnd
Func _Ini()
;On charge dans un tableau les Keys & Values de la section [USERS]
$aUser = IniReadSection(@ScriptDir & "\User.txt", "USERS")
_ArrayDelete($aUser, 0)
EndFunc
Func _Main()
$hGUI = GUICreate("Assistance à distance", $Width, $Heigh)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$idListview = GUICtrlCreateListView("Utilisateur|Nom poste", 0, 0, $Width, $Heigh - 120) ;,$LVS_SORTDESCENDING)
$iDate = GUICtrlCreateDate("", 2, $Heigh - 110, 100, 20, $DTS_SHORTDATEFORMAT)
$bOK = GUICtrlCreateButton("OK", 105, $Heigh - 110, 45, 20)
GUICtrlSetOnEvent($bOK, "_OK")
$bClose = GUICtrlCreateButton("Déconnexion", 2, $Heigh - 50, 150, 20)
GUICtrlSetOnEvent($bClose, "_Deconnexion")
$bAdd = GUICtrlCreateButton("Se connecter", 2, $Heigh - 70, 150, 20)
GUICtrlSetOnEvent($bAdd, "_Connexion")
If @error Then
MsgBox(4096, "", "Error occured, probably no INI file.")
Else
_GUICtrlListView_DeleteAllItems($idListview)
_GUICtrlListView_AddArray($idListview, $aUser)
EndIf
My_GUICtrlListView_AutoSizeColumns($idListview)
GUISetState(@SW_SHOW, $hGUI)
EndFunc
Func _Connexion()
$IndexItemListView = _GUICtrlListView_GetNextItem($idListview)
If $IndexItemListView = -1 Then MsgBox(16, "Erreur", "Choisir un utlisateur")
$Computer = _GUICtrlListView_GetItemText($idListview, $IndexItemListView, 1)
Run(@ComSpec & ' /c msra.exe /offerra ' & $Computer, @TempDir, @SW_HIDE)
EndFunc
Func _Deconnexion()
ConsoleWrite("Deconnexion" & @CRLF)
EndFunc
Func _OK()
ConsoleWrite(GUICtrlRead($iDate) & @CRLF)
EndFunc
Func _Exit()
Exit
EndFunc
Func My_GUICtrlListView_AutoSizeColumns($idListview, $iMini = 80)
If Not IsHWnd($idListview) Then $idListview = GUICtrlGetHandle($idListview)
Local $hHeader = _GUICtrlListView_GetHeader($idListview), $iHeader_Width, $iData_Width
_GUICtrlListView_BeginUpdate($idListview)
For $iIndex = 0 To _GUICtrlListView_GetColumnCount($idListview) - 1
If _GUICtrlListView_GetColumnWidth($idListview, $iIndex) = 0 Then ContinueLoop
_GUICtrlListView_SetColumnWidth($idListview, $iIndex, $LVSCW_AUTOSIZE_USEHEADER)
$iHeader_Width = _GUICtrlListView_GetColumnWidth($idListview, $iIndex)
If @OSVersion = "WIN_XP" And $iIndex < _GUICtrlListView_GetColumnCount($idListview) - 1 Then
If _GUICtrlHeader_GetItemFlags($hHeader, $iIndex) / 2 > 1 Then $iHeader_Width += 30
EndIf
_GUICtrlListView_SetColumnWidth($idListview, $iIndex, $LVSCW_AUTOSIZE)
$iData_Width = _GUICtrlListView_GetColumnWidth($idListview, $iIndex)
If $iHeader_Width > $iData_Width Then
_GUICtrlListView_SetColumnWidth($idListview, $iIndex, $iHeader_Width)
EndIf
If _GUICtrlListView_GetColumnWidth($idListview, $iIndex) < $iMini Then
_GUICtrlListView_SetColumnWidth($idListview, $iIndex, $iMini)
EndIf
Next
_GUICtrlListView_EndUpdate($idListview)
EndFunc ;==>My_GUICtrlListView_AutoSizeColumns