Jump to content

_GUICtrlComboBox_AutoComplete with multiple comboboxes


corgano
 Share

Recommended Posts

Is it possible to have more than one combobox using _GUICtrlComboBox_AutoComplete with separate item lists? Say I wanted a GUI with two combo's, one with fruit (apple|orange|tomato) and one with vegetables (celery|Turnip|carrot) and wanted both of them to autocomplete. Is this possible? I like the way the _GUICtrlComboBox_AutoComplete example works, but I am having difficulties understanding the code :/

http://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlComboBox_AutoComplete.htm

my first attempt:

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

Global $hCombo, $hCombo2

_Main()

Func _Main()

    ; Create GUI
    GUICreate("ComboBox Auto Complete", 400, 296)
    $hCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    GUICtrlSetData(-1, "Apple|Orange|Tomatoe")
    $hCombo2 = GUICtrlCreateCombo("", 2, 42, 396, 296)
    GUICtrlSetData(-1, "One|Two|Three")
    GUISetState()

    ; Add files
;~     _GUICtrlComboBox_BeginUpdate($hCombo)
;~     _GUICtrlComboBox_AddDir($hCombo, @WindowsDir & "\*.exe")
;~     _GUICtrlComboBox_EndUpdate($hCombo)

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Func _Edit_Changed($hCombo)
    _GUICtrlComboBox_AutoComplete($hCombo)
EndFunc   ;==>_Edit_Changed

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo, $hWndCombo2
    If Not IsHWnd($hCombo) Then $hWndCombo = GUICtrlGetHandle($hCombo)
    If Not IsHWnd($hCombo2) Then $hWndCombo2 = GUICtrlGetHandle($hCombo2)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $hCombo, $hWndCombo
            Switch $iCode
                Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
                    _Edit_Changed($hCombo)
                    ; no return value
            EndSwitch

        Case $hCombo2, $hWndCombo
            Switch $iCode
                Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
                    _Edit_Changed($hCombo)
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

there must be an easier way..

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

  • Moderators

corgano,

You can simplify the code a bit - this works for me: ;)

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $cCombo1, $cCombo2

_Main()

Func _Main()

    ; Create GUI
    GUICreate("ComboBox Auto Complete", 400, 296)
    $cCombo1 = GUICtrlCreateCombo("", 2, 2, 396, 296)
    GUICtrlSetData(-1, "Apple|Orange|Tomato")
    $cCombo2 = GUICtrlCreateCombo("", 2, 42, 396, 296)
    GUICtrlSetData(-1, "One|Two|Three")
    GUISetState()

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Func _Edit_Changed($cCombo)
    _GUICtrlComboBox_AutoComplete($cCombo)
EndFunc   ;==>_Edit_Changed

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)

    #forceref $hWnd, $iMsg, $ilParam

    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    If $iCode = $CBN_EDITCHANGE Then
        Switch $iIDFrom
            Case $cCombo1
                _Edit_Changed($cCombo1)
            Case $cCombo2
                _Edit_Changed($cCombo2)
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
Does it work for you too? :)

M23

Edited by Melba23
Typo

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

Thankyou so much :D This is awesome :D

there should really be an autocomplete style for Combos. It'd make things sooo much simpler. But it's not a standard windows style, so it'd probably be difficult...

Still, we can dream of a GUICtrlCreateCombo("", default, default, default, default, $CBS_AUTOCOMPLETE) style can't we? :P

That should really be the example in the help file. It's short, usefull, and shows multiple (It's easier to subtract from a multiple example than add to a single example)

The help file page for _GUICtrlComboBox_AutoComplete is rather useless, as it contains next to no information, and there is no way a noob would understand the example. Someone should update it to be a bit more noob-friendly (noobs love and use the help file!)

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

  • Moderators

corgano,

Glad I could help. But I do not find this code over complicated - and it could always be made into a UDF which would go some way to simplifying the whole affair. I will see if I can come up with something tomorrow. :)

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

  • Moderators

corgano,

Does this meet your idea of "simple"? :huh:

#include <GUIConstantsEx.au3>
#include "CAC.au3"

_Main()

Func _Main()
    ; Create GUI
    GUICreate("ComboBox Auto Complete", 400, 296)
    $cCombo1 = GUICtrlCreateCombo("", 2, 2, 396, 296)
    ; Initialise combo
    _CAC_Init($cCombo1)
    GUICtrlSetData(-1, "Apple|Orange|Tomato")
    $cCombo2 = GUICtrlCreateCombo("", 2, 42, 396, 296)
    ; Initialise combo
    _CAC_Init($cCombo2)
    GUICtrlSetData(-1, "One|Two|Three")
    GUISetState()
    ; Register handler
    _CAC_RegMsg()

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
You will need this as CAC.au3:

#include <GUIComboBox.au3>

Global $g_aCAC_ComboList[1] = [0]

Func _CAC_Init($cCombo)
    $g_aCAC_ComboList[0] += 1
    ReDim $g_aCAC_ComboList[$g_aCAC_ComboList[0] + 1]
    $g_aCAC_ComboList[$g_aCAC_ComboList[0]] = $cCombo
EndFunc   ;==>_CAC_Init

Func _CAC_RegMsg()
    GUIRegisterMsg(0x0111, "_CAC_WM_COMMAND_Handler") ; $WM_COMMAND
EndFunc   ;==>_CAC_RegMsg

Func _CAC_WM_COMMAND_Handler($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $lParam
    Local $iIDFrom = BitAND($wParam, 0xFFFF) ;  (Low Word)
    If BitShift($wParam, 16) = $CBN_EDITCHANGE Then ; $iCode (Hi Word) ;
        For $i = 1 To $g_aCAC_ComboList[0]
            If $iIDFrom = $g_aCAC_ComboList[$i] Then
                __CAC_AutoComplete($iIDFrom)
                ExitLoop
            EndIf
        Next
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>_CAC_WM_COMMAND_Handler

Func __CAC_AutoComplete($cCombo)
    _GUICtrlComboBox_AutoComplete($cCombo)
EndFunc   ;==>__CAC_AutoComplete
Good enough? :)

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

That's awesome :D You're registering only the control's message to the handler right? That's cool :D

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

  • 1 year later...

I know this topic already has 1 more year without posts I posted just to thank Melba23 because this code was very useful for me, thanks Melba23.

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

×
×
  • Create New...