Jump to content
Sign in to follow this  
nacerbaaziz

create a tool bar with buttons

Recommended Posts

nacerbaaziz
Posted (edited)

Hi dear
I have a request
I want a simplified example of how to create the toolbar
With an example of pressing the buttons inside this bar
for example
Toolbar contains Three buttons
open, save, And delete
and i want  If i press a button from among these buttons a MSGBox appears
I know this is easy
But I did not know how to do it
I hope you help me
I apologize for the inconvenience
Thank you in advance

Edited by nacerbaaziz

Share this post


Link to post
Share on other sites
JLogan3o13

@nacerbaaziz you have been around long enough (and we have had this conversation with you often enough) to know that we are not going to spoon-feed code to you. What have you tried, and what isn't working?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
nacerbaaziz

I did this
But I want to apply the command when I click the item and not when it is selected
So it's for compatibility with screen readers

#include <GUIConstantsEx.au3>
#include <GuiToolbar.au3>
#include <WinAPIConstants.au3>
#include <WindowsConstants.au3>

Global $g_hToolbar, $g_idMemo
Global $g_iItem ; Command identifier of the button associated with the notification.
Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp

Example()

Func Example()
    Local $hGUI, $aSize, $aStrings[4]

    ; Create GUI
    $hGUI = GUICreate("Toolbar", 600, 400)
    $g_hToolbar = _GUICtrlToolbar_Create($hGUI)
    $aSize = _GUICtrlToolbar_GetMaxSize($g_hToolbar)

    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    ; Add standard system bitmaps
    _GUICtrlToolbar_AddBitmap($g_hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

    ; Add strings
    $aStrings[0] = _GUICtrlToolbar_AddString($g_hToolbar, "&New")
    $aStrings[1] = _GUICtrlToolbar_AddString($g_hToolbar, "&Open")
    $aStrings[2] = _GUICtrlToolbar_AddString($g_hToolbar, "&Save")
    $aStrings[3] = _GUICtrlToolbar_AddString($g_hToolbar, "&Help")

    ; Add buttons
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idNew, $STD_FILENEW, $aStrings[0])
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idOpen, $STD_FILEOPEN, $aStrings[1])
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idSave, $STD_FILESAVE, $aStrings[2])
    _GUICtrlToolbar_AddButtonSep($g_hToolbar)
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idHelp, $STD_HELP, $aStrings[3])


    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example


; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $iMsgID, $wParam, $lParam)
    #forceref $hWndGUI, $iMsgID, $wParam
    Local $tNMHDR, $hWndFrom, $iCode, $iNew, $iFlags, $iOld
    Local $tNMTBHOTITEM
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $g_hToolbar
            Switch $iCode
                Case $NM_LDOWN
                    ;----------------------------------------------------------------------------------------------
                    MemoWrite("$NM_LDOWN: Clicked Item: " & $g_iItem & " at index: " & _GUICtrlToolbar_CommandToIndex($g_hToolbar, $g_iItem))
                    ;----------------------------------------------------------------------------------------------
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $iOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $iNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    $g_iItem = $iNew
                    $iFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
                    If BitAND($iFlags, $HICF_LEAVING) = $HICF_LEAVING Then
                        MemoWrite("$HICF_LEAVING: " & $iOld)
                    Else
                        Switch $iNew
                            Case $e_idNew
                                ;----------------------------------------------------------------------------------------------
msgBox(0, "", "new")
                                ;----------------------------------------------------------------------------------------------
                            Case $e_idOpen
                            ;----------------------------------------------------------------------------------------------
msgBox(0, "", "open")
                                ;----------------------------------------------------------------------------------------------
                            Case $e_idSave
                                ;----------------------------------------------------------------------------------------------
msgBox(0, "", "save")
                                ;----------------------------------------------------------------------------------------------
                            Case $e_idHelp
                                ;----------------------------------------------------------------------------------------------
msgBox(0, "", "help")
                                ;----------------------------------------------------------------------------------------------
                        EndSwitch
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)
38 minutes ago, nacerbaaziz said:

I did this

@nacerbaaziz

All you did was copy and paste the example from the help file for the _GUICtrlToolbar_Create() function.  So actually, you haven't done anything.

Edited by TheXman

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
nacerbaaziz

@TheXman

I know that, thanks
But I did not find what I wanted

I put this code here to explain the difficulty face me to you
and to  ask you if there is a solution
Thanks in advance

Share this post


Link to post
Share on other sites
TheXman

@nacerbaaziz

Everything you need to fulfill your original request, except the MsgBox, is in that example from the help file you posted.


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
TheXman

@nacerbaaziz

The more of your own effort that you show, the more others will be willing to help you.  Not too many people are willing to help those who just want everything given to them.

The code below is just slightly modified from the help file example.  I just removed unnecessary code and added the MsgBoxes that you requested.

 

#include <GUIConstantsEx.au3>
#include <GuiToolbar.au3>
#include <WinAPIConstants.au3>
#include <WindowsConstants.au3>

Global $g_hToolbar, $g_idMemo
Global $g_iItem ; Command identifier of the button associated with the notification.
Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp

Example()

Func Example()
    Local $hGUI, $aSize

    ; Create GUI
    $hGUI = GUICreate("Toolbar", 600, 400)
    $g_hToolbar = _GUICtrlToolbar_Create($hGUI)
    $aSize = _GUICtrlToolbar_GetMaxSize($g_hToolbar)

    $g_idMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 20, 596, 396 - ($aSize[1] + 20), $WS_VSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    ; Add standard system bitmaps
    _GUICtrlToolbar_AddBitmap($g_hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

    ; Add buttons
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idNew, $STD_FILENEW)
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idOpen, $STD_FILEOPEN)
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idSave, $STD_FILESAVE)
    _GUICtrlToolbar_AddButtonSep($g_hToolbar)
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idHelp, $STD_HELP)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $iMsgID, $wParam, $lParam)
    #forceref $hWndGUI, $iMsgID, $wParam
    Local $tNMHDR, $hWndFrom, $iCode, $iNew, $iFlags, $iOld
    Local $tNMTBHOTITEM
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $g_hToolbar
            Switch $iCode
                Case $NM_LDOWN
                    Switch $g_iItem
                        Case 1000
                            MsgBox(0, "", "You clicked NEW")
                        Case 1001
                            MsgBox(0, "", "You clicked OPEN")
                        Case 1002
                            MsgBox(0, "", "You clicked SAVE")
                        Case 1003
                            MsgBox(0, "", "You clicked HELP")
                        Case Else
                            MsgBox(0, "", "You clicked an unrecognized button")
                    EndSwitch
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $iNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    $g_iItem = $iNew
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
nacerbaaziz

It works dear. Thank you

i have only a simple question
it does not recognize the keyboard
Eg with screen readers
The buttons clicked wen we press the spacebar or the enter key
But here it do not recognize it
Is there a solution for that?

Share this post


Link to post
Share on other sites
AutoBert

Have a look in helpfile, the example for the func _GUICtrlToolbar_Create works and shows what you want.

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • okolaris
      By okolaris
      Hey everyone,
      I thought I might share my little Language UDF plus the more powerful SciTE Tool to ship Strings from SciTE into the xml file. While I haven't had the time to fully adapt the small UDF to one of the big XML-UDFs the so called "Language Transmitter" that basically writes the XML file for you runs mostly on "XML DOM wrapper (COM)" by eltorro. The Transmitter should work with other XML-Language-UDFs depending on their encoding.
       
      First let's start with the UDF, there are two functions of interest: _LangInit($sFilePath) and s($sString) As you will have guessed, _LangInit($sFilePath) is called once to initialize the UDF and s($sString) is used to receive the string to your key. Plain and simple.
      Now to the actual "new" part, the Language Transmitter. It basically allows you to transfer a selected String from SciTE into a xml file. While doing so it will scan for AutoIt variables, macros etc. and parse the string to fit StringFormat(). It then saves the formatted string in the xml file and returns the formatted call into SciTE. If the selected string is already defined it will directly parse the key into SciTE. To change the default output file, you can either edit the ini-file in the @ScriptDir of the LanguageTransmitter.exe or press Alt+A on empty space again and keep clicking cancel/no until the Transmitter let's you select the current output file. Standard output is strings.xml in the current opened AutoIt Script.
      Example:
      ; given the line: MsgBox(16, 'Error', 'Error message') ; select 'Error' run the Transmitter follow the instructions, repeat with 'Error message'. Outcome (e.g.): MsgBox(16, s('Error'), s('Error_msg')) ; Variables and Macro example: $sString = "Value: " & $iValue & @CRLF & 'Another value: '& $iValue2 ; Select the full string including all AutoIt variables and macros etc. in SciTE and press Alt+A (default) to run the LanguageTransmitter ; follow the instructions and it will then paste a formatted string like that into SciTE: $sVar = StringFormat(s('Key'), $iValue, $iValue2) ; the correlating xml entry should look like that: ; <string name="Key">Value: %s\r\nAnother value: %s</string> ; as you can see @CRLF has been replaced with \r\n as well. If you are working on a project and want to directly add a string to the xml file just start the Language Transmitter without selecting any text, enter your string and a key.
      SetUp/Installation
      Examples
      Since xml files are required all examples can be found in the zip file. There are two examples, one includes a language selection interface.
      Language File Checker
      I added a script to check whether the xml file contains all required strings or even unnecessary strings.
       
      Hope you like my little helper!
       
      UDF - LanguageSupport.zip
    • t0nZ
      By t0nZ
      Hello to all, my problem is to have in the same gui buttons (static and dinamically generated ones) and an edit control.
      The gui also adjust its height in function of button number.
      Below you see an ugly interface and the long buttons at the bottom are dinamically generated reading from a txt file.

      Because I have "static" buttons and dynamically generated ones it's not workin' well your method, also the EDIT area is updated (is a live log) and this is detected as GUI events, and this makes the guigetmsg() "dirty".
      Have you any ideas to make it work in better way ?  I only think about creating two different GUIs to not interfere one with the other one.
      My code is this
      While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GOLLOG("<<<< STOP <<<<") Exit #cs ; test 1 Case $iStart To $iEnd ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< gollog(GUICtrlRead($nMsg) & ' ' & 'was pressed' & @CRLF) $iValueToWorkWith = $nMsg - $iStart ; Adjust as required gollog($iValueToWorkWith) ;ExitLoop #ce Case $buttonarray[1] To $buttonarray[UBound($buttonarray) - 1] $UMDguimsg = GUICtrlRead($nMsg) If $UMDguimsg <> 0 Then GOLLOG("ButtonText=[" & $UMDguimsg & "] was clicked") EndIf Case $Bcerca If BitAND(GUICtrlRead($idradio1), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("username-machinedescription") If BitAND(GUICtrlRead($idradio2), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("machinename-username") ;Multisearch("username-machinedescription") Case $Block lock() Case $Busergroups usergroups() Case $Bvnc VNC() Case $Icercato If BitAND(GUICtrlRead($idradio1), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("username-machinedescription") If BitAND(GUICtrlRead($idradio2), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("machinename-username") #CS Multisearch("username-machinedescription") Case Else msgbox(64,"test",GUIGetMsg()) $UMDguimsg = GUICtrlRead(GUIGetMsg()) If $UMDguimsg <> $salvaUMDguimsg Then MsgBox(64, "test2", $UMDguimsg) $salvaUMDguimsg = $UMDguimsg #CE EndIf EndSwitch WEnd Thank you , cheers,
    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • UEZ
      By UEZ
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
       
       
        
       
       
      Some files from cannot be downloaded although they are visible on the web site!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.1 build 2017-10-23 beta.7z  (1353 downloads previously)
      -=> Requires AutoIt version 3.3.13.20 or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
       
      Compiled exe only: @MediaFire
       
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
       
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
       
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
       
      Please report any bug or if you have any suggestions.
       
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
       
      Br,
      UEZ
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I want create retractable bar using autoit
      I tried creating slider, but there's a problem with screen reader for the blind, so is there another retractable tape?
      It is advisable to not accept dragging with the keybord only with  mouse
      note:
      This bar is needed in the process of raising and lowering the volume
      I hope that there is a solution to do that
      i waiting your responses.
      Thanks in advance to all members and administrators
×