morgan1991 |
29-04-2019 13:26 2869579 |
Нашел на просторах:
Код:
; http://www.autoitscript.com/forum/topic/158070-autocomplete-input-text/
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <ListBoxConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
Global $Words1[20] = ["fight", "first", "fly", "third", "fire", "wall", "hi", "hello", "world", "window", _
"window 1", "window 2", "window 3", "window 4", "window 5", "window 6", "window 7", "window 8", "window 9", "window 10"]
Global $Words2[6] = ["Alain", "Aline", "Bernard", "Beatrice", "Chloe", "Caroline"]
Global $hGUI, $hList
Global $sChosen, $idCurInput, $sCurrInput = "", $hListGUI = -1
$hGUI = GUICreate("AutoComplete Input Text", 300, 200)
GUICtrlCreateLabel('lettres "w, f" ', 10, 10, 280, 20)
$hInput = GUICtrlCreateInput("", 10, 40, 280, 20)
GUICtrlCreateLabel('lettres "a, b, c" ', 10, 70, 280, 20)
$hInput2 = GUICtrlCreateInput("", 10, 100, 280, 20)
GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $IdFrom = BitAnd($wParam, 0x0000FFFF)
Local $iCode = BitShift($wParam, 16)
Switch $IdFrom
Case $hInput, $hInput2
Switch $iCode
Case $EN_UPDATE
$idCurInput = $IdFrom
_Update($idCurInput)
EndSwitch
Case $hList
_Update($idCurInput)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _Update($_input)
If GUICtrlRead($_Input) <> $sCurrInput Then
$sCurrInput = GUICtrlRead($_Input)
If $hListGUI <> -1 Then ; List is visible.
GUIDelete($hListGUI)
$hListGUI = -1
EndIf
Local $_array
Switch $_input
Case $hInput
$_array = $Words1
Case $hInput2
$_array = $Words2
EndSwitch
$hList = _PopupSelector($hGUI, $hListGUI, $_Input, _CheckInputText($_Input, $_array))
EndIf
If $hList <> -1 Then $sChosen = GUICtrlRead($hList)
If $sChosen <> "" Then
GuiCtrlSetData($_Input, $sChosen)
$sCurrInput = GUICtrlRead($_Input)
GUIDelete($hListGUI)
$hListGUI = -1
$sChosen = ""
EndIf
EndFunc
Func _PopupSelector($hMainGUI, ByRef $hListGUI, $_Input, $sCurr_List)
Local $hList = -1
If $sCurr_List = "" Then Return $hList
Local $pos = ControlGetPos($hMainGUI, "", $_Input)
$hListGUI = GUICreate("", 280, 160, $pos[0], $pos[1]+$pos[3], $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_MDICHILD), $hMainGUI)
$hList = GUICtrlCreateList("", 0, 0, 280, 150, BitOR(0x00100000, 0x00200000))
StringReplace($sCurr_List, "|", "|")
Local $iCurrHeight = @extended*GUICtrlSendMsg($hList, $LB_GETITEMHEIGHT, 0, 0)+10
WinMove($hListGUI, "", Default, Default, Default, $iCurrHeight)
GUICtrlSetPos($hList, 0, 0, 150, $iCurrHeight)
GUICtrlSetData($hList, $sCurr_List)
GUISetControlsVisible($hListGUI) ; To Make Control Visible And Window Invisible.
GUISetState(@SW_SHOWNOACTIVATE, $hListGUI)
Return $hList
EndFunc ;==>_PopupSelector
Func _CheckInputText($_Input, $array)
Local $sPartialData = ""
$aSelected = _GetSelectionPointers($_Input)
If (IsArray($aSelected)) And ($aSelected[0] <= $aSelected[1]) Then
$sCurrInput = GUICtrlRead($_Input)
Local $aSplit = StringSplit(StringLeft($sCurrInput, $aSelected[0]), " ")
$aSelected[0] -= StringLen($aSplit[$aSplit[0]])
If $aSplit[$aSplit[0]] <> "" Then
For $A = 0 To UBound($array)-1
If StringLeft($array[$A], StringLen($aSplit[$aSplit[0]])) = $aSplit[$aSplit[0]] _
And $array[$A] <> $aSplit[$aSplit[0]] Then
$sPartialData &= $array[$A] & "|"
EndIf
Next
EndIf
EndIf
Return $sPartialData
EndFunc ;==>_CheckInputText
Func _GetSelectionPointers($hEdit)
Local $aReturn[2] = [0, 0]
Local $aSelected = GUICtrlRecvMsg($hEdit, 0x00B0) ; $EM_GETSEL.
If IsArray($aSelected) Then
$aReturn[0] = $aSelected[0]
$aReturn[1] = $aSelected[1]
EndIf
Return $aReturn
EndFunc ;==>_GetSelectionPointers
Func GUISetControlsVisible($hWnd) ; By Melba23.
Local $aControlGetPos = 0, $hCreateRect = 0, $hRectRgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
Local $iLastControlID = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1))
For $i = 3 To $iLastControlID
$aControlGetPos = ControlGetPos($hWnd, '', $i)
If IsArray($aControlGetPos) = 0 Then ContinueLoop
$hCreateRect = _WinAPI_CreateRectRgn($aControlGetPos[0], $aControlGetPos[1], $aControlGetPos[0] + $aControlGetPos[2], $aControlGetPos[1] + $aControlGetPos[3])
_WinAPI_CombineRgn($hRectRgn, $hCreateRect, $hRectRgn, 2)
_WinAPI_DeleteObject($hCreateRect)
Next
_WinAPI_SetWindowRgn($hWnd, $hRectRgn, True)
_WinAPI_DeleteObject($hRectRgn)
EndFunc ;==>GUISetControlsVisible
Не охота переделывать готовый код под GUICtrlCreateCombo.
Теперь будет два варианта, может кому пригодится.
|