StungStang 1 Posted January 17, 2011 Today im playing with a lot of fun with Autoit Toolbar Function : I've write this code : #include <GuiToolbar.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #Include <GuiImageList.au3> Local $hGUI, $hToolbar Local Enum $idNew = 1000, $id1, $id2 ; Create GUI $hGUI = GUICreate("Toolbar", 400, 300) $hToolbar = _GUICtrlToolbar_Create($hGUI) GUISetState() $hToolBarImageListNorm = _GUIImageList_Create(32, 32, 5, 3,3) _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll",131,1) _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll",146,1) _GUICtrlToolbar_SetImageList($hToolbar, $hToolBarImageListNorm) _GUICtrlToolbar_AddButton($hToolbar,$id1,0) ;Now is set icon numer 131 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If _GUICtrlToolbar_IsButtonPressed ($hToolbar,$id1) Then ;Set icon 146 to button ;If button is set on icon 146 switch the button on icon 131 EndIf WEnd How u can see i've an button, and i would like to set another icon to it, if the button is pressed... For example the button start with icon number 131...if i pressed it i would like to switch to 146 icon... And if button is set to icon 146 if i pressed it i would like to switch to 131 icon... How i can do it? I've read help file but i don't find nothing =P Hi and thanks for your help Share this post Link to post Share on other sites
smartee 14 Posted January 17, 2011 look what this does If _GUICtrlToolbar_IsButtonPressed($hToolbar, $id1) Then _GUICtrlToolbar_SetButtonInfo($hToolbar, $id1, 1) EndIf Share this post Link to post Share on other sites
StungStang 1 Posted January 17, 2011 It works ...but now i've another problem i have to know what icon are displaying the button...How i can know that? For example i've to do that : If button have icon 131 then Function 1 elseid button have icon 146 then Function 2 endif There is a soluction for that? Hi and thanks for help Share this post Link to post Share on other sites
smartee 14 Posted January 17, 2011 It works ...but now i've another problem i have to know what icon are displaying the button...How i can know that? For example i've to do that : If button have icon 131 then Function 1 elseid button have icon 146 then Function 2 endif There is a soluction for that? Hi and thanks for help one approach is to set some variable when you change the icon like If _GUICtrlToolbar_IsButtonPressed($hToolbar, $id1) Then _GUICtrlToolbar_SetButtonInfo($hToolbar, $id1, 1) $currentIcon = 146 EndIf Share this post Link to post Share on other sites
Varian 8 Posted January 17, 2011 (edited) Your While loopWhile 1 $nMsg = GUIGetMWhile 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If _GUICtrlToolbar_IsButtonPressed($hToolbar, $id1) Then $Array = _GUICtrlToolbar_GetButtonInfo($hToolbar, $id1) Sleep(100) ;needed a sleep to ensure change time Switch $Array[0] Case 0 _GUICtrlToolbar_SetButtonInfo($hToolbar, $id1, 1) Sleep(50) ;needed a sleep to ensure change time Case 1 _GUICtrlToolbar_SetButtonInfo($hToolbar, $id1, 0) Sleep(50) ;needed a sleep to ensure change time EndSwitch EndIf WEnd Edited January 17, 2011 by Varian Share this post Link to post Share on other sites
StungStang 1 Posted January 17, 2011 Your While loopWhile 1 $nMsg = GUIGetMWhile 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If _GUICtrlToolbar_IsButtonPressed($hToolbar, $id1) Then $Array = _GUICtrlToolbar_GetButtonInfo($hToolbar, $id1) Sleep(100) ;needed a sleep to ensure change time Switch $Array[0] Case 0 _GUICtrlToolbar_SetButtonInfo($hToolbar, $id1, 1) Sleep(50) ;needed a sleep to ensure change time Case 1 _GUICtrlToolbar_SetButtonInfo($hToolbar, $id1, 0) Sleep(50) ;needed a sleep to ensure change time EndSwitch EndIf WEnd This work great Share this post Link to post Share on other sites