Jump to content

Recommended Posts

Posted

I have a situation where a user needs to select from a set of canned choices that are held in a simple text file of up to about 10 choices (not more than 20).  The choices are static and the file can be read once, when the script starts.

The feature I envision might be described as a Popup Selection Panel.  

I'd like for the selection to be as simple as possible:
• Click a button to open a overlaid panel of choices (overlaid on top of the main GUI).
• Click on a choice to select it.
... all with no check boxes or 'OK' button, for example.  The panel would close when a selection is made.

I can use a popup window with a combo box, as shown by the following prototype.  But I would like it to be even cleaner, with no "current choice" or even combo box appearance ... just the choices shown and a selection made from them.

;
;       Popup Combo Box Prototype
;
$hGUI = GUICreate("Test Script", 400, 200)
$idComboBox = GUICtrlCreateCombo("", 40, 40, 200, 24)
GUICtrlSetData($idComboBox, "Choice A|Choice B|Choice C|Choice D")
GUICtrlSetFont(-1, 14)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            ExitLoop
        Case $idComboBox
            $sComboRead = GUICtrlRead($idComboBox)
            MsgBox(0, "", "The selection is currently: " & $sComboRead, 0, $hGUI)
    EndSwitch
WEnd

I've searched these forums for something suitable (idea or starting point script), but don't recognize anything as such.  Hopefully, something like this already exists.  I would think it would be useful in a lot of instances.

Thanks in advance for any suggestions.

Selection Panle.png

Posted (edited)

Maybe RadioButtons would be simple choice:

$hGUI = GUICreate("Test Script", 400, 200)
;~ $idComboBox = GUICtrlCreateCombo("", 40, 40, 200, 24)
$id1 = GUICtrlCreateRadio("Choice A", 40, 40, 200, 24)
GUICtrlSetFont(-1, 14)
$id2 = GUICtrlCreateRadio("Choice B", 40, 70, 200, 24)
GUICtrlSetFont(-1, 14)
$id3 = GUICtrlCreateRadio("Choice C", 40, 100, 200, 24)
GUICtrlSetFont(-1, 14)
$id4 = GUICtrlCreateRadio("Choice D", 40, 130, 200, 24)
GUICtrlSetFont(-1, 14)
;~ GUICtrlSetData($idComboBox, "Choice A|Choice B|Choice C|Choice D")
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            ExitLoop
;~         Case $idComboBox
;~             $sComboRead = GUICtrlRead($idComboBox)
;~             MsgBox(0, "", "The selection is currently: " & $sComboRead, 0, $hGUI)
    EndSwitch
WEnd

Probably array of id's ...

Edited by Zedna
Posted (edited)

a context menu of radio items perhaps? (not necessarily activated by right-click).

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Posted

Thanks for your responses.

Radio buttons are an interesting possibility.  I get an event upon the selection, but it would seem to need a 20-case while loop to avoid the need for a 'Done' button.  (IOW, so I can respond immediately to the user's selection.

While 1
    Switch GUIGetMsg()
        Case -3
            ExitLoop
         Case $id1, $id2, $id3, $id4
             MsgBox(0, "", "The selection is currently: ____", 0, $hGUI)
    EndSwitch
WEnd

Regarding a context menu, I had found this forum post/solution, but it doesn't let me control the font or format, and it seems to need the same kind of While Loop processing.

Have I missed something obvious with either of these?

Posted

This is turning into a bit of a puzzle.  I have an idea that a carefully-fashioned combo box might be a solution.  But I'm stumped on one point:

Does anyone know of a way to programmatically Open a combo box?

I can Send a Page Up and it selects the first entry.  And I can Send a Page Down to select the last.  But I can't determine a key that just Opens the set of choices (equivalent to clicking on the down arrow that's on the right side of the control).

Thanks for any suggestions.

 

Posted

It turns out that the answer to my question is CB_SHOWDROPDOWN.

So, I think I have something that's both simple and powerful:

;
;       Popup Combo Box Prototype
;
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>

$hGUI = GUICreate("Test Script", 200, 80, -1, -1, $WS_POPUP)
$idComboBox = GUICtrlCreateCombo("", 0, -30, 200, 24)
GUICtrlSetData($idComboBox, "Choice A|Choice B|Choice C|Choice D")
GUICtrlSetFont(-1, 14)
GUICtrlSetState($idComboBox, $GUI_FOCUS)
GUISetState()

GUICtrlSendMsg($idComboBox, $CB_SHOWDROPDOWN , True, -1) ; 4th param 'not used'

While 1
    Switch GUIGetMsg()
        Case -3
            ExitLoop
        Case $idComboBox
            $sComboRead = GUICtrlRead($idComboBox)
            MsgBox(0, "", "The selection is currently: " & $sComboRead, 0, $hGUI)
            Exit
    EndSwitch
WEnd

But can someone explain what the cursor's doing? ... and how to cancel it?

 

 

Posted (edited)

Here is concept with RadioButtons using array of ID's including evaluating result in message loop using the array of ID's

Dim $aId[4][2] = [[0,"Choice A"], [0,"Choice B"], [0,"Choice C"], [0,"Choice D"]]

$hGUI = GUICreate("Test Script", 400, 200)
;~ $idComboBox = GUICtrlCreateCombo("", 40, 40, 200, 24)
$aId[0][0] = GUICtrlCreateRadio($aId[0][1], 40, 40, 200, 24)
GUICtrlSetFont(-1, 14)
$aId[1][0] = GUICtrlCreateRadio($aId[1][1], 40, 70, 200, 24)
GUICtrlSetFont(-1, 14)
$aId[2][0] = GUICtrlCreateRadio($aId[2][1], 40, 100, 200, 24)
GUICtrlSetFont(-1, 14)
$aId[3][0] = GUICtrlCreateRadio($aId[3][1], 40, 130, 200, 24)
GUICtrlSetFont(-1, 14)
;~ GUICtrlSetData($idComboBox, "Choice A|Choice B|Choice C|Choice D")
GUISetState()
While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case -3
            ExitLoop
;~         Case $idComboBox
;~             $sComboRead = GUICtrlRead($idComboBox)
;~             MsgBox(0, "", "The selection is currently: " & $sComboRead, 0, $hGUI)
        Case Else
            If $msg <> 0 Then
                For $i = 0 To UBound($aId)-1
                    If $msg = $aId[$i][0] Then
                        MsgBox(0, "", "The selection is currently: " & $aId[$i][1], 0, $hGUI)
                        ExitLoop
                    EndIf
                Next
            EndIf
    EndSwitch
WEnd

You can use For/Next loop also for GUICtrlCreateRadio part of code ...

 

EDIT: Instead of one 2D array you can have two 1D arrays, one for IDs, one for text labels

Edited by Zedna

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...