;Auto complete combobox #include #include #include #include #include Global $g_idCombo Example() Func Example() ; Create GUI GUICreate("ComboBox Auto Complete", 200, 25) $g_idCombo = GUICtrlCreateCombo("", 2, 2, 196, 300) $myEnter = GUICtrlCreateDummy() $myEsc = GUICtrlCreateDummy() Global $iCnt = 0 ;Set GUIAccelerators to capture Enter key ; Local $aAcc[1][2] = [["{Enter}", $myEnter]] Local $aAcc[2][2] = [["{Enter}", $myEnter],["{Esc}", $myEsc]] GUISetAccelerators($aAcc) GUISetState(@SW_SHOW) ; Add files and strings and sort ; You could use InsertString at 0 index instead of AddString to see most recent first additions. _GUICtrlComboBox_BeginUpdate($g_idCombo) _GUICtrlComboBox_AddDir($g_idCombo, @WindowsDir & "\*.exe") Global $aStrings[4] = ["Rock","Paper","Scissors","Rubber"] for $i = 0 to 3 _GUICtrlComboBox_AddString($g_idCombo, $aStrings[$i]) Next $aStrings = _GUICtrlComboBox_GetListArray($g_idCombo) _ArraySort($aStrings) _GUICtrlComboBox_ResetContent($g_idCombo) for $i = 0 to UBound($aStrings) -1 ;ConsoleWrite($aStrings[$i] & @CRLF) _GUICtrlComboBox_AddString($g_idCombo, $aStrings[$i]) Next _GUICtrlComboBox_EndUpdate($g_idCombo) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Loop until the user exits. Do Sleep(100) ;<----- helps get enter key but hurts using close window button X Switch GUIGetMsg() Case $myEnter $iCnt +=1 $sCtrlRead = GUICtrlRead($g_idCombo) ConsoleWrite("Entered " & $iCnt & " " & $sCtrlRead & @CRLF) ToolTip("Entered " & $iCnt & " " & $sCtrlRead,10,10) Case $myEsc GUICtrlSetData($g_idCombo,"Set") ;~ ;GUIDelete() EndSwitch ;Alternative to Accelerator Keys ;~ if chk_key("0d") then ;~ $iCnt +=1 ;~ $sCtrlRead = GUICtrlRead($g_idCombo) ;~ ConsoleWrite("Press-Entered " & $iCnt & " " & $sCtrlRead & @CRLF) ;~ EndIf ;~ if chk_key("1b") then ;~ ConsoleWrite("Esc" & @CRLF) ;~ Exit ;~ EndIf ;and WinActive("ComboBox Auto Complete") Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example func chk_key($sK) ; 0d,1b Enter, Esc if _IsPressed($sK) and WinActive("ComboBox Auto Complete") then While _IsPressed($sK) Sleep(200) WEnd return True EndIf return False EndFunc Func _Edit_Changed() _GUICtrlComboBox_AutoComplete($g_idCombo) EndFunc ;==>_Edit_Changed Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo If Not IsHWnd($g_idCombo) Then $hWndCombo = GUICtrlGetHandle($g_idCombo) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $g_idCombo, $hWndCombo Switch $iCode Case $CBN_CLOSEUP ; Sent when the list box of a combo box has been closed _DebugPrint("$CBN_CLOSEUP" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value Case $CBN_DBLCLK ; Sent when the user double-clicks a string in the list box of a combo box _DebugPrint("$CBN_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value Case $CBN_DROPDOWN ; Sent when the list box of a combo box is about to be made visible _DebugPrint("$CBN_DROPDOWN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value 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 _DebugPrint("$CBN_EDITCHANGE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) _Edit_Changed() ; no return value Case $CBN_EDITUPDATE ; Sent when the edit control portion of a combo box is about to display altered text _DebugPrint("$CBN_EDITUPDATE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value Case $CBN_ERRSPACE ; Sent when a combo box cannot allocate enough memory to meet a specific request _DebugPrint("$CBN_ERRSPACE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus _DebugPrint("$CBN_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box _DebugPrint("$CBN_SELCHANGE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value Case $CBN_SELENDCANCEL ; Sent when the user selects an item, but then selects another control or closes the dialog box _DebugPrint("$CBN_SELENDCANCEL" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value Case $CBN_SELENDOK ; Sent when the user selects a list item, or selects an item and then closes the list _DebugPrint("$CBN_SELENDOK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value Case $CBN_SETFOCUS ; Sent when a combo box receives the keyboard focus _DebugPrint("$CBN_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; no return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint