Jump to content

multiple dropdowns in toolbar


Recommended Posts

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

Opt('MustDeclareVars', 0)
instead of
Opt('MustDeclareVars', 1)

; Create GUI
$hGUI = GUICreate("Toolbar", 500, 300)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("About")
$hToolbar = _GUICtrlToolbar_Create($hGUI)
$aSize = _GUICtrlToolbar_GetMaxSize($hToolbar)

....

It works.

_____________________________________________________________________________

Link to comment
Share on other sites

ya i already have a menu created.. i wanted to do a toolbar under it =) where a few of the buttons have submenus

how can i go about doign that?

Edited by gcue
Link to comment
Share on other sites

@Vitas

the OnHover UDF would be great for a custom toolbar menu.

@gcue

just use the global var $iItem from tagNMTBHOTITEM to select multiple drop down buttons.

iItem Command identifier is also in tagNMTOOLBAR struct (if you need parameters other than the three in tagNMHDR, replace it with tagNMTOOLBAR)

you might want to use an array and a For/Next loop to create the menu items.

also, tweak the Y screen coordinate of dropdown button left corner in _GetToolbarButtonScreenPos

depending on visual style, it looks better with a bit of a gap between the button and menu.

in the posted script I've added 2 pixels to the Y coordinate.

added an update to _GetToolbarButtonScreenPos() to correct for negative off-screen X coordinate

if not using a rebar, remove the rebar include and rebar section in _GetToolbarButtonScreenPos()

as you are using the BTNS_WHOLEDROPDOWN style, you don't want to return TBDDRET_TREATPRESSED.

I used that in that old toolbar example because there was a drop down button without the BTNS_WHOLEDROPDOWN style.

the button returns either a normal button pressed event or a dropdown menu event.

if used in your script, then the message handler is captured and won't release until another button is clicked.

(comment out the MsgBox() lines in _ToolBarMenu to see).

I think I dropped using that in an example I worked out for that button type.

TBSTYLE_EX_DRAWDDARROWS is required as toolbar extended style for dropdown buttons, but it works without it?

It's usually good practice to send to a dummy control and return quickly from a message handler (no blocking functions),

but this is not the case with a drop down menu button.

If a drop down menu function is called by a dummy control and the default message is returned in the handler,

then you lose the pressed state of the button. (explorer Views button being a good example of this button type)

Edit: fixed code tags

#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

Global Const $TBDDRET_DEFAULT = 0
Global Const $TBDDRET_NODEFAULT = 1
Global Const $TBDDRET_TREATPRESSED = 2

; 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, "Shell32.dll", 0);netsupport 0
    _GUIImageList_AddIcon($hImage, "Shell32.dll", 3);-7);manage 1
    _GUIImageList_AddIcon($hImage, "Shell32.dll", 2);common 2
    _GUIImageList_AddIcon($hImage, "Shell32.dll", 7);hardware 3
    _GUIImageList_AddIcon($hImage, "Shell32.dll", 19);software 4

;~ _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)

    $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")
        Case $idLookupLocation
        Case $idDefaultPrinter
        Case $idNonIPrint
        Case $idEncryptionStatus
        Case $idMACnHD
        Case $idDPIsetting
        Case $idUptime
    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

    $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()
                    Switch $iItem
                        Case $idCommon
                            _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)
                        Case $idHardware
                            _GUICtrlMenu_AddMenuItem($hMenu, "Lookup Location", $idLookupLocation)
                            _GUICtrlMenu_AddMenuItem($hMenu, "Default Printer", $idDefaultPrinter)
                            _GUICtrlMenu_AddMenuItem($hMenu, "No nIPrint", $idNonIPrint)
                            _GUICtrlMenu_AddMenuItem($hMenu, "Encryption Status", $idEncryptionStatus)
                            _GUICtrlMenu_AddMenuItem($hMenu, "MAC nHD", $idMACnHD)
                            _GUICtrlMenu_AddMenuItem($hMenu, "DPI setting", $idDPIsetting)
                            _GUICtrlMenu_AddMenuItem($hMenu, "Uptime", $idUptime)
                        Case $idSoftware
                    EndSwitch

                    $aRet = _GetToolbarButtonScreenPos($hGUI, $hToolbar, $iItem, 2)
                    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
                    Return $TBDDRET_DEFAULT
                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, $iOffset = 0, $iIndex = 0, $hRbar = -1)
; 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
; $hRbar and $iIndex is for optional Rebar hwnd and band index
; $iOffset sets menu Y position below button
; Update: 06/27/2009 added offset for menu position below button, corrected left off-screen menu positioning.
    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, "")

; X screen coordinate of dropdown button left corner
    $aRet[0] = DllStructGetData($tpoint, "X")
; limit X coordinate to 0 if button partially off-screen
    If $aRet[0] < 0 Then $aRet[0] = 0
; Y screen coordinate of dropdown button left corner
    $aRet[1] = DllStructGetData($tpoint, "Y") + Number($iOffset)

    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
        If $aRet[0] <> 0 Then $aRet[0] += ($aBorders[0] - $aBandRect[0])
    EndIf

    Return $aRet; return X,Y screen coordinates of toolbar dropdown button lower left corner
EndFunc ;==>_GetToolbarButtonScreenPos
Edited by rover

I see fascists...

Link to comment
Share on other sites

  • 3 years later...

not sure if anyone else has used this.. or rover if you're still around - i am trying to get it working in windows 7 - a 64 bit version... anyone get it working in win7 64-bit?

Link to comment
Share on other sites

The issue comes from the dropdown menu. The $TBN_HOTITEMCHANGE/$NM_LDOWN messages are fired after that menu so the item index is not updated and the click is on the dropdown menu item.

I suggest you to merge the $TBN_DROPDOWN and the $NM_LDOWN messages into the $NM_LDOWN one.

Br, FireFox.

Link to comment
Share on other sites

i combined them but it did not work for me.. did it work for you?

i tried in and out of the switch case

 

#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

Global Const $TBDDRET_DEFAULT = 0
Global Const $TBDDRET_NODEFAULT = 1
Global Const $TBDDRET_TREATPRESSED = 2

; 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, "Shell32.dll", 0);netsupport 0
_GUIImageList_AddIcon($hImage, "Shell32.dll", 3);-7);manage 1
_GUIImageList_AddIcon($hImage, "Shell32.dll", 2);common 2
_GUIImageList_AddIcon($hImage, "Shell32.dll", 7);hardware 3
_GUIImageList_AddIcon($hImage, "Shell32.dll", 19);software 4

;~ _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)

$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")
Case $idLookupLocation
Case $idDefaultPrinter
Case $idNonIPrint
Case $idEncryptionStatus
Case $idMACnHD
Case $idDPIsetting
Case $idUptime
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

$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()
Switch $iItem
Case $idCommon
_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)
Case $idHardware
_GUICtrlMenu_AddMenuItem($hMenu, "Lookup Location", $idLookupLocation)
_GUICtrlMenu_AddMenuItem($hMenu, "Default Printer", $idDefaultPrinter)
_GUICtrlMenu_AddMenuItem($hMenu, "No nIPrint", $idNonIPrint)
_GUICtrlMenu_AddMenuItem($hMenu, "Encryption Status", $idEncryptionStatus)
_GUICtrlMenu_AddMenuItem($hMenu, "MAC nHD", $idMACnHD)
_GUICtrlMenu_AddMenuItem($hMenu, "DPI setting", $idDPIsetting)
_GUICtrlMenu_AddMenuItem($hMenu, "Uptime", $idUptime)
Case $idSoftware
EndSwitch

$aRet = _GetToolbarButtonScreenPos($hGUI, $hToolbar, $iItem, 2)
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
Return $TBDDRET_DEFAULT
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)

$tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
$i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
$i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
$iItem = $i_idNew
$dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
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, $iOffset = 0, $iIndex = 0, $hRbar = -1)
; 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
; $hRbar and $iIndex is for optional Rebar hwnd and band index
; $iOffset sets menu Y position below button
; Update: 06/27/2009 added offset for menu position below button, corrected left off-screen menu positioning.
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, "")

; X screen coordinate of dropdown button left corner
$aRet[0] = DllStructGetData($tpoint, "X")
; limit X coordinate to 0 if button partially off-screen
If $aRet[0] < 0 Then $aRet[0] = 0
; Y screen coordinate of dropdown button left corner
$aRet[1] = DllStructGetData($tpoint, "Y") + Number($iOffset)

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
If $aRet[0] <> 0 Then $aRet[0] += ($aBorders[0] - $aBandRect[0])
EndIf

Return $aRet; return X,Y screen coordinates of toolbar dropdown button lower left corner
EndFunc ;==>_GetToolbarButtonScreenPos
Edited by gcue
Link to comment
Share on other sites

hmm that still didnt work

I changed line 187 to what you suggested

Case $NM_CLICK;$NM_LDOWN

#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

Global Const $TBDDRET_DEFAULT = 0
Global Const $TBDDRET_NODEFAULT = 1
Global Const $TBDDRET_TREATPRESSED = 2

; 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, "Shell32.dll", 0);netsupport 0
_GUIImageList_AddIcon($hImage, "Shell32.dll", 3);-7);manage 1
_GUIImageList_AddIcon($hImage, "Shell32.dll", 2);common 2
_GUIImageList_AddIcon($hImage, "Shell32.dll", 7);hardware 3
_GUIImageList_AddIcon($hImage, "Shell32.dll", 19);software 4

;~ _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)

$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")
Case $idLookupLocation
Case $idDefaultPrinter
Case $idNonIPrint
Case $idEncryptionStatus
Case $idMACnHD
Case $idDPIsetting
Case $idUptime
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

$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()
Switch $iItem
Case $idCommon
_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)
Case $idHardware
_GUICtrlMenu_AddMenuItem($hMenu, "Lookup Location", $idLookupLocation)
_GUICtrlMenu_AddMenuItem($hMenu, "Default Printer", $idDefaultPrinter)
_GUICtrlMenu_AddMenuItem($hMenu, "No nIPrint", $idNonIPrint)
_GUICtrlMenu_AddMenuItem($hMenu, "Encryption Status", $idEncryptionStatus)
_GUICtrlMenu_AddMenuItem($hMenu, "MAC nHD", $idMACnHD)
_GUICtrlMenu_AddMenuItem($hMenu, "DPI setting", $idDPIsetting)
_GUICtrlMenu_AddMenuItem($hMenu, "Uptime", $idUptime)
Case $idSoftware
EndSwitch

$aRet = _GetToolbarButtonScreenPos($hGUI, $hToolbar, $iItem, 2)
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
Return $TBDDRET_DEFAULT
Case $NM_CLICK;$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, $iOffset = 0, $iIndex = 0, $hRbar = -1)
; 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
; $hRbar and $iIndex is for optional Rebar hwnd and band index
; $iOffset sets menu Y position below button
; Update: 06/27/2009 added offset for menu position below button, corrected left off-screen menu positioning.
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, "")

; X screen coordinate of dropdown button left corner
$aRet[0] = DllStructGetData($tpoint, "X")
; limit X coordinate to 0 if button partially off-screen
If $aRet[0] < 0 Then $aRet[0] = 0
; Y screen coordinate of dropdown button left corner
$aRet[1] = DllStructGetData($tpoint, "Y") + Number($iOffset)

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
If $aRet[0] <> 0 Then $aRet[0] += ($aBorders[0] - $aBandRect[0])
EndIf

Return $aRet; return X,Y screen coordinates of toolbar dropdown button lower left corner
EndFunc ;==>_GetToolbarButtonScreenPos
Link to comment
Share on other sites

dropdowns intermittently work.

also theres a message box that comes up when clicking netsupport or manage - msgbox comes on only the first time and its usually the wrong box

Link to comment
Share on other sites

dropdowns intermittently work.

Do you mean that you have to click two times on another dropdown when you are focused on a dropdown?

also theres a message box that comes up when clicking netsupport or manage

Yes and?

msgbox comes on only the first time and its usually the wrong box

Not for me. Don't try to click on the toolbar when a msgbox is active, otherwise you will have to add a fix if you want to handle this behaviour.

Br, FireFox.

Link to comment
Share on other sites

dropdowns

right from the start - if i click a dropdown it doesnt work i have to click it several times for it to work..

netsupport/manage

if i click either from the beginning they dont work at all not matter how many times i click either. after eventaully getting a dropdown from one of the dropdowns then the msgbox will come up on one of them but not if i close the box and click again on the same option...

Link to comment
Share on other sites

Weird...

Comment the HOTITEMCHANGE case and try this :

...
Case $TBN_DROPDOWN
$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
$iItem = DllStructGetData($tNMTOOLBAR, "iItem")
...
Case $NM_CLICK
$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
$iItem = DllStructGetData($tNMTOOLBAR, "iItem")
...
Br, FireFox.
Link to comment
Share on other sites

no action

#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

Global Const $TBDDRET_DEFAULT = 0
Global Const $TBDDRET_NODEFAULT = 1
Global Const $TBDDRET_TREATPRESSED = 2

; 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, "Shell32.dll", 0);netsupport 0
_GUIImageList_AddIcon($hImage, "Shell32.dll", 3);-7);manage 1
_GUIImageList_AddIcon($hImage, "Shell32.dll", 2);common 2
_GUIImageList_AddIcon($hImage, "Shell32.dll", 7);hardware 3
_GUIImageList_AddIcon($hImage, "Shell32.dll", 19);software 4

;~ _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)

$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")
Case $idLookupLocation
Case $idDefaultPrinter
Case $idNonIPrint
Case $idEncryptionStatus
Case $idMACnHD
Case $idDPIsetting
Case $idUptime
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

$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
$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
$iItem = DllStructGetData($tNMTOOLBAR, "iItem")

Case $NM_CLICK
$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
$iItem = DllStructGetData($tNMTOOLBAR, "iItem")

EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY


Func _GetToolbarButtonScreenPos($hwnd, $hTbar, $iCmdID, $iOffset = 0, $iIndex = 0, $hRbar = -1)
; 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
; $hRbar and $iIndex is for optional Rebar hwnd and band index
; $iOffset sets menu Y position below button
; Update: 06/27/2009 added offset for menu position below button, corrected left off-screen menu positioning.
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, "")

; X screen coordinate of dropdown button left corner
$aRet[0] = DllStructGetData($tpoint, "X")
; limit X coordinate to 0 if button partially off-screen
If $aRet[0] < 0 Then $aRet[0] = 0
; Y screen coordinate of dropdown button left corner
$aRet[1] = DllStructGetData($tpoint, "Y") + Number($iOffset)

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
If $aRet[0] <> 0 Then $aRet[0] += ($aBorders[0] - $aBandRect[0])
EndIf

Return $aRet; return X,Y screen coordinates of toolbar dropdown button lower left corner
EndFunc ;==>_GetToolbarButtonScreenPos
Link to comment
Share on other sites

My ellipses mean that there is a code. You needed to add the code showed above inside the original script, not to remove the entire Cases.

 

#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

Global Const $TBDDRET_DEFAULT = 0
Global Const $TBDDRET_NODEFAULT = 1
Global Const $TBDDRET_TREATPRESSED = 2

; 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, "Shell32.dll", 0);netsupport 0
_GUIImageList_AddIcon($hImage, "Shell32.dll", 3);-7);manage 1
_GUIImageList_AddIcon($hImage, "Shell32.dll", 2);common 2
_GUIImageList_AddIcon($hImage, "Shell32.dll", 7);hardware 3
_GUIImageList_AddIcon($hImage, "Shell32.dll", 19);software 4

;~ _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)

$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")
Case $idLookupLocation
Case $idDefaultPrinter
Case $idNonIPrint
Case $idEncryptionStatus
Case $idMACnHD
Case $idDPIsetting
Case $idUptime
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

$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
$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
$iItem = DllStructGetData($tNMTOOLBAR, "iItem")

$hMenu = _GUICtrlMenu_CreatePopup()
Switch $iItem
Case $idCommon
_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)
Case $idHardware
_GUICtrlMenu_AddMenuItem($hMenu, "Lookup Location", $idLookupLocation)
_GUICtrlMenu_AddMenuItem($hMenu, "Default Printer", $idDefaultPrinter)
_GUICtrlMenu_AddMenuItem($hMenu, "No nIPrint", $idNonIPrint)
_GUICtrlMenu_AddMenuItem($hMenu, "Encryption Status", $idEncryptionStatus)
_GUICtrlMenu_AddMenuItem($hMenu, "MAC nHD", $idMACnHD)
_GUICtrlMenu_AddMenuItem($hMenu, "DPI setting", $idDPIsetting)
_GUICtrlMenu_AddMenuItem($hMenu, "Uptime", $idUptime)
Case $idSoftware
EndSwitch

$aRet = _GetToolbarButtonScreenPos($hGUI, $hToolbar, $iItem, 2)
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
Return $TBDDRET_DEFAULT
Case $NM_CLICK
$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
$iItem = DllStructGetData($tNMTOOLBAR, "iItem")

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))
;----------------------------------------------------------------------------------------------
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY


Func _GetToolbarButtonScreenPos($hwnd, $hTbar, $iCmdID, $iOffset = 0, $iIndex = 0, $hRbar = -1)
; 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
; $hRbar and $iIndex is for optional Rebar hwnd and band index
; $iOffset sets menu Y position below button
; Update: 06/27/2009 added offset for menu position below button, corrected left off-screen menu positioning.
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, "")

; X screen coordinate of dropdown button left corner
$aRet[0] = DllStructGetData($tpoint, "X")
; limit X coordinate to 0 if button partially off-screen
If $aRet[0] < 0 Then $aRet[0] = 0
; Y screen coordinate of dropdown button left corner
$aRet[1] = DllStructGetData($tpoint, "Y") + Number($iOffset)

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
If $aRet[0] <> 0 Then $aRet[0] += ($aBorders[0] - $aBandRect[0])
EndIf

Return $aRet; return X,Y screen coordinates of toolbar dropdown button lower left corner
EndFunc ;==>_GetToolbarButtonScreenPos
Anyway, if it does not work for you I give up.

Br, FireFox.

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...