Jump to content
Sign in to follow this  
gcue

multiple dropdowns in toolbar

Recommended Posts

gcue

*oops posted in wrong forum topic.. my apologies..*

hello. i am trying to use rover's toolbar example but am trying to add additional dropdown menus.

thanks in advacne

#include <GuiToolbar.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiMenu.au3>
#include <GuiRebar.au3>
#include <GuiImageList.au3>

Opt('MustDeclareVars', 1)

$Debug_TB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hGUI, $hToolbar, $Tbar, $TbarMenu, $iMemo, $msg, $aSize
Global $iItem ; Command identifier of the button associated with the notification.
Global Enum $idRemoteScreenShot = 1000, $idPushKillNotes, $idWhoseLoggedOn, $idMustHave, $idGetIP, $idSysInfo, $idLocalMaps, $idWhosAdmin, $idUserHistory ;Common
Global Enum $idLookupLocation = 1100, $idDefaultPrinter, $idNonIPrint, $idEncryptionStatus, $idMACnHD, $idDPIsetting, $idUptime ;Hardware
Global Enum $idActiveProcesses = 1200, $idKillProcess, $idInstalledPrograms, $idNotesDataDir, $idImageBuild, $idRecoverySol ;Software
Global $netsupport_button_txt, $manage_button_txt, $common_button_txt, $hardware_button_txt, $software_button_txt
Global Enum $idNetSupport = 2000, $idManage, $idCommon, $idHardware, $idSoftware


; Create GUI
$hGUI = GUICreate("Toolbar", 500, 300)
$hToolbar = _GUICtrlToolbar_Create($hGUI)
$aSize = _GUICtrlToolbar_GetMaxSize($hToolbar)

;~  _GUICtrlToolbar_SetExtendedStyle($hToolbar, $TBSTYLE_EX_DRAWDDARROWS)
;~ _GUICtrlToolbar_SetColorScheme($hToolbar, 16774367, 16774367)

$iMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 20, 596, 396 - ($aSize[1] + 20), $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")

$Tbar = GUICtrlCreateDummy() ; dummy control to receive toolbar events
$TbarMenu = GUICtrlCreateDummy() ; dummy control to receive toolbar button dropdown menu events

GUISetState()

toolbar()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
                        Case $Tbar       ; toolbar buttons
                _ToolBar_Click(GUICtrlRead($Tbar))
        Case $TbarMenu ; toolbar button dropdown menu
            _ToolBarMenu(GUICtrlRead($TbarMenu))
    EndSwitch
WEnd

Func Toolbar()

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    Global $hImage = _GUIImageList_Create(16, 16, 5, 3, 3)
    _GUIImageList_AddIcon($hImage, "C:\program Files\NetSupport Manager\PCIAX.DLL", 0) ;netsupport    0
    _GUIImageList_AddIcon($hImage, "tapisnap.dll", 3);-7) ;manage    1
    _GUIImageList_AddIcon($hImage, "cdfview.dll", 2) ;common    2
    _GUIImageList_AddIcon($hImage, "azroleui.dll", 7) ;hardware    3
    _GUIImageList_AddIcon($hImage, "Shell32.dll", 19) ;software    4
    _GUICtrlToolbar_SetImageList($hToolbar, $hImage)

    _GUICtrlToolbar_SetImageList($hToolbar, $hImage)

    $netsupport_button_txt = _GUICtrlToolbar_AddString($hToolbar, "NetSupport")
    $manage_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Manage")
    $common_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Common")
    $hardware_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Hardware")
    $software_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Software")

    _GUICtrlToolbar_AddButton($hToolbar, $idNetSupport, 0, $netsupport_button_txt)
    _GUICtrlToolbar_AddButton($hToolbar, $idManage, 1, $manage_button_txt)
    _GUICtrlToolbar_AddButton($hToolbar, $idCommon, 2, $common_button_txt, BitOR($BTNS_DROPDOWN, $BTNS_WHOLEDROPDOWN))
    _GUICtrlToolbar_AddButton($hToolbar, $idHardware, 3, $hardware_button_txt, BitOR($BTNS_DROPDOWN, $BTNS_WHOLEDROPDOWN))
    _GUICtrlToolbar_AddButton($hToolbar, $idSoftware, 4, $software_button_txt, BitOR($BTNS_DROPDOWN, $BTNS_WHOLEDROPDOWN))

    ;_GUICtrlToolbar_SetButtonStyle($hToolbar, $idPower, $BTNS_CHECK)
    _GUICtrlToolbar_SetButtonWidth($hToolbar, 100, 37)

EndFunc   ;==>Toolbar

; Toolbar: call functions for toolbar button dropdown menu
Func _ToolBarMenu($TbarMenuCmdID)
    Switch $TbarMenuCmdID
        Case $idRemoteScreenShot
            MsgBox(4096, "Pop-Up Menu", "Remote ScreenShot")
        Case $idPushKillNotes
            MsgBox(4096, "Pop-Up Menu", "Push KillNotes")
        Case $idWhoseLoggedOn
            MsgBox(4096, "Pop-Up Menu", "Whose Logged On")
        Case $idMustHave
            MsgBox(4096, "Pop-Up Menu", "MustHave")
        Case $idGetIP
            MsgBox(4096, "Pop-Up Menu", "GetIP")
        Case $idSysInfo
            MsgBox(4096, "Pop-Up Menu", "SysInfo")
        Case $idLocalMaps
            MsgBox(4096, "Pop-Up Menu", "Local Maps")
        Case $idWhosAdmin
            MsgBox(4096, "Pop-Up Menu", "Whos Admin")
        Case $idUserHistory
            MsgBox(4096, "Pop-Up Menu", "User History")
    EndSwitch
EndFunc   ;==>_ToolBarMenu

Func _ToolBar_Click($TbarCmdID)
    Switch $TbarCmdID
        Case $idNetSupport    ; FileOpen
            MsgBox(4096, "Pop-Up Menu", "Netsupport")
        Case $idManage    ; FileSave
            MsgBox(4096, "Pop-Up Menu", "Manage")
    EndSwitch
    Return
EndFunc   ;==>_ToolBar_Click

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

; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $event, $hwndFrom, $code, $i_idNew, $dwFlags, $lResult, $idFrom, $i_idOld
    Local $tNMTOOLBAR, $tNMTBHOTITEM, $hMenu, $hSubmenu, $aRet, $iMenuID
    Local Const $TBDDRET_TREATPRESSED = 2

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $idFrom = DllStructGetData($tNMHDR, "IDFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Switch $hwndFrom
        Case $hToolbar
            Switch $code
                Case $TBN_DROPDOWN
                    $hMenu = _GUICtrlMenu_CreatePopup()
                    _GUICtrlMenu_AddMenuItem($hMenu, "Remote ScreenShot", $idRemoteScreenShot)
                    _GUICtrlMenu_AddMenuItem($hMenu, "Push KillNotes", $idPushKillNotes)
                    _GUICtrlMenu_AddMenuItem($hMenu, "Whose Logged On?", $idWhoseLoggedOn)
                    _GUICtrlMenu_AddMenuItem($hMenu, "MustHave", $idMustHave)
                    _GUICtrlMenu_AddMenuItem($hMenu, "Get IP", $idGetIP)
                    _GUICtrlMenu_AddMenuItem($hMenu, "System Information", $idSysInfo)
                    _GUICtrlMenu_AddMenuItem($hMenu, "Local Mappings", $idLocalMaps)
                    _GUICtrlMenu_AddMenuItem($hMenu, "Who's An Admin", $idWhosAdmin)
                    _GUICtrlMenu_AddMenuItem($hMenu, "User History", $idUserHistory)

                    $aRet = _GetToolbarButtonScreenPos($hGUI, $hToolbar, $idCommon)
                    If Not IsArray($aRet) Then
                        Dim $aRet[2] = [-1, -1]
                    EndIf


                    ; send button dropdown menu item commandID to dummy control for use in GuiGetMsg() or GUICtrlSetOnEvent()
                    ; allows quick return from message handler : See warning for GUIRegisterMsg() in helpfile
                    $iMenuID = _GUICtrlMenu_TrackPopupMenu($hMenu, $hToolbar, $aRet[0], $aRet[1], 1, 1, 2)
                    GUICtrlSendToDummy($TbarMenu, $iMenuID)
                    _GUICtrlMenu_DestroyMenu($hMenu)
                    If $iMenuID Then Return $TBDDRET_TREATPRESSED
                Case $NM_LDOWN
                    Switch _GUICtrlToolbar_IsButtonEnabled($hToolbar, $iItem) ; add check for button state if disabled
                        Case True
                            ; send toolbar commandID to dummy control for use in GuiGetMsg() or GUICtrlSetOnEvent()
                            ; allows quick return from message handler : See warning for GUIRegisterMsg() in helpfile
                            GUICtrlSendToDummy($Tbar, $iItem)
                    EndSwitch
                    ;----------------------------------------------------------------------------------------------
                    MemoWrite("$NM_LDOWN: Clicked Item: " & $iItem & " at index: " & _GUICtrlToolbar_CommandToIndex($hToolbar, $iItem))
                    ;----------------------------------------------------------------------------------------------
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    $iItem = $i_idNew
                    $dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY


Func _GetToolbarButtonScreenPos($hwnd, $hTbar, $iCmdID, $iIndex = 0, $hRbar = -1) ; $hRbar and $iIndex is for optional Rebar hwnd and band index
    ; Author: rover 04/08/2008
    ; this UDF integrates _WinAPI_ClientToScreen() from WinAPI.au3 include
    ; _GUICtrlMenu_TrackPopupMenu() uses screen coordinates to place dropdown menu
    ; need to convert button client coordinates to screen coordinates
    Local $aBorders, $aBandRect, $aRect, $tpoint, $pPoint, $aRet[2]
    Local $aRect = _GUICtrlToolbar_GetButtonRect($hTbar, $iCmdID) ; 'Options' button with dropdown menu
    If Not IsArray($aRect) Then Return SetError(@error, 0, "")
    $tpoint = DllStructCreate("int X;int Y")
    DllStructSetData($tpoint, "X", $aRect[0])
    DllStructSetData($tpoint, "Y", $aRect[3])
    $pPoint = DllStructGetPtr($tpoint)
    DllCall("User32.dll", "int", "ClientToScreen", "hwnd", $hwnd, "ptr", $pPoint)
    If @error Then Return SetError(@error, 0, "")
    If $hRbar <> -1 And IsHWnd($hRbar) And IsNumber($iIndex) Then
        $aBorders = _GUICtrlRebar_GetBandBorders($hRbar, $iIndex)
        If Not IsArray($aBorders) Then Return SetError(@error, 0, "")
        $aBandRect = _GUICtrlRebar_GetBandRect($hRbar, $iIndex)
        If Not IsArray($aBandRect) Then Return SetError(@error, 0, "")
        ; X screen coordinate of dropdown button left corner
        ; subtract 2 pixel border of bounding rectangle for band in rebar control
        $aRet[0] = (DllStructGetData($tpoint, "X") + $aBorders[0]) - $aBandRect[0]
    Else
        ; X screen coordinate of dropdown button left corner
        $aRet[0] = DllStructGetData($tpoint, "X")
    EndIf
    ; Y screen coordinate of dropdown button left corner
    $aRet[1] = DllStructGetData($tpoint, "Y")
    Return $aRet ; return X,Y screen coordinates of toolbar dropdown button lower left corner
EndFunc   ;==>_GetToolbarButtonScreenPos
Edited by gcue

Share this post


Link to post
Share on other sites
gcue

yep sorry. accidentally posted in wrong topic..

thanks again for your help!!!!!!!!!!!!!!!!!!!

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  

×