Sign in to follow this  
Followers 0
corgano

_GUICtrlComboBox_AutoComplete with multiple comboboxes

7 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Subz
      By Subz
      Wanted to create an AutoComplete function like "Start » Run" functionality for both Urls and Files using SHAutoComplete function,  Unfortunately my knowledge is quite limited and so put the following together based on existing functions and snippets online.  While everything works fine, I'm not sure if I've written the function correctly and was hoping someone with more experience with WinAPI could look it over and let me know if I've missed anything.
      Thanks in advance.
      #include <GuiComboBoxEx.au3> #include <GUIConstantsEx.au3> Global Const $SHACF_AUTOAPPEND_FORCE_OFF = 0x80000000 Global Const $SHACF_AUTOAPPEND_FORCE_ON = 0x40000000 Global Const $SHACF_AUTOSUGGEST_FORCE_OFF = 0x20000000 Global Const $SHACF_AUTOSUGGEST_FORCE_ON = 0x10000000 Global Const $SHACF_DEFAULT = 0x00000000 Global Const $SHACF_FILESYS_ONLY = 0x00000010 Global Const $SHACF_FILESYS_DIRS = 0x00000020 Global Const $SHACF_FILESYSTEM = 0x00000001 Global Const $SHACF_URLHISTORY = 0x00000002 Global Const $SHACF_URLMRU = 0x00000004 Global Const $SHACF_USETAB = 0x00000008 Global Const $SHACF_URLALL = BitOR($SHACF_URLHISTORY, $SHACF_URLMRU) Global Const $SHACF_VIRTUAL_NAMESPACE = 0x00000040 ; #FUNCTION# =========================================================================================================== ; Name...........: __WinAPI_SHAutoComplete ; Description ...: Instructs system edit controls to use AutoComplete to help complete URLs or file system paths in a ; Input or ComboBoxEx control. ; Syntax.........: __WinAPI_SHAutoComplete ( $hWnd [, $dwFlag = $SHACF_DEFAULT] ) ; Parameters ....: $hWnd - Handle of parent window ; $dwFlags - The flags to control the operation of SHAutoComplete: ; | $SHACF_AUTOAPPEND_FORCE_OFF - Ignore the registry default and force the AutoAppend feature off. ; This flag must be used in combination with one or more of the ; SHACF_FILESYS* or SHACF_URL* flags. ; | $SHACF_AUTOAPPEND_FORCE_ON - Ignore the registry value and force the AutoAppend feature on. The ; completed string will be displayed in the edit box with the added ; characters highlighted. This flag must be used in combination with ; one or more of the SHACF_FILESYS* or SHACF_URL* flags. ; |$SHACF_AUTOSUGGEST_FORCE_OFF - Ignore the registry default and force the AutoSuggest feature off. ; This flag must be used in combination with one or more of the ; SHACF_FILESYS* or SHACF_URL* flags. ; |$SHACF_AUTOSUGGEST_FORCE_ON - Ignore the registry value and force the AutoSuggest feature on. A ; selection of possible completed strings will be displayed as a ; drop-down list, below the edit box. ; This flag must be used in combination with one or more of the ; SHACF_FILESYS* or SHACF_URL* flags. ; |$SHACF_DEFAULT - The default setting, equivalent to SHACF_FILESYSTEM + SHACF_URLALL. ; SHACF_DEFAULT cannot be combined with any other flags. ; |$SHACF_FILESYS_ONLY - Include the file system only. ; |$SHACF_FILESYS_DIRS - Include the file system and directories, UNC servers, and UNC server ; shares. ; |$SHACF_FILESYSTEM - Include the file system and the rest of the Shell (Desktop, Computer, ; and Control Panel, for example). ; |$SHACF_URLHISTORY - Include the URLs in the user's History list. ; |$SHACF_URLMRU - Include the URLs in the user's Recently Used list. ; |$SHACF_USETAB - Allow the user to select from the autosuggest list by pressing the ; TAB key. If this flag is not set, pressing the TAB key will shift ; focus to the next control and close the autosuggest list. If ; SHACF_USETAB is set, pressing the TAB key will select the first item ; in the list. Pressing TAB again will select the next item in the list, ; and so on. When the user reaches the end of the list, the next TAB key ; press will cycle the focus back to the edit control. This flag must be ; used in combination with one or more of the SHACF_FILESYS* or ; SHACF_URL* flags listed on this page. ; |$SHACF_URLALL - Include the URLs in the users History and Recently Used lists. ; Equivalent to SHACF_URLHISTORY + SHACF_URLMRU. ; |$SHACF_VIRTUAL_NAMESPACE ; Author ........: Subz ; Remarks .......: The first four flags are used to override the Internet Explorer registry settings. The user can change these ; settings manually by launching the Internet Options property sheet from the Tools menu and clicking the ; Advanced tab. ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb759862(v=vs.85).aspx ; =============================================================================================================================== Func __WinAPI_SHAutoComplete($hWnd, $dwFlags = $SHACF_DEFAULT) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) Local $hWndEdit, $aResult Switch _WinAPI_GetClassName($hWnd) Case 'ComboBoxEx32' $hWndEdit = _GUICtrlComboBoxEx_GetEditControl($hWnd) Case 'Edit' $hWndEdit = $hWnd Case Else Return EndSwitch $aResult = DllCall('shlwapi.dll', 'long', 'SHAutoComplete', 'hwnd', $hWndEdit, 'int', $dwFlags) If @error Or Not $aResult[0] Then Return SetError(@error, @extended, '') Return SetExtended($aResult[0], $aResult[2]) EndFunc ;==>__WinAPI_SHAutoComplete Global $hGui_FileSystem Global $hGui_WebHistory Example() Func Example() ; Create GUI $hGui = GUICreate('Example', 600, 100) GUICtrlCreateLabel('Website History:', 5, 5, 150, 21) $hGui_WebHistory = GUICtrlCreateInput('http://', 2, 2, 380, 21) __WinAPI_SHAutoComplete($hGui_WebHistory, BitOR($SHACF_AUTOAPPEND_FORCE_ON, $SHACF_URLHISTORY, $SHACF_USETAB)) $hGui_FileSystem = _GUICtrlComboBoxEx_Create($hGui, "", 2, 42, 396, 120) GUISetState(@SW_SHOW) _GUICtrlComboBoxEx_BeginUpdate($hGui_FileSystem) _GUICtrlComboBoxEx_AddDir($hGui_FileSystem, @WindowsDir & "\*.exe") _GUICtrlComboBoxEx_EndUpdate($hGui_FileSystem) __WinAPI_SHAutoComplete($hGui_FileSystem, BitOR($SHACF_AUTOAPPEND_FORCE_ON, $SHACF_FILESYSTEM, $SHACF_USETAB)) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example  
    • Em4gdn1m
      By Em4gdn1m
      Hey everyone, I'm curious if there is a way to incorporate a checkbox with a combo GUICtrl?
      so for instance I have a GUI that has a bunch of checkboxes that allow me to open certain programs as needed.  (this is just some parsing of my code, sorry, noob here and not sure what the preferred method of displaying code is, please enlighten me)

          $L0742 = GUICtrlCreateCheckbox("L07 4.2", 110, 320, 100)
          $L07502 = GUICtrlCreateCheckbox("L07 5.0.2", 110, 350, 100)
          $GenComm = GUICtrlCreateCheckbox("GenComm", 110, 380, 100)
          $Templates = GUICtrlCreateCheckbox("Templates", 110, 410, 100)
          $MCT = GUICtrlCreateCheckbox("MCT", 110, 440, 100)
          $Desktop_Shortcuts = GUICtrlCreateCheckbox("Desktop Shortcuts by Tester", 110, 470, 200)
       
      ...
      Case $msg = $RunBtn
                  RunPrograms()
       
      ...
      Func RunPrograms()

          if GUICtrlRead($L0742) = $GUI_CHECKED then Run("C:\Program Files\Varian\Paxscan\L07 Rel4.2\viva\viva.exe", "")
          if GUICtrlRead($L07502) = $GUI_CHECKED then Run("C:\Program Files\Varian\Paxscan\L07 Rel5\viva\viva.exe", "")
          if GUICtrlRead($GenComm) = $GUI_CHECKED then Run("\\Fpanelfs1\FPShared\Desktop_Shortcuts_by_Tester\Matt\CPI Generator\CPI Generator Windows 7 64 Bit\GenComm\GenComm.NET.exe", "")
          if GUICtrlRead($Templates) = $GUI_CHECKED then ShellExecute("\\Fpanelfs1\FPProjects\Documentation Controlled\Test_Templates")
          if GUICtrlRead($MCT) = $GUI_CHECKED then Run("\\Fpanelfs1\FPProjects\Documentation Controlled\Manufacturing Software\MCT\MCT.exe","")
          if GUICtrlRead($Desktop_Shortcuts) = $GUI_CHECKED then ShellExecute("\\Fpanelfs1\fpshared\Desktop_Shortcuts_by_Tester")
      EndFunc
       
      so i click some checkboxes, and hit a run button and the programs which are checked run, great.
      BUT i want to add a bunch of options under one checkbox. A combo that will list a bunch of versions of a program that can be opened. something like this... but I want that program to be part of a checkbox
      $ViVAComboBox = GUICtrlCreateCombo("L01 Rel 13", 110, 320, 100)
      GUICtrlSetData($ViVAComboBox, "L04|L05|L07 Rel 4.2|L07 Rel 5.0.2|L09", "L07 Rel 4.2")
       
      is this possible? is there another GUICtrl that does this better that i am not aware of?
       
       
    • Wingens
      By Wingens
      Hi all,
      I created a little script we use at work for inputing date and time stamps into our ticket system.
      Now I thought it would look nice in a Metro style GUI, I found an UDF on the forum what does almost everything I want.
      I have but one thing I can't seem to find and don't have the skills to create.
      The gui uses one pulldown menu (GUICtrlCreateCombo) it stays in the older looking style.
      I attached the script and files I have, also in the zip you find an example of what I am looking for.
       
      Hope you guys can help me 
      Hotkey.zip
    • jloyzaga
      By jloyzaga
      I'm trying to use GUICtrlCreateCombo but I need it to get the list values from an excel spreadsheet column - that makes it dynamic. My method is to prompt for the Module name (this gives me the application to run the automation test) this also gives me the name of the folder that stores all the spreadsheets.
      1.I then get the list of spreadsheet names and use that as input for another list (this can be select 1 or many or all - don't know which control to use...)
      2.On selection I then go to the spreadsheets selected and display columns C, E from TestController tab in a further combo box to select 1 or many or all.
      3. keep doing point 2 above until all selected in 1 are complete. I'm wondering if I just display as many combo boxes as items selected in point 1 or loop thru them somehow.
      Very complex for my little brain - any advice to simplify is greatly appreciated
      Joe
       
      Accounts_TestFlow.xls
    • rm4453
      By rm4453
      I need to find a way to after x amount of seconds set the Autoit gui's ComboBox to next option available, and if it reaches the end of the list start back at beginning. This way I can cycle through checking if users are connected to a network. The combo is populated via a recursive file search that contains folders with each connected user's username. The ComboBox will contain something like " username\config " for every connected user. So I need to make so it cycles through constantly every X seconds I have the gui functioning, and all that I just can't get this one part to work.

      TL:DR - How do I make so an AutoIt GUI ComboBox will cycle through all of its options every X seconds, and when it reaches bottom of options cycle back to top and continue the process again.

      Thanks! I can't post any code due to NDA sorry...