Jump to content

Gui Toolbar


Recommended Posts

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

Link to comment
Share on other sites

It works :x...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 :P

Link to comment
Share on other sites

It works :x...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 :P

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
Link to comment
Share on other sites

Your While loop

While 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 by Varian
Link to comment
Share on other sites

Your While loop

While 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 :x
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...