Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; #include <Array.au3>
#include <WinAPI.au3>
Dim $boutons[5][7] = [[0, "Exit", "_Exit", 0, 0, 0, 0], [0, "OK", "_OK", 0, 0, 0, 0], _
[0, "Enregistrer", "_Enregistrer", 0, 0, 0, 0], [0, "Tester", "_Tester", 0, 0, 0, 0], _
[0, "Lire le journal du Dimanche", "_Newspapa", 0, 0, 0, 0]]
; 0 id ; 1 texte ; 2 fonction ; 3 left pos ; 4 largeur ; 5 menuitem ajouter ; 6 menuitem enlever
$gui = GUICreate("my_amazing_toolbar", 0, 40, -1, -1, $WS_POPUP)
For $i = 0 To UBound($boutons) - 1
$boutons[$i][4] = _GetZeSizeOfZisText($boutons[$i][1])
If $i = 0 Then
$boutons[$i][3] = 0
Else
$boutons[$i][3] = $boutons[$i - 1][3] + $boutons[$i - 1][4]
EndIf
$guipos1 = WinGetPos($gui)
WinMove($gui, "", $guipos1[0], $guipos1[1], $guipos1[2] + $boutons[$i][4])
$boutons[$i][0] = GUICtrlCreateButton($boutons[$i][1], $boutons[$i][3], 15, $boutons[$i][4], 25)
GUICtrlSetBkColor($boutons[$i][0], 0xbadaff)
GUICtrlSetResizing($boutons[$i][0], 256 + 512 + 2)
$context = GUICtrlCreateContextMenu($boutons[$i][0])
$boutons[$i][5] = GUICtrlCreateMenuItem("Ajouter", $context)
$boutons[$i][6] = GUICtrlCreateMenuItem("Enlever", $context)
Next
$label = GUICtrlCreateLabel(" ici y en avoir du texte", 0, 0, 1000, 15, 0x1200, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, 0xffffff)
GUICtrlSetFont(-1, 8, 400, 0, "Courier New")
GUICtrlSetResizing($label, 1)
GUICtrlSetState($label, $GUI_FOCUS)
GUISetState()
;_ArrayDisplay($boutons)
While 1
$msg = GUIGetMsg()
For $i = 0 To UBound($boutons) - 1
Switch $msg
Case $boutons[$i][0] ; actions
Call($boutons[$i][2])
GUICtrlSetState($label, $GUI_FOCUS)
Case $boutons[$i][6] ; menu enlever
If $boutons[$i][1] <> "Exit" Then
$decal = $boutons[$i][4] ;size
$guipos = WinGetPos($gui)
WinMove($gui, "", $guipos[0], $guipos[1], $guipos[2] - $decal)
For $j = $i + 1 To UBound($boutons) - 1
$boutons[$j][3] = $boutons[$j][3] - $decal
ControlMove($gui, "", $boutons[$j][0], $boutons[$j][3], 15)
GUICtrlSetResizing($boutons[$j][0], 256 + 512 + 2)
Next
GUICtrlSetState($boutons[$i][0], $GUI_HIDE)
ExitLoop
EndIf
Case $boutons[$i][5] ; menu ajouter
$gui2 = GUICreate("titre", 120, 80, -1, -1, $WS_POPUP)
GUISetBkColor(0xbadaff)
$itext = GUICtrlCreateCombo("OK", 10, 10, 100, 18)
For $i = 2 To UBound($boutons) - 1
GUICtrlSetData($itext, $boutons[$i][1] & "|")
Next
$ibtn = GUICtrlCreateButton("OK", 10, 40, 40, 25)
$iexit = GUICtrlCreateButton("Annuler", 60, 40, 50, 25)
GUISetState()
While 1
$msg2 = GUIGetMsg()
Switch $msg2
Case $iexit
GUIDelete($gui2)
ExitLoop
Case $ibtn ; ok
$itexte = GUICtrlRead($itext)
GUIDelete($gui2)
For $i = 0 To UBound($boutons) - 1
If $itexte = $boutons[$i][1] Then
If BitAND(GUICtrlGetState($boutons[$i][0]), $GUI_SHOW) = $GUI_SHOW Then
ExitLoop 2
Else
GUICtrlSetState($boutons[$i][0], $GUI_SHOW)
ExitLoop
EndIf
EndIf
Next
$guipos2 = WinGetPos($gui)
WinMove($gui, "", $guipos2[0], $guipos2[1], $guipos2[2] + $boutons[$i][4])
For $j = $i + 1 To UBound($boutons) - 1
$boutons[$j][3] += $boutons[$i][4]
ControlMove($gui, "", $boutons[$j][0], $boutons[$j][3], 15)
GUICtrlSetResizing($boutons[$j][0], 256 + 512 + 2)
Next
_WinAPI_RedrawWindow($gui)
ExitLoop
EndSwitch
WEnd
$msg = ""
EndSwitch
Next
WEnd
Func _GetZeSizeOfZisText($mytext)
$hDC = _WinAPI_GetDC($gui)
$tSize = _WinAPI_GetTextExtentPoint32($hDC, $mytext)
_WinAPI_ReleaseDC($gui, $hDC)
Return DllStructGetData($tSize, "X") - StringLen($mytext)*2 + 30
EndFunc
Func _Exit()
Exit
EndFunc
Func _OK()
MsgBox(0, "", "toi y en a cliqué OK")
EndFunc
Func _Enregistrer()
MsgBox(0, "", "toi y en a cliqué Enregistrer")
EndFunc
Func _Tester()
MsgBox(0, "", "toi y en a cliqué Tester")
EndFunc
Func _Newspapa()
MsgBox(0, "", "toi y en a vouloir lire les nouvelles ?")
EndFunc