[Func] _GuiCreate_ListBox()
Posté : mer. 02 sept. 2009 17:02
par timmalos
Cette fonction sert à Modifier Graphiquement une ListView. Ie Monter Et Descendre 2 Elements, Modifier un 3Eme, etc...
Ainsi, il faut lui donner en parametre un Array à 1 Dimension
Et elle vous retournera Une Array à 1 Dimension Modifiée.
Si vous l'utilisez dans un programme, pensez à rajouter des tests.
Il faut copier coller le code ci-dessous dans votre programme, puis ecrire:
Peut être que faire un fichier complet et l'appeler en Include serait mieux
Vous pouvez Mettre les images dans le même répertoire, si vous ne les mettez pas le script marchera quand même.
Le pack d'image est donné dans le .zip
Ainsi, il faut lui donner en parametre un Array à 1 Dimension
Et elle vous retournera Une Array à 1 Dimension Modifiée.
Si vous l'utilisez dans un programme, pensez à rajouter des tests.
Il faut copier coller le code ci-dessous dans votre programme, puis ecrire:
Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <ListBoxConstants.au3>
#include <WindowsConstants.au3>
_GuiCreate_ListBox(StringSplit("Bonjour, Je, Suis, Timothée, Le Créateur, De Cette, Fonction",","))


Le pack d'image est donné dans le .zip
► Afficher le texte_GuiCreate_ListBo
Code : Tout sélectionner
Func _GuiCreate_ListBox($W_array)
$W_gui_delete = GUICreate("Scénario", 300, 480,-1,-1,-1)
GUISwitch($W_gui_delete)
GUICtrlCreateLabel("Liste des actions", 70, 14, 200, 25)
GUICtrlSetFont(-1, 15, -1, -1, "Verdana")
;$W_list = GUICtrlCreateList("", 10, 60, 280, 300)
If FileExists(@ScriptDir & "\Raise.ico") then
$style = Execute("$BS_ICON")
Else
$style = ""
EndIf
Global $hListBox = _GUICtrlListBox_Create($W_gui_delete,"",10, 60, 250, 300,$WS_VSCROLL, $LBS_NOTIFY)
Global $W_haut = GUICtrlCreateButton("H", 265, 70, 30, 30,$style)
GUICtrlSetImage(-1, @ScriptDir & "\Raise.ico")
Global $W_bas = GUICtrlCreateButton("B", 265, 102, 30, 30,$style)
GUICtrlSetImage(-1, @ScriptDir & "\Fall.ico")
Global $W_folder = GUICtrlCreateButton("B", 265, 150, 30, 30,$style)
GUICtrlSetImage(-1, @ScriptDir & "\Folder.ico")
Global $W_add = GUICtrlCreateButton("+", 265, 200, 30, 30,$style)
GUICtrlSetImage(-1, @ScriptDir & "\Add.ico")
Global $W_mod = GUICtrlCreateButton("M", 265, 232, 30, 30,$style)
GUICtrlSetImage(-1, @ScriptDir & "\Modify.ico")
Global $W_del = GUICtrlCreateButton("-", 265, 264, 30, 30,$style)
GUICtrlSetImage(-1, @ScriptDir & "\Trash.ico")
Global $W_copy = GUICtrlCreateButton("-", 265, 296, 30, 30,$style)
GUICtrlSetImage(-1, @ScriptDir & "\Copy.ico")
Global $W_input = GuiCtrlCreateInput("",40,365,150,20)
GUICtrlSetState($W_input,$GUI_HIDE)
Global $W_valider = GUICtrlCreateButton("V",195,360,30,30,$style)
GUICtrlSetImage(-1, @ScriptDir & "\Apply.ico")
Global $W_stop = GUICtrlCreateButton("V",228,360,30,30,$style)
GUICtrlSetImage(-1, @ScriptDir & "\Delete.ico")
GUICtrlSetState($W_valider,$GUI_HIDE)
Global $W_continue = GUICtrlCreateButton("Valider le Scénario",20,360,260,40)
Global $W_group = GUICtrlCreateGroup("",5,400,290,73)
Global $W_info = GUICtrlCreateLabel( "Action :" & @CRLF & "Position :" & @CRLF & "Description :", 10, 410, 280, 60)
GUICtrlSetState($W_info, $GUI_DISABLE)
GUISetState(@SW_SHOW,$W_gui_delete)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
_GUICtrlListBox_BeginUpdate($hListBox)
_GUICtrlListBox_ResetContent($hListBox)
_GUICtrlListBox_InitStorage($hListBox, 100, 4096)
For $W_i = 1 to UBound($W_array)-1
_GUICtrlListBox_AddString($hListBox,$W_array[$W_i])
Next
_GUICtrlListBox_EndUpdate($hListBox)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
If _Msg("Etes Vous vraiment certain de vouloir quitter l'assistant de création de scénarios?") = 1 Then
Guidelete($W_gui_delete)
Return 0
EndIf
Case $W_continue
Dim $return[_GUICtrlListBox_GetCount($hListBox)]
For $i = 0 to _GUICtrlListBox_GetCount($hListBox) -1
$return[$i] = _GUICtrlListBox_GetText($hListBox,$i)
Next
Guidelete($W_gui_delete)
Return $return
Case $W_add
_GuiAff(1)
Global $W_hAction = "ajouter"
$W_old_sel = _GUICtrlListBox_GetCurSel($hListBox)
Case $W_mod
If _GUICtrlListBox_GetCurSel($hListBox) = -1 Then
MsgBox(32,"Scénario","Erreur : Vous n'avez séléctionné aucune action.")
Else
_GuiAff(1)
Global $W_hAction = "modifier"
$W_old_sel = _GUICtrlListBox_GetCurSel($hListBox)
GUICtrlSetData($W_input,_GUICtrlListBox_GetText($hListBox,$W_old_sel))
EndIf
Case $W_folder
_GuiAff(0)
$i = -1
$ii = 1
$lasti = 3
While 1
$i = _GUICtrlListBox_FindInText($hListBox, "Action "&$ii)
If $i <> -1 then
$ii += 1
Else
$lasti = $i
ExitLoop
EndIf
WEnd
_GUICtrlListBox_InsertString($hListBox,"##{Action "&$ii&"}##",$lasti)
Case $W_copy
_GuiAff(0)
If _GUICtrlListBox_GetCurSel($hListBox) = -1 Then
MsgBox(32,"Scénario","Erreur : Vous n'avez séléctionné aucune action.")
Else
$W_old_sel = _GUICtrlListBox_GetCurSel($hListBox)
_GUICtrlListBox_AddString($hListBox,_GUICtrlListBox_GetText($hListBox,$W_old_sel))
_GUICtrlListBox_SetCurSel($hListBox, _GUICtrlListBox_GetCount($hListBox) -1)
$W_old_sel = _GUICtrlListBox_GetCurSel($hListBox)
GUICtrlSetData($W_info,"Action :"&_GUICtrlListBox_GetText($hListBox,$W_old_sel) & @CRLF & "Position :"&$W_old_sel + 1 & @CRLF & "Description :")
EndIf
Case $W_valider
Switch $W_hAction
Case "ajouter"
If GuiCtrlRead($W_input) = "" Then
MsgBox(32,"Scénario","Erreur : Vous devez rentrez un code action.")
Else
_GUICtrlListBox_InsertString($hListBox,GuiCtrlRead($W_input),$W_old_sel)
_GUICtrlListBox_SetCurSel($hListBox, $W_old_sel)
GUICtrlSetData($W_info,"Action :"&_GUICtrlListBox_GetText($hListBox,$W_old_sel) & @CRLF & "Position :"&$W_old_sel + 1 & @CRLF & "Description :")
EndIf
Case "modifier"
If GuiCtrlRead($W_input) = "" Then
MsgBox(32,"Scénario","Erreur : Vous devez rentrez un code action.")
Else
_GUICtrlListBox_ReplaceString($hListBox,$W_old_sel,GuiCtrlRead($W_input))
_GUICtrlListBox_SetCurSel($hListBox, $W_old_sel)
GUICtrlSetData($W_info,"Action :"&_GUICtrlListBox_GetText($hListBox,$W_old_sel) & @CRLF & "Position :"&$W_old_sel + 1 & @CRLF & "Description :")
EndIf
EndSwitch
Case $W_stop
_GuiAff(0)
_GUICtrlListBox_SetCurSel($hListBox, $W_old_sel)
Case $W_del
_GuiAff(0)
If _GUICtrlListBox_GetCurSel($hListBox) = -1 Then
MsgBox(32,"Scénario","Erreur : Vous n'avez séléctionné aucune action.")
Else
$W_old_sel = _GUICtrlListBox_GetCurSel($hListBox)
_GUICtrlListBox_DeleteString($hListBox,$W_old_sel)
_GUICtrlListBox_SetCurSel($hListBox, $W_old_sel)
GUICtrlSetData($W_info,"Action :"&_GUICtrlListBox_GetText($hListBox,$W_old_sel) & @CRLF & "Position :"&$W_old_sel + 1 & @CRLF & "Description :")
EndIf
Case $W_haut
_GuiAff(0)
If _GUICtrlListBox_GetCurSel($hListBox) = -1 Then
MsgBox(32,"Scénario","Erreur : Vous n'avez séléctionné aucune action.")
Else
$W_old_sel = _GUICtrlListBox_GetCurSel($hListBox)
If $W_old_sel > 0 then
_GUICtrlListBox_SwapString($hListBox,$W_old_sel, $W_old_sel - 1)
_GUICtrlListBox_SetCurSel($hListBox, $W_old_sel -1)
$W_old_sel = _GUICtrlListBox_GetCurSel($hListBox)
GUICtrlSetData($W_info,"Action :"&_GUICtrlListBox_GetText($hListBox,$W_old_sel) & @CRLF & "Position :"&$W_old_sel + 1 & @CRLF & "Description :")
EndIf
EndIf
Case $W_bas
_GuiAff(0)
If _GUICtrlListBox_GetCurSel($hListBox) = -1 Then
MsgBox(32,"Scénario","Erreur : Vous n'avez séléctionné aucune action.")
Else
$W_old_sel = _GUICtrlListBox_GetCurSel($hListBox)
If $W_old_sel < _GUICtrlListBox_GetCount($hListBox) -1 then
_GUICtrlListBox_SwapString($hListBox,$W_old_sel, $W_old_sel + 1)
_GUICtrlListBox_SetCurSel($hListBox, $W_old_sel +1)
$W_old_sel = _GUICtrlListBox_GetCurSel($hListBox)
GUICtrlSetData($W_info,"Action :"&_GUICtrlListBox_GetText($hListBox,$W_old_sel) & @CRLF & "Position :"&$W_old_sel + 1 & @CRLF & "Description :")
EndIf
EndIf
EndSwitch
Sleep(10)
WEnd
EndFunc
Func _GuiAff($func)
If $func = 1 And BitAnd(GUICtrlGetState($W_continue),$GUI_SHOW) Then
GUICtrlSetState($W_input,$GUI_SHOW)
GUICtrlSetState($W_valider,$GUI_SHOW)
GUICtrlSetState($W_continue,$GUI_HIDE)
GUICtrlSetState($W_stop,$GUI_SHOW)
ElseIf $func = 0 And BitAnd(GUICtrlGetState($W_continue),$GUI_HIDE) Then
GUICtrlSetState($W_input,$GUI_HIDE)
GUICtrlSetState($W_valider,$GUI_HIDE)
GUICtrlSetState($W_continue,$GUI_SHOW)
GUICtrlSetState($W_stop,$GUI_HIDE)
EndIf
EndFunc
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word
Switch $hWndFrom
Case $hListBox, $hWndListBox
_GuiAff(0)
Switch $iCode
Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
_DebugPrint("$LBN_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; no return value
ControlClick("Scénario","",$W_mod)
Case $LBN_SELCHANGE ; Sent when the selection in a list box has changed
GUICtrlSetData($W_info,"Action :"&_GUICtrlListBox_GetText($hListBox,_GUICtrlListBox_GetCurSel($hListBox)) & @CRLF & "Position :"&_GUICtrlListBox_GetCurSel($hListBox) + 1 & @CRLF & "Description :")
_DebugPrint("$LBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; no return value
EndSwitch
EndSwitch
; Proceed the default Autoit3 internal message commands.
; You also can complete let the line out.
; !!! But only 'Return' (without any value) will not proceed
; the default Autoit3-message in the future !!!
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
- _GuiCreate_ListBox.zip
- (13.33 Kio) Téléchargé 388 fois