Sign in to follow this  
Followers 0
SHAHRAM

Menu On Button

13 posts in this topic

Hi

I would like create a button, that when it is clicked on, then it shows a menu, some thing like context menu, but it is shown over the button, when it is clicked.

is that possible.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Well, until Gary or Holger... or anyone else for that matter can do a drawn one the correct way, this might tide you over for a bit (If I'm understanding what your wanting)... (It's quite crude, I didn't tweak it much... wrote it on the fly really)

#include <guiconstants.au3>
Local $ButtonMenuText[4] = ['', 'Notepad', 'Calculator', 'MSPaint']; Will need beta to run an Array like this example
Local $ButtonMenuCommands[4] = ['', 'Notepad.exe', 'Calc.exe', 'MSPaint.exe']
;$ButtonMenuText = 'Notepad'
;$ButtonMenuCommands = 'Notepad.exe'

$Main_GUI = GUICreate('NOTHING SPECIAL', 200, 100)
$BUTTON = GUICtrlCreateButton('BUTTON 1', 55, 35, 80, 25)
GUISetState()
While 1
    Sleep(10)
    $MSG = GUIGetMsg()
    If $MSG = $GUI_EVENT_CLOSE Then Exit
    If $MSG = $BUTTON Then
        _GUICtrlCreateButtonMenu ($Main_GUI, $BUTTON, $ButtonMenuText, $ButtonMenuCommands)
    EndIf
WEnd

Func _GUICtrlCreateButtonMenu ($sv_CurrentGUI, $v_ButtonToOperate, $av_Text, $av_Commands, _
        $b_LabelColour = "0xFFFFFF", $i_FontSize = 10, $i_FontWeight = 4, $i_WinTrans = 240, $i_DLLSlideDelay = 250)
    $MouseCoordOPT = Opt('MouseCoordMode', 2)
    Local $s_ButtonClassNN = ControlGetFocus($sv_CurrentGUI)
    Local $i_CPos = ControlGetPos($sv_CurrentGUI, '', $v_ButtonToOperate)
    Local $i_WinPos = WinGetPos($sv_CurrentGUI)
    Local $i_StringLen = ''
    If IsArray($av_Text) Then
        Local $GCCBM_Label[UBound($av_Text)]
        $av_Hold_Text = $av_Text
        $av_Hold_Commands = $av_Commands
        _ArraySortByLen ($av_Hold_Text)
        _ArraySortByLen ($av_Hold_Commands)
        If StringLen($av_Hold_Text[1]) > StringLen($av_Commands[1]) Then
            $i_StringLen = StringLen($av_Hold_Text[1])
        Else
            $i_StringLen = StringLen($av_Commands[1])
        EndIf
        If IsArray($i_CPos) And IsArray($i_WinPos) Then
            $v_Temp___GUI = GUICreate(WinGetTitle($sv_CurrentGUI) & ' Button Menu', _
                    (10 * $i_StringLen), ((UBound($av_Text) - 1) * 20), $i_CPos[0] + $i_WinPos[0], $i_CPos[1] + $i_WinPos[1], BitOR(0x00800000, 0x80000000))
            For $i_LabelCount = 1 To UBound($av_Text) - 1
                $GCCBM_Label[$i_LabelCount] = GUICtrlCreateLabel($av_Text[$i_LabelCount], _
                        0, _ 
                        (($i_LabelCount - 1) * 20), _ 
                        (10 * $i_StringLen), 20, _ 
                        BitOR(0x01, 0x1000))
                GUICtrlSetBkColor($GCCBM_Label[$i_LabelCount], $b_LabelColour)
                GUICtrlSetFont($GCCBM_Label[$i_LabelCount], $i_FontSize, $i_FontWeight)
            Next
            WinSetTrans($v_Temp___GUI, '', $i_WinTrans)
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $v_Temp___GUI, "int", $i_DLLSlideDelay, "long", 0x00040005)
            GUISetState(@SW_SHOW, $v_Temp___GUI)
            Local $i_LABEL_WAS_CLICKED = 0
            While WinActive($v_Temp___GUI)
                $GCCBM_MSG = GUIGetMsg()
                For $i_LabelCount = 1 To UBound($GCCBM_Label) - 1
                    If $GCCBM_MSG = $GCCBM_Label[$i_LabelCount] Then
                        Run($av_Commands[$i_LabelCount])
                        $i_LABEL_WAS_CLICKED = 1
                        ExitLoop
                    EndIf
                Next
                If $i_LABEL_WAS_CLICKED = 1 Then ExitLoop
            WEnd
            GUIDelete($v_Temp___GUI)
        EndIf
    ElseIf IsArray($i_CPos) And IsArray($i_WinPos) Then
        If StringLen($av_Text) > StringLen($av_Commands) Then
            $i_StringLen = StringLen($av_Text)
        Else
            $i_StringLen = StringLen($av_Commands)
        EndIf
        $v_Temp___GUI = GUICreate(WinGetTitle($sv_CurrentGUI) & ' Button Menu', _
                (10 * $i_StringLen), 20, $i_CPos[0] + $i_WinPos[0], $i_CPos[1] + $i_WinPos[1], BitOR(0x00800000, 0x80000000))
        $GCCBM_Label = GUICtrlCreateLabel($av_Text, 0, 0, (10 * $i_StringLen), 20, BitOR(0x01, 0x1000))
        GUICtrlSetBkColor($GCCBM_Label, $b_LabelColour)
        GUICtrlSetFont($GCCBM_Label, $i_FontSize, $i_FontWeight)
        WinSetTrans($v_Temp___GUI, '', $i_WinTrans)
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $v_Temp___GUI, "int", $i_DLLSlideDelay, "long", 0x00040005)
        GUISetState(@SW_SHOW, $v_Temp___GUI)
        Local $i_LABEL_WAS_CLICKED = 0
        While WinActive($v_Temp___GUI)
            $GCCBM_MSG = GUIGetMsg()
            If $GCCBM_MSG = $GCCBM_Label Then
                Run($av_Commands)
                ExitLoop
            EndIf
        WEnd
        GUIDelete($v_Temp___GUI)
    Else
    ;MsgBox(0, 'Error', 'The GUI/Button did not exist')
    EndIf
    Opt('MouseCoordMode', $MouseCoordOPT)
EndFunc  ;==>_GUICtrlCreateButtonMenu

Func _ArraySortByLen (ByRef $nArray, $Start = 1)
    For $i = $Start To UBound($nArray) - 2
        Local $SE = $i
        For $x = $i To UBound($nArray) - 1
            If StringLen($nArray[$SE]) < StringLen($nArray[$x]) Then $SE = $x
        Next
        Local $HLD = $nArray[$i]
        $nArray[$i] = $nArray[$SE]
        $nArray[$SE] = $HLD
    Next
EndFunc  ;==>_ArraySortByLen

Edit: Added a DLLCall to slide the menu in from the left to bottom... you can set the delay... longer or shorter if you want (in milliseconds).

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Wow, thank you,

I was looking for something simpler, like Provoking a right click on the button when it is clicked, to show the cotext menu of that button,

This script is working fine,

Thanx again

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Wow, thank you,

I was looking for something simpler, like Provoking a right click on the button when it is clicked, to show the cotext menu of that button,

This script is working fine,

Thanx again

Ha... I probably over complicated it, I'm known to do it, maybe someone can do it the right way, or improve on what I've done... here it is with the buttons being menu being high lighted over the selection
#include <guiconstants.au3>
Local $ButtonMenuText[4] = ['', 'Notepad', 'Calculator', 'MSPaint']; Will need beta to run an Array like this example
Local $ButtonMenuCommands[4] = ['', 'Notepad.exe', 'Calc.exe', 'MSPaint.exe']
;$ButtonMenuText = 'Notepad'
;$ButtonMenuCommands = 'Notepad.exe'

$Main_GUI = GUICreate('NOTHING SPECIAL', 200, 100)
$BUTTON = GUICtrlCreateButton('BUTTON 1', 55, 35, 80, 25)
GUISetState()
While 1
    Sleep(10)
    $MSG = GUIGetMsg()
    If $MSG = $GUI_EVENT_CLOSE Then Exit
    If $MSG = $BUTTON Then
        _GUICtrlCreateButtonMenu ($Main_GUI, $BUTTON, $ButtonMenuText, $ButtonMenuCommands)
    EndIf
WEnd

Func _GUICtrlCreateButtonMenu ($sv_CurrentGUI, $v_ButtonToOperate, $av_Text, $av_Commands, _
        $b_LabelColour = "0xFFFFFF", $b_HighLightLabelColur = '0xFFE600', $i_FontSize = 10, $i_FontWeight = 4, $i_WinTrans = 240, $i_DLLSlideDelay = 250)
    $MouseCoordOPT = Opt('MouseCoordMode', 2)
    Local $s_ButtonClassNN = ControlGetFocus($sv_CurrentGUI)
    Local $i_CPos = ControlGetPos($sv_CurrentGUI, '', $v_ButtonToOperate)
    Local $i_WinPos = WinGetPos($sv_CurrentGUI)
    Local $i_StringLen = ''
    If IsArray($av_Text) Then
        Local $GCCBM_Label[UBound($av_Text)]
        $av_Hold_Text = $av_Text
        $av_Hold_Commands = $av_Commands
        _ArraySortByLen ($av_Hold_Text)
        _ArraySortByLen ($av_Hold_Commands)
        If StringLen($av_Hold_Text[1]) > StringLen($av_Commands[1]) Then
            $i_StringLen = StringLen($av_Hold_Text[1])
        Else
            $i_StringLen = StringLen($av_Commands[1])
        EndIf
        If IsArray($i_CPos) And IsArray($i_WinPos) Then
            $v_Temp___GUI = GUICreate(WinGetTitle($sv_CurrentGUI) & ' Button Menu', _
                    (10 * $i_StringLen), ((UBound($av_Text) - 1) * 20), $i_CPos[0] + $i_WinPos[0], $i_CPos[1] + $i_WinPos[1], BitOR(0x00800000, 0x80000000))
            For $i_LabelCount = 1 To UBound($av_Text) - 1
                $GCCBM_Label[$i_LabelCount] = GUICtrlCreateLabel($av_Text[$i_LabelCount], _
                        0, _ 
                        (($i_LabelCount - 1) * 20), _ 
                        (10 * $i_StringLen), 20, _ 
                        BitOR(0x01, 0x1000))
                GUICtrlSetBkColor($GCCBM_Label[$i_LabelCount], $b_LabelColour)
                GUICtrlSetFont($GCCBM_Label[$i_LabelCount], $i_FontSize, $i_FontWeight)
            Next
            WinSetTrans($v_Temp___GUI, '', $i_WinTrans)
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $v_Temp___GUI, "int", $i_DLLSlideDelay, "long", 0x00040005)
            GUISetState(@SW_SHOW, $v_Temp___GUI)
            Local $i_LABEL_WAS_CLICKED = 0
            While WinActive($v_Temp___GUI)
                $GCCBM_MSG = GUIGetMsg()
                For $i_LabelCount = 1 To UBound($GCCBM_Label) - 1
                    Local $i_WendCpos = ControlGetPos($v_Temp___GUI, '', $GCCBM_Label[$i_LabelCount])
                    Local $i_WendMpos = MouseGetPos()
                    If ($i_WendMpos[0] >= $i_WendCpos[0] And $i_WendMpos[0] <= $i_WendCpos[0] + $i_WendCpos[2]) And _ 
                        ($i_WendMpos[1] >= $i_WendCpos[1] And $i_WendMpos[1] <= $i_WendCpos[1] + $i_WendCpos[3]) Then
                        GUICtrlSetBkColor($GCCBM_Label[$i_LabelCount], $b_HighLightLabelColur)
                    Else
                        GUICtrlSetBkColor($GCCBM_Label[$i_LabelCount], $b_LabelColour)
                    EndIf
                    If $GCCBM_MSG = $GCCBM_Label[$i_LabelCount] Then
                        Run($av_Commands[$i_LabelCount])
                        $i_LABEL_WAS_CLICKED = 1
                        ExitLoop
                    EndIf
                Next
                If $i_LABEL_WAS_CLICKED = 1 Then ExitLoop
            WEnd
            GUIDelete($v_Temp___GUI)
        EndIf
    ElseIf IsArray($i_CPos) And IsArray($i_WinPos) Then
        If StringLen($av_Text) > StringLen($av_Commands) Then
            $i_StringLen = StringLen($av_Text)
        Else
            $i_StringLen = StringLen($av_Commands)
        EndIf
        $v_Temp___GUI = GUICreate(WinGetTitle($sv_CurrentGUI) & ' Button Menu', _
                (10 * $i_StringLen), 20, $i_CPos[0] + $i_WinPos[0], $i_CPos[1] + $i_WinPos[1], BitOR(0x00800000, 0x80000000))
        $GCCBM_Label = GUICtrlCreateLabel($av_Text, 0, 0, (10 * $i_StringLen), 20, BitOR(0x01, 0x1000))
        GUICtrlSetBkColor($GCCBM_Label, $b_LabelColour)
        GUICtrlSetFont($GCCBM_Label, $i_FontSize, $i_FontWeight)
        WinSetTrans($v_Temp___GUI, '', $i_WinTrans)
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $v_Temp___GUI, "int", $i_DLLSlideDelay, "long", 0x00040005)
        GUISetState(@SW_SHOW, $v_Temp___GUI)
        Local $i_LABEL_WAS_CLICKED = 0
        While WinActive($v_Temp___GUI)
            $GCCBM_MSG = GUIGetMsg()
                    Local $i_WendCpos = ControlGetPos($v_Temp___GUI, '', $GCCBM_Label)
                    Local $i_WendMpos = MouseGetPos()
                    If ($i_WendMpos[0] >= $i_WendCpos[0] And $i_WendMpos[0] <= $i_WendCpos[0] + $i_WendCpos[2]) And _ 
                        ($i_WendMpos[1] >= $i_WendCpos[1] And $i_WendMpos[1] <= $i_WendCpos[1] + $i_WendCpos[3]) Then
                        GUICtrlSetBkColor($GCCBM_Label, $b_HighLightLabelColur)
                    Else
                        GUICtrlSetBkColor($GCCBM_Label, $b_LabelColour)
                    EndIf
            If $GCCBM_MSG = $GCCBM_Label Then
                Run($av_Commands)
                ExitLoop
            EndIf
        WEnd
        GUIDelete($v_Temp___GUI)
    Else
    ;MsgBox(0, 'Error', 'The GUI/Button did not exist')
    EndIf
    Opt('MouseCoordMode', $MouseCoordOPT)
EndFunc  ;==>_GUICtrlCreateButtonMenu

Func _ArraySortByLen (ByRef $nArray, $Start = 1)
    For $i = $Start To UBound($nArray) - 2
        Local $SE = $i
        For $x = $i To UBound($nArray) - 1
            If StringLen($nArray[$SE]) < StringLen($nArray[$x]) Then $SE = $x
        Next
        Local $HLD = $nArray[$i]
        $nArray[$i] = $nArray[$SE]
        $nArray[$SE] = $HLD
    Next
EndFunc  ;==>_ArraySortByLen
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

from the beta help file

; *****************
; * Second sample *
; *****************

#include <GUIConstants.au3>

$hGui          = GUICreate("My GUI", 170, 40)

$OptionsBtn  = GUICtrlCreateButton("&Options", 10, 10, 70, 20, $BS_FLAT)

; At first create a dummy control for the options and a contextmenu for it
$OptionsDummy   = GUICtrlCreateDummy()
$OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
$OptionsCommon  = GUICtrlCreateMenuItem("Common", $OptionsContext)
$OptionsFile    = GUICtrlCreateMenuItem("File", $OptionsContext)
GUICtrlCreateMenuItem("", $OptionsContext)
$OptionsExit    = GUICtrlCreateMenuItem("Exit", $OptionsContext)


$HelpBtn        = GUICtrlCreateButton("&Help", 90, 10, 70, 20, $BS_FLAT)

; Create a dummy control and a contextmenu for the help too
$HelpDummy    = GUICtrlCreateDummy()
$HelpContext    = GUICtrlCreateContextMenu($HelpDummy)
$HelpWWW        = GUICtrlCreateMenuItem("Website", $HelpContext)
GUICtrlCreateMenuItem("", $HelpContext)
$HelpAbout    = GUICtrlCreateMenuItem("About...", $HelpContext)


GUISetState()

While 1
    $Msg = GUIGetMsg()
    
    Switch $Msg
        Case $OptionsExit, $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $OptionsBtn
            ShowMenu($hGui, $Msg, $OptionsContext)
            
        Case $HelpBtn
            ShowMenu($hGui, $Msg, $HelpContext)
            
        Case $HelpAbout
            Msgbox(64, "About...", "GUICtrlGetHandle-Sample")
    EndSwitch   
WEnd
    
Exit


; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $hMenu = GUICtrlGetHandle($nContextID)
    
    $arPos = ControlGetPos($hWnd, "", $CtrlID)
    
    Local $x = $arPos[0]
    Local $y = $arPos[1] + $arPos[3]
    
    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc


; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")
    
    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
    
    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
   ; release Struct not really needed as it is a local 
    $stPoint = 0
EndFunc


; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Ha!!, I knew I'd over complicate it!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

yeah.. but hey, thats a pretty neat affect with the "complecated" way :)

Share this post


Link to post
Share on other sites

thank you both, that's exactly what I wanted, but the problem here is, that I am using this script in a low memory environment( infact ERDC),

and so I am using Opt("GUIOnEventMode", 1),

and

While 1

sleep(1000000)

Wend

,

I tried to convert this script to a way that I can use it, but it's a little complicated for me,

Ps.

isn't this onevent mode better than putting the script in a loop forever?

Share this post


Link to post
Share on other sites

Ok,

I guess I could do a little Modificatons, seams to work fine

#include <GUIConstants.au3>


Opt("GUIOnEventMode", 1)
$hGui          = GUICreate("My GUI", 170, 40)

$OptionsBtn  = GUICtrlCreateButton("&Options", 10, 10, 70, 20, $BS_FLAT)
GUICtrlSetOnEvent($OptionsBtn, "ShowMenua")

; At first create a dummy control for the options and a contextmenu for it
$OptionsDummy   = GUICtrlCreateDummy()
$OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
$OptionsCommon  = GUICtrlCreateMenuItem("Common", $OptionsContext)
$OptionsFile    = GUICtrlCreateMenuItem("File", $OptionsContext)
GUICtrlCreateMenuItem("", $OptionsContext)
$OptionsExit    = GUICtrlCreateMenuItem("Exit", $OptionsContext)
GUICtrlSetOnEvent($OptionsExit, "ShowMenua")


$HelpBtn        = GUICtrlCreateButton("&Help", 90, 10, 70, 20, $BS_FLAT)
GUICtrlSetOnEvent($HelpBtn, "ShowMenua")

; Create a dummy control and a contextmenu for the help too
$HelpDummy    = GUICtrlCreateDummy()
$HelpContext    = GUICtrlCreateContextMenu($HelpDummy)
$HelpWWW        = GUICtrlCreateMenuItem("Website", $HelpContext)
GUICtrlCreateMenuItem("", $HelpContext)
$HelpAbout    = GUICtrlCreateMenuItem("About...", $HelpContext)
GUICtrlSetOnEvent($HelpAbout, "ShowMenua")


GUISetState()

While 1
Sleep(1000000)
WEnd
Exit


Func ShowMenua()

    $Msg = @GUI_CTRLID
    
    Switch $Msg
       Case $OptionsExit, $GUI_EVENT_CLOSE
            Exit
            
        Case $OptionsBtn
            ShowMenu($hGui, $Msg, $OptionsContext)
            
        Case $HelpBtn
            ShowMenu($hGui, $Msg, $HelpContext)
            
        Case $HelpAbout
            Msgbox(64, "About...", "GUICtrlGetHandle-Sample")
    EndSwitch   


EndFunc


; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $hMenu = GUICtrlGetHandle($nContextID)
    
    $arPos = ControlGetPos($hWnd, "", $CtrlID)
    
    Local $x = $arPos[0]
    Local $y = $arPos[1] + $arPos[3]
    
    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc


; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")
    
    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
    
    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
   ; release Struct not really needed as it is a local 
    $stPoint = 0
EndFunc


; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc

Share this post


Link to post
Share on other sites

Ha... I probably over complicated it, I'm known to do it, maybe someone can do it the right way, or improve on what I've done... here it is with the buttons being menu being high lighted over the selection

#include <guiconstants.au3>
Local $ButtonMenuText[4] = ['', 'Notepad', 'Calculator', 'MSPaint']; Will need beta to run an Array like this example
Local $ButtonMenuCommands[4] = ['', 'Notepad.exe', 'Calc.exe', 'MSPaint.exe']
;$ButtonMenuText = 'Notepad'
;$ButtonMenuCommands = 'Notepad.exe'

$Main_GUI = GUICreate('NOTHING SPECIAL', 200, 100)
$BUTTON = GUICtrlCreateButton('BUTTON 1', 55, 35, 80, 25)
GUISetState()
While 1
    Sleep(10)
    $MSG = GUIGetMsg()
    If $MSG = $GUI_EVENT_CLOSE Then Exit
    If $MSG = $BUTTON Then
        _GUICtrlCreateButtonMenu ($Main_GUI, $BUTTON, $ButtonMenuText, $ButtonMenuCommands)
    EndIf
WEnd

Func _GUICtrlCreateButtonMenu ($sv_CurrentGUI, $v_ButtonToOperate, $av_Text, $av_Commands, _
        $b_LabelColour = "0xFFFFFF", $b_HighLightLabelColur = '0xFFE600', $i_FontSize = 10, $i_FontWeight = 4, $i_WinTrans = 240, $i_DLLSlideDelay = 250)
    $MouseCoordOPT = Opt('MouseCoordMode', 2)
    Local $s_ButtonClassNN = ControlGetFocus($sv_CurrentGUI)
    Local $i_CPos = ControlGetPos($sv_CurrentGUI, '', $v_ButtonToOperate)
    Local $i_WinPos = WinGetPos($sv_CurrentGUI)
    Local $i_StringLen = ''
    If IsArray($av_Text) Then
        Local $GCCBM_Label[UBound($av_Text)]
        $av_Hold_Text = $av_Text
        $av_Hold_Commands = $av_Commands
        _ArraySortByLen ($av_Hold_Text)
        _ArraySortByLen ($av_Hold_Commands)
        If StringLen($av_Hold_Text[1]) > StringLen($av_Commands[1]) Then
            $i_StringLen = StringLen($av_Hold_Text[1])
        Else
            $i_StringLen = StringLen($av_Commands[1])
        EndIf
        If IsArray($i_CPos) And IsArray($i_WinPos) Then
            $v_Temp___GUI = GUICreate(WinGetTitle($sv_CurrentGUI) & ' Button Menu', _
                    (10 * $i_StringLen), ((UBound($av_Text) - 1) * 20), $i_CPos[0] + $i_WinPos[0], $i_CPos[1] + $i_WinPos[1], BitOR(0x00800000, 0x80000000))
            For $i_LabelCount = 1 To UBound($av_Text) - 1
                $GCCBM_Label[$i_LabelCount] = GUICtrlCreateLabel($av_Text[$i_LabelCount], _
                        0, _ 
                        (($i_LabelCount - 1) * 20), _ 
                        (10 * $i_StringLen), 20, _ 
                        BitOR(0x01, 0x1000))
                GUICtrlSetBkColor($GCCBM_Label[$i_LabelCount], $b_LabelColour)
                GUICtrlSetFont($GCCBM_Label[$i_LabelCount], $i_FontSize, $i_FontWeight)
            Next
            WinSetTrans($v_Temp___GUI, '', $i_WinTrans)
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $v_Temp___GUI, "int", $i_DLLSlideDelay, "long", 0x00040005)
            GUISetState(@SW_SHOW, $v_Temp___GUI)
            Local $i_LABEL_WAS_CLICKED = 0
            While WinActive($v_Temp___GUI)
                $GCCBM_MSG = GUIGetMsg()
                For $i_LabelCount = 1 To UBound($GCCBM_Label) - 1
                    Local $i_WendCpos = ControlGetPos($v_Temp___GUI, '', $GCCBM_Label[$i_LabelCount])
                    Local $i_WendMpos = MouseGetPos()
                    If ($i_WendMpos[0] >= $i_WendCpos[0] And $i_WendMpos[0] <= $i_WendCpos[0] + $i_WendCpos[2]) And _ 
                        ($i_WendMpos[1] >= $i_WendCpos[1] And $i_WendMpos[1] <= $i_WendCpos[1] + $i_WendCpos[3]) Then
                        GUICtrlSetBkColor($GCCBM_Label[$i_LabelCount], $b_HighLightLabelColur)
                    Else
                        GUICtrlSetBkColor($GCCBM_Label[$i_LabelCount], $b_LabelColour)
                    EndIf
                    If $GCCBM_MSG = $GCCBM_Label[$i_LabelCount] Then
                        Run($av_Commands[$i_LabelCount])
                        $i_LABEL_WAS_CLICKED = 1
                        ExitLoop
                    EndIf
                Next
                If $i_LABEL_WAS_CLICKED = 1 Then ExitLoop
            WEnd
            GUIDelete($v_Temp___GUI)
        EndIf
    ElseIf IsArray($i_CPos) And IsArray($i_WinPos) Then
        If StringLen($av_Text) > StringLen($av_Commands) Then
            $i_StringLen = StringLen($av_Text)
        Else
            $i_StringLen = StringLen($av_Commands)
        EndIf
        $v_Temp___GUI = GUICreate(WinGetTitle($sv_CurrentGUI) & ' Button Menu', _
                (10 * $i_StringLen), 20, $i_CPos[0] + $i_WinPos[0], $i_CPos[1] + $i_WinPos[1], BitOR(0x00800000, 0x80000000))
        $GCCBM_Label = GUICtrlCreateLabel($av_Text, 0, 0, (10 * $i_StringLen), 20, BitOR(0x01, 0x1000))
        GUICtrlSetBkColor($GCCBM_Label, $b_LabelColour)
        GUICtrlSetFont($GCCBM_Label, $i_FontSize, $i_FontWeight)
        WinSetTrans($v_Temp___GUI, '', $i_WinTrans)
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $v_Temp___GUI, "int", $i_DLLSlideDelay, "long", 0x00040005)
        GUISetState(@SW_SHOW, $v_Temp___GUI)
        Local $i_LABEL_WAS_CLICKED = 0
        While WinActive($v_Temp___GUI)
            $GCCBM_MSG = GUIGetMsg()
                    Local $i_WendCpos = ControlGetPos($v_Temp___GUI, '', $GCCBM_Label)
                    Local $i_WendMpos = MouseGetPos()
                    If ($i_WendMpos[0] >= $i_WendCpos[0] And $i_WendMpos[0] <= $i_WendCpos[0] + $i_WendCpos[2]) And _ 
                        ($i_WendMpos[1] >= $i_WendCpos[1] And $i_WendMpos[1] <= $i_WendCpos[1] + $i_WendCpos[3]) Then
                        GUICtrlSetBkColor($GCCBM_Label, $b_HighLightLabelColur)
                    Else
                        GUICtrlSetBkColor($GCCBM_Label, $b_LabelColour)
                    EndIf
            If $GCCBM_MSG = $GCCBM_Label Then
                Run($av_Commands)
                ExitLoop
            EndIf
        WEnd
        GUIDelete($v_Temp___GUI)
    Else
;MsgBox(0, 'Error', 'The GUI/Button did not exist')
    EndIf
    Opt('MouseCoordMode', $MouseCoordOPT)
EndFunc ;==>_GUICtrlCreateButtonMenu

Func _ArraySortByLen (ByRef $nArray, $Start = 1)
    For $i = $Start To UBound($nArray) - 2
        Local $SE = $i
        For $x = $i To UBound($nArray) - 1
            If StringLen($nArray[$SE]) < StringLen($nArray[$x]) Then $SE = $x
        Next
        Local $HLD = $nArray[$i]
        $nArray[$i] = $nArray[$SE]
        $nArray[$SE] = $HLD
    Next
EndFunc ;==>_ArraySortByLen
Hello, If i use this script with this...

FileInstall("C:\Test.exe", @TempDir & "\Test.exe",1)

Local $ButtonMenuText[3] = ['', 'Test', 'Calculator']

Local $ButtonMenuCommands[3] = ['', 'Test.exe', 'Calc.exe']

then i always get a error that he can not find the path of test.exe if i press test.

Is this not working with @tempdir?


Sapiente vince, rex, noli vincere ferro!

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Hello, If i use this script with this...

FileInstall("C:\Test.exe", @TempDir & "\Test.exe",1)

Local $ButtonMenuText[3] = ['', 'Test', 'Calculator']

Local $ButtonMenuCommands[3] = ['', 'Test.exe', 'Calc.exe']

then i always get a error that he can not find the path of test.exe if i press test.

Is this not working with @tempdir?

You should try the actual path.. so instead of >> ['', 'Test.exe', 'Calc.exe'] you should make it >> ['', @TempDir & '\Test.exe', 'Calc.exe'] Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You should try the actual path.. so instead of >> ['', 'Test.exe', 'Calc.exe'] you should make it >> ['', @TempDir & '\Test.exe', 'Calc.exe']

Yes i try that already but that make the button menu 3 times bigger :think:

Is this not possible without changes on the button menu size?

With _makepath or something?


Sapiente vince, rex, noli vincere ferro!

Share this post


Link to post
Share on other sites

Yes i try that already but that make the button menu 3 times bigger :think:

Is this not possible without changes on the button menu size?

With _makepath or something?

Look at _PathSplit() in beta, you'll have to write your own UDF to load it. But you'll need the actual path to the exe if it isn't in the script directory, that just makes sense?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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  
Followers 0