Jump to content

Multi-line combobox


Recommended Posts

I don't think a multiline combo is part of Windows. I've never heard of such a thing. You could use a [disabled] multiline edit control with a button next to it. Pressing the button could open a child window with the choices of what you may want.

Link to comment
Share on other sites

  • 3 years later...
  • Moderators

telmob,

I do not believe a multiline combo is possible. :)

Does this work-a-round help at all? :graduated:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIMenu.au3>

Global Enum $id_1 = 1000, $id_2, $id_3
Global $sItem_1 = "Item 1 and a long tail"
Global $sItem_2 = "Item 2 and a long tail"
Global $sItem_3 = "Item 3 and a long tail"

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

$hEdit = GUICtrlCreateEdit("", 10, 10, 60, 35, $ES_READONLY)
$hSplit = GUICtrlCreateButton("6", 69, 10, 20, 35)
GUICtrlSetFont(-1, 10, 400, 0, "Webdings")

GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
       Case $hSplit
            ; Show the menu for a left click on the button
            _Menu()
    EndSwitch

WEnd

Func _Menu()

    ; Move mouse to correct place
    $iOldOpt = Opt("MouseCoordMode", 2)
    MouseMove(10, 45, 0)
    Opt("MouseCoordMode", $iOldOpt)
    ; Show menu
    $hMenu = _GUICtrlMenu_CreatePopup(24)
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, $sItem_1, $id_1)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, $sItem_2, $id_2)
    _GUICtrlMenu_InsertMenuItem($hMenu, 3, $sItem_3, $id_3)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI)
    _GUICtrlMenu_DestroyMenu($hMenu)

EndFunc

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

    #forceref $hWnd, $iMsg, $lParam
    Switch $wParam
        Case $id_1
            GUICtrlSetData($hEdit, $sItem_1)
        Case $id_2
            GUICtrlSetData($hEdit, $sItem_2)
        Case $id_3
            GUICtrlSetData($hEdit, $sItem_3)
    EndSwitch

EndFunc   ;==>WM_COMMAND

Or perhaps this one which is considerably simpler: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIMenu.au3>
#Include <GuiComboBox.au3>

Global $sItem_1 = "Item 1 and a long tail"
Global $sItem_2 = "Item 2 and a long tail"
Global $sItem_3 = "Item 3 and a long tail"

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

$hEdit = GUICtrlCreateEdit("", 10, 10, 60, 35, $ES_READONLY)
$hSplit = GUICtrlCreateButton("6", 69, 10, 21, 35)
GUICtrlSetFont(-1, 10, 400, 0, "Webdings")

$hCombo = GUICtrlCreateCombo("", 10, 25, 80, 20, BitOr($GUI_SS_DEFAULT_COMBO, $WS_CLIPSIBLINGS))
GUICtrlSetData(-1, $sItem_1 & "|" & $sItem_2 & "|" &$sItem_3)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hSplit
            _GUICtrlComboBox_ShowDropDown ($hCombo, True)
        Case $hCombo
            GUICtrlSetData($hEdit, GUICtrlRead($hCombo))
    EndSwitch

WEnd

M23

Edit: Added second example. ;)

Edited by Melba23

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 had an idea about this. It's complicated, but I imagine it would be possible to embed a child GUI with a vertical scroll bar and set the multiline data on labels. The trick is getting the child gui to appear and disappear. It could be destroyed and created by clicking on a custom desined button, similar in appearnce to a combo dropdown button. I'm not sure how you would highlight the items, but it all sounds feasable. Some consideration will have to be made about other controls on the gui to ensure the embeded gui does not overlap anything (I think). Perhaps other controls could be destroyed before the dropdown appears in front of them, or maybe the child gui does not need to be embedded. Perhaps it can be floated over the parent in the corresponding position.

Edit

On reflection I think there are several downsides to my idea. It woulld be limited to a small number of items and would involve quite a lot of code.

Edited by czardas
Link to comment
Share on other sites

  • Moderators

czardas,

Do you mean something like this: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIMenu.au3>
#Include <GuiComboBox.au3>

Global $sItem_1 = "Item 1 and a long tail"
Global $sItem_2 = "Item 2 and a longer tail"
Global $sItem_3 = "Item 3 and an even longer tail"

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

$hEdit = GUICtrlCreateEdit("", 10, 10, 60, 35, $ES_READONLY)
$hSplit = GUICtrlCreateButton("6", 69, 10, 21, 35)
GUICtrlSetFont(-1, 10, 400, 0, "Webdings")

GUISetState()

$hGUI_Child = GUICreate("Child", 200, 200, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
$hCombo = GUICtrlCreateCombo("", 0, -21, 200, 20, BitOr($GUI_SS_DEFAULT_COMBO, $WS_CLIPSIBLINGS))
GUICtrlSetData(-1, $sItem_1 & "|" & $sItem_2 & "|" &$sItem_3)

GUISetState(@SW_HIDE)

WinMove($hGUI_Child, "", 115, 167)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hSplit
            GUISetState(@SW_SHOW, $hGUI_Child)
            _GUICtrlComboBox_ShowDropDown ($hCombo, True)
        Case $hCombo
            GUISetState(@SW_HIDE, $hGUI_Child)
            GUICtrlSetData($hEdit, GUICtrlRead($hCombo))
    EndSwitch

WEnd

Still a bit rough - ideally I would want to limit the child GUI size to that required for the drop-down and deal with the "no combo selection" case, but it shows the principle. :)

Not sure it is any better then the other examples though. :graduated:

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 thinking more along the lines of having multiline on all items in the list, and not just on the selected item in the edit. I thought it might be possible to float something over the parent gui. At first I hadn't quite figured out what was going on in the examples you posted. Now I have looked again and I think your solution is the most practical and probably the best. Thanks again. :graduated:

Edited by czardas
Link to comment
Share on other sites

  • Moderators

czardas,

You mean something like this then: :graduated:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Global $iItems = 3        ; Number of items in list
Global $aLabelID[$iItems][2]  ; ControlIDs & handles of labels
; Data and colour state of labels
Global $aData[$iItems] = ["Item 1 and a long tail", "Item 2 and a longer tail", "Item 3 and an even longer tail"]

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

$hEdit = GUICtrlCreateEdit("", 10, 10, 80, 35, $ES_READONLY)
$hSplit = GUICtrlCreateButton("6", 89, 10, 21, 35)
GUICtrlSetFont(-1, 10, 400, 0, "Webdings")

$hButton = GUICtrlCreateButton("Test", 10, 70, 80, 30)

GUISetState()

$hGUI_Child = GUICreate("Child", 200, 200, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)

; Create "list"
For $i = 0 To $iItems - 1
    $aLabelID[$i][0] = GUICtrlCreateLabel($aData[$i], 10, 10 + ($i * 40), 100, 40)
    $aLabelID[$i][1] = GUICtrlGetHandle(-1)
Next

GUISetState(@SW_HIDE)

WinMove($hGUI_Child, "", 114, 167)

$iLast_Hilite = 0

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hSplit
            GUISetState(@SW_SHOW, $hGUI_Child)
        Case $aLabelID[0][0] To $aLabelID[$iItems - 1][0]
            GUICtrlSetData($hEdit, GUICtrlRead($iMsg))
            GUISetState(@SW_HIDE, $hGUI_Child)
    EndSwitch

    ; Get highlighting
    If BitAnd(WinGetState($hGUI_Child, ""), 2) Then
        If @AutoItX64 Then
            $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData ( $tPoint, "X", MouseGetPos(0))
            DllStructSetData ( $tPoint, "Y", MouseGetPos(1))
            $tPoint64 = DllStructCreate("int64", DllStructGetPtr($tPoint))
            $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int64", DllStructGetData($tPoint64, 1))
        Else
            $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", MouseGetPos(0), "uint", MouseGetPos(1))
        EndIf
        For $i = 0 To $iItems - 1
            If $aLabelID[$i][1] = $aHwnd[0] And $aLabelID[$i][0] <> $iLast_Hilite Then
                GUICtrlSetBkColor($iLast_Hilite, 0xFEFEFE)
                GUICtrlSetBkColor($aLabelID[$i][0], 0xCCCCFF)
                $iLast_Hilite = $aLabelID[$i][0]
            EndIf
        Next
    EndIf

WEnd

Can you tell I am bored this morning? ;)

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