#include <WinAPI.au3>
#include <GuiEdit.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
Opt('MustDeclareVars', 1)
Global $hEdit, $hList = 0, $tRECT, $iHeight
Global $aValid[11] = ['Bruce Wayne', 'Bruce Banner', 'Brian Damage', 'Peter Parker', 'Polly Pocket', 'Hugh Janus', 'Zachary Quack', 'Zebedee', 'Billy Hunt', 'Jackson Pollock', 'Clark Kent']
_Main()
Exit
Func _Main()
Local $hGUI = GUICreate('Daisywheel Combo', 512, 212)
$hEdit = GUICtrlCreateInput('', 8, 8, 496)
$hList = GUICtrlCreateList('', 8, 32, 496, 24, $LBS_SORT + $WS_VSCROLL)
GUICtrlSetOnEvent($hList, '_OnListClick')
GUICtrlSetState($hList, $GUI_HIDE)
GUISetState()
$tRECT = _WinAPI_GetWindowRect(GUICtrlGetHandle($hEdit))
$iHeight = DllStructGetData($tRECT, 'Bottom') - DllStructGetData($tRECT, 'Top')
GUIRegisterMsg($WM_COMMAND, '_OnMessage')
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
Func _OnMessage($hWnd, $iMsg, $wParam, $lParam)
Local $hWndFrom = $lParam, $iIDFrom = _WinAPI_LoWord($wParam), $iCode = _WinAPI_HiWord($wParam)
Switch $iMsg
Case $WM_COMMAND
Switch $hWndFrom
Case GUICtrlGetHandle($hEdit)
Switch $iCode
Case $EN_CHANGE
_ShowList()
EndSwitch
Case GUICtrlGetHandle($hList)
Switch $iCode
Case $LBN_SELCHANGE
_OnListClick()
Case $LBN_DBLCLK, $LBN_KILLFOCUS
GUICtrlSetState($hList, $GUI_HIDE)
If $iCode = $LBN_DBLCLK Then GUICtrlSetState($hEdit, $GUI_FOCUS)
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_OnMessage
Func _ShowList()
Local $sText = GUICtrlRead($hEdit), $i, $j = 0, $sContents = ''
If $sText <> '' Then
For $i = 0 To UBound($aValid) - 1
If StringRegExp($aValid[$i], '(?i)^' & $sText & '.*') Then
$sContents &= '|' & $aValid[$i]
$j += 1
EndIf
Next
EndIf
If $sContents <> '' Then
ConsoleWrite($j & ' ' & $iHeight * $j & @CRLF)
GUICtrlSetPos($hList, 8, 8 + $iHeight, 496, $iHeight * $j)
GUICtrlSetData($hList, $sContents)
GUICtrlSetState($hList, $GUI_SHOW)
Else
GUICtrlSetState($hList, $GUI_HIDE)
EndIf
EndFunc ;==>_ShowList
Func _OnListClick()
ConsoleWrite(GUICtrlRead($hList) & @CRLF)
GUICtrlSetData($hEdit, GUICtrlRead($hList))
EndFunc ;==>_OnListClick