Jump to content

Combo Button


Deye
 Share

Recommended Posts

Hi,

I need something that will look like this combo and act as a regular button
Where the drop-down should extend only when the arrow is pressed not anywhere else in the button's body

GUICtrlCreateUpdown might be an option but will have to find a way to link it to the button

Thanks
 

nclude <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a combobox control.
    Local $idComboBox = GUICtrlCreateCombo("", 10, 10, 185, 20, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
    Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Add additional buttons to the combobox.
    GUICtrlSetData($idComboBox, "button 1|button 2", "button 1")

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $sComboRead = ""

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop

            Case $idComboBox
                $sComboRead = GUICtrlRead($idComboBox)
                MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI)

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Link to comment
Share on other sites

  • Moderators

Deye,

A "SplitButton" control seems to me like the solution - you code it like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StructureConstants.au3>
#include <GuiMenu.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Main", 10, 10, 80, 30, $BS_SPLITBUTTON)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            MsgBox($MB_SYSTEMMODAL, "Chosen", "Main button")
    EndSwitch

WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
    If DllStructGetData($tStruct, "Code") = $BCN_DROPDOWN Then
        _Dropdown_Menu(DllStructGetData($tStruct, "hWndFrom"))
    EndIf

EndFunc   ;==>_WM_NOTIFY

Func _Dropdown_Menu($hCtrl)
    
    Local Enum $iOption_1 = 1000, $iOption_2
    Local $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Option 1", $iOption_1)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Option 2", $iOption_2)
    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hCtrl, -1, -1, 1, 1, 2)
        Case $iOption_1
            MsgBox($MB_SYSTEMMODAL, "Chosen", "Option 1")
        Case $iOption_2
            MsgBox($MB_SYSTEMMODAL, "Chosen", "Option 2")
    EndSwitch
    _GUICtrlMenu_DestroyMenu($hMenu)

EndFunc   ;==>_Dropdown_Menu

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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