Jump to content

re-usable combobox function


Recommended Posts

im trying to do something along the lines of InputBox. however if it is used more than once at a time: reading the right value and closing out the right box.

has anyone tried doing this?

thanks in advance

$title = "Proxy Select"
$items = "proxy1.server|proxy2.server|proxy3.server"
$proxy = ComboBox($title, $items, 250, 70)

MsgBox(0, "", $proxy)

Func ComboBox($title, $items, $width, $height)

    GUICreate($title, $width, $height, -1, -1, $WS_EX_MDICHILD, $WS_EX_TOPMOST)

    $reusable_combo = GUICtrlCreateCombo("", 2, $width - 2, 2, $height - 2, $ES_PASSWORD)
    GUICtrlSetData(-1, $items)

    $OK_btn = GUICtrlCreateButton("OK", 210, 5, 40, 20, $BS_DEFPUSHBUTTON)
    GUICtrlSetOnEvent(-1, "ComboBox_Return")

    $CANCEL_btn = GUICtrlCreateButton("Cancel", 210, 30, 40, 20)
    GUICtrlSetOnEvent(-1, "DEL_combobox")

    GUISetState()

EndFunc   ;==>ComboBox

Func ComboBox_Return()
    $proxy = GUICtrlRead($reusable_combo)
    Return $proxy
EndFunc   ;==>ComboBox_Return
Link to comment
Share on other sites

  • Moderators

gcue,

Nice idea. :mellow: I would do it this way:

#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

$title = "Proxy Select"
$items = "proxy1.server|proxy2.server|proxy3.server"
$proxy = ComboBox($title, $items, 250, 80)

MsgBox(0, "", $proxy)

Func ComboBox($title, $items, $width, $height)

    ; Set MessageLoop mode and store previous mode
    Local $iOldOpt = Opt("GUIOnEventMode", 0)

    ; Declare return value
    Local $sRet = ""

    ;Create the GUI
    $hGUI = GUICreate($title, $width, $height, -1, -1, $WS_EX_MDICHILD, $WS_EX_TOPMOST)

    $reusable_combo = GUICtrlCreateCombo("", 5, 5, ($width - 70) / 2, ($height - 10) / 2)
    GUICtrlSetData(-1, $items)

    $OK_btn = GUICtrlCreateButton("OK", $width - 60, 5, 40, 20, $BS_DEFPUSHBUTTON)
    $CANCEL_btn = GUICtrlCreateButton("Cancel", $width - 60, 30, 40, 20)

    GUISetState()

    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $OK_btn
                ; Read selected value
                $sRet = GUICtrlRead($reusable_combo)
                ; Continue if no value selected
                If $sRet = "" Then ContinueLoop
                ExitLoop
            Case $CANCEL_btn
                Exitloop
        EndSwitch
    WEnd

    ; Delete GUI
    GUIDelete($hGUI)

    ; Reset previous mode
    Opt("GUIOnEventMode", $iOldOpt)

    ; Return selected value or "" if cancelled
    Return $sRet

EndFunc   ;==>ComboBox

Changing to MessageLoop mode keeps the whole thing in one function. And you cannot have $ES_PASSWORD style on a combo - did you try? :party:

Please ask if you have any questions. :P

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

many thanks =)

one question, how will it know which one to read from or delete from when two are opened simultaneously?

wish it was built in to autoit.. i put in a feature request but got bounced back as "autoit is not a out of the box language" =)

Edited by gcue
Link to comment
Share on other sites

  • Moderators

gcue,

one question, how will it know which one to read from or delete from when two are opened simultaneously?

Well in your initial post you said:

im trying to do something along the lines of InputBox

Can you have 2 InputBoxes open at the same time? No, so why would you expect to have 2 of these? :mellow:

Your user can only select thigs one at a time after all. :P

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

Again, message loops make it more complicated than event mode would be:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

Opt("GuiOnEventMode", 1)

Global $hGUI
Global $aidInputs[5][2] ; [n][0] = Input; [n][1] = hwnd of popup
Global $sChoices0 = "proxy1.server|proxy2.server|proxy3.server"
Global $sChoices1 = "Choice One|Choice Two|Choice Three|Choice Four|Choice Five"

$hGUI = GUICreate("Test", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
For $n = 0 To UBound($aidInputs) - 1
    GUISwitch($hGUI)
    GUICtrlCreateLabel("Input:  " & $n, 50, 20 + ($n * 40), 50, 20)
    $aidInputs[$n][0] = GUICtrlCreateInput("<None>", 100, 20 + ($n * 40), 100, 20)
    If Mod($n, 2) Then
        ; Odd
        $aidInputs[$n][1] = ComboBox("Odd Picker: " & $n, $sChoices1, 200 + ($n * 50), 100 + ($n * 50))
    Else
        ; Even
        $aidInputs[$n][1] = ComboBox("Even Picker: " & $n, $sChoices0, 200 + ($n * 50), 100 + ($n * 50))
    EndIf
Next
GUISetState(@SW_SHOW, $hGUI)

While 1
    Sleep(10)
WEnd

Func ComboBox($title, $items, $iX, $iY)
    Local $hPopup, $width = 250, $height = 80

    ;Create the GUI
    $hPopup = GUICreate($title, $width, $height, $iX, $iY, $WS_EX_MDICHILD, $WS_EX_TOPMOST)

    GUICtrlCreateCombo("", 5, 5, ($width - 70) / 2, ($height - 10) / 2)
    GUICtrlSetData(-1, $items)

    GUICtrlCreateButton("OK", $width - 60, 5, 40, 20, $BS_DEFPUSHBUTTON)
    GUICtrlSetOnEvent(-1, "_OKButton")

    GUICtrlCreateButton("Cancel", $width - 60, 30, 40, 20)
    GUICtrlSetOnEvent(-1, "_Cancel")

    GUISetState()

    Return $hPopup
EndFunc   ;==>ComboBox

Func _OKButton()
    Local $sChoice = ControlCommand(@GUI_WinHandle, "", "[CLASS:ComboBox; INSTANCE:1]", "GetCurrentSelection")
    For $n = 0 To UBound($aidInputs) - 1
        If $aidInputs[$n][1] = @GUI_WinHandle Then
            ControlSetText($hGUI, "", $aidInputs[$n][0], $sChoice)
            ExitLoop
        EndIf
    Next
    GUIDelete(@GUI_WinHandle)
EndFunc   ;==>_OKButton

Func _Cancel()
    GUIDelete(@GUI_WinHandle)
EndFunc   ;==>_Cancel

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

PsaltyDS,

Who is a clever as well a rakishly good-looking bird! :P Take a gold star! :mellow:

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

I was shooting for something similar, but am (so far) allergic to eventmode...

#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

Global $CB_GUI[1], $CB[1], $CB_Index

$title = "Proxy Select"
$items = "proxy1.server|proxy2.server|proxy3.server"
$proxy = ComboBox($title, $items, 300, 300, 400, 90)
$title = "Airplane Select"
$items = "ME-262|DO-335|AR-234"
$proxy = ComboBox($title, $items, 350, 350, 300, 90)
$title = "Ice Cream Select"
$items = "vanilla|chocolate|garlic"
$proxy = ComboBox($title, $items, 400, 400, 400, 90)
While 1
    $iMsg = GUIGetMsg()
    For $x = 1 to $CB_Index
        If $iMsg = $CB[$x] + 1 Then
            ToolTip(GUICtrlRead($CB[$x]) & " RETURNED FROM COMBOBOX " & $x)
            GUIDelete($CB_GUI[$X])
        EndIf
        If $iMsg = $CB[$x] + 2 Then GUIDelete($CB_GUI[$X])
    Next
WEnd
Exit

Func ComboBox($title, $items, $left, $top, $width, $height)
    $CB_Index += 1
    ReDim $CB_GUI[$CB_Index + 1], $CB[$CB_Index + 1]
    $CB_GUI[$CB_Index] = GUICreate("", $width, $height, $left, $top, $WS_EX_MDICHILD, $WS_EX_TOPMOST)
    $CB[$CB_Index] = GUICtrlCreateCombo($title, 5, 5, $width - 80, $height -10)
    GUICtrlSetData(-1, $items)
    GUICtrlCreateButton("OK", $width - 60, 5, 40, 20, $BS_DEFPUSHBUTTON)
    GUICtrlCreateButton("Cancel", $width - 60, 30, 40, 20)
    GUISetState()
EndFunc   ;==>ComboBox
Edited by Spiff59
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...