Jump to content

Recommended Posts

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
  • Moderators
Posted

@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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

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

 

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
Posted

@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

Posted

@nacerbaaziz

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

Posted

@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

 

Posted

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?

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
×
×
  • Create New...