Inputbox beim schreiben auswählen

  • Moin

    möchte mal gerne wissen wie ich es machen kann, dass ich z.B. in eine Inputbox etwas eintrage und nach jedem neuen buchstabe die auswahl verkleinert wird.

    heißt also, gebe ich A ein erscheint

    Ameisenstr.
    Auenallee
    Amsterdam

    wenn ich einen 2. Buchstabe hinzufüge wird davon ausgegangen. Z.B. Am

    Ameisenstr.
    Amsterdam

  • ich habe 45 inputboxen in der so etwas stehen soll.

    muss ich nun für jede box eine neue funktion machen?? oder einfach die variablen in die funktion einschleußen?

    _ChooseBox($senseGui,$SenseCtrl)

    • Offizieller Beitrag

    45 ? Das Lösungsschema ist nur für ein Ctrl ausgelegt.
    Wenn du mehrere verwendest, mußt du für jedes Ctrl eine eigene Liste laden und zwar in Abhängigkeit, welches Ctrl gerade den Fokus hat. Du mußt also bei Fokuswechsel die Variable $SenseCtrl neu zuweisen. Dann könnte das klappen.

  • ich brauche 2 unterschiedliche listen

    in der einen sind namen, in der anderen viele orte

    edit: wüsste nicht wie ich das anstellen kann ^^

    Einmal editiert, zuletzt von Texos (20. März 2011 um 21:53)

    • Offizieller Beitrag

    Ich habe mein Bsp. mal auf 2 Inputs mit verschiedenen Listboxinhalten erweitert. Kannst du jetzt auf beliebig viel ausbauen.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <ListBoxConstants.au3>
    #include <WindowsConstants.au3>
    #include <GUIListBox.au3>
    #Include <WinAPI.au3>
    #include <Misc.au3>
    Opt("GUICloseOnESC", 0)

    [/autoit] [autoit][/autoit] [autoit]

    #region - Deklarationen für Sense
    Global $show = False
    Global $indexB = -1
    Global $SenseGui, $SenseCtrl, $guiBox, $box, $tmp, $currCtrl = 'Edit1' ; <== bei Start erstes Input (Achtung Anzahl Edit-Class, s. Input Create)
    Global $POSSenseGui[2]

    [/autoit] [autoit][/autoit] [autoit]

    ; unterschiedliche Boxinhalte festlegen
    Global $aData1[10] = ['Birne','Alligator','Auto','Dank','Automat','Bett','Garten','Bettler','Danke','Danksagung']
    Global $aData2[12] = ['Blech','Anagramm','Arie','Dolomiten','Artist','Berlin','Domino','Balearen','Atomausstieg','Debakel','Anker','Borelie']

    [/autoit] [autoit][/autoit] [autoit]

    #Region Box
    ; bei Start mit Data1 befüllen
    $guiBox = GUICreate('', 150, 85, 0, 0, BitOR($WS_SIZEBOX,$WS_POPUP), $WS_EX_TOPMOST)
    $box = _GUICtrlListBox_Create($guiBox, '', 0, 0, 150, 86, BitOR($LBS_SORT, 0x00B00002))
    ; ListBox muß 1 Pixel höher als GUI sein - sonst fehlerhafte Darstellung
    _ListBoxFill($aData1)
    #EndRegion Box

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListBoxFill($aData)
    For $i = 0 To UBound($aData) -1 ; falls Daten mit _FileReadToArray gelesen werden: StartIndex=1
    _GUICtrlListBox_AddString($box, $aData[$i])
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
    GUIRegisterMsg($WM_MOVE, "_WM_MOVE")
    GUIRegisterMsg(0x231, "_WM_ENTERSIZEMOVE")
    #EndRegion - Deklarationen Sense

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region Main
    $Form1 = GUICreate('Intelli Sense Box', 400, 300, 200, 50)
    $SenseGui = $Form1 ; <== Für Allgemeingültigkeit Zuweisung an $SenseGui
    $Input1 = GUICtrlCreateInput('', 10, 10, 380, 21) ; wenn Fokus ==> "Edit1" ! - die Ziffer kann variieren, wenn noch andere Edit-Class Elemente erstellt wurden!!
    $SenseCtrl = $Input1 ; <== bei Start ist Input1 das $SenseCtrl, wechselt bei Fokusverlust
    $Input2 = GUICtrlCreateInput('', 10, 40, 380, 21) ; wenn Fokus ==> "Edit2" !
    GUISetState()
    #EndRegion Main

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While True
    _ChooseBox()
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    ; Fokus abfragen:
    $tmp = ControlGetFocus($Form1)
    If StringInStr('Edit1 Edit2', $tmp, 1) Then ; hat eines der beiden Inputs den Fokus?
    If $tmp <> $currCtrl Then
    $currCtrl = $tmp
    Switch $currCtrl ; das Input mit Fokus als SenseCtrl zuweisen
    Case 'Edit1'
    $SenseCtrl = $Input1
    _GUICtrlListBox_ResetContent($box)
    _ListBoxFill($aData1)
    Case 'Edit2'
    $SenseCtrl = $Input2
    _GUICtrlListBox_ResetContent($box)
    _ListBoxFill($aData2)
    EndSwitch
    EndIf
    EndIf
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    #region - SenseFunc's
    Func _ChooseBox()
    If Not $show Then Return
    If _IsPressed('0D') Then ; ENTER
    ControlSetText($SenseGui, '', $SenseCtrl, _GUICtrlListBox_GetText($box, $indexB))
    GUISetState(@SW_HIDE, $guiBox)
    $show = False
    ElseIf _IsPressed('1B') Then ; ESC
    GUISetState(@SW_HIDE, $guiBox)
    $show = False
    ElseIf _IsPressed('26') Then ; UP
    If $indexB > 0 Then
    $indexB -= 1
    _GUICtrlListBox_SetCurSel($box, $indexB)
    Sleep(90)
    EndIf
    ElseIf _IsPressed('28') Then ; DOWN
    If $indexB < _GUICtrlListBox_GetCount($box)-1 Then
    $indexB += 1
    _GUICtrlListBox_SetCurSel($box, $indexB)
    Sleep(90)
    EndIf
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $hCtrl = $lParam
    Local $hSenseCtrl = $SenseCtrl
    If Not IsHWnd($hSenseCtrl) Then $hSenseCtrl = GUICtrlGetHandle($hSenseCtrl)
    If ($nNotifyCode = 1024 Or $nNotifyCode = 6) And $hCtrl = $hSenseCtrl Then
    Local $str = ControlGetText($SenseGui, '', $SenseCtrl)
    $indexB = _GUICtrlListBox_FindString($box, $str)
    _GUICtrlListBox_SetCurSel($box, $indexB)
    $caret = _CaretPos()
    If Not @error And Not $show Then
    If $caret[3] + $caret[4] - 95 < 0 Then ; Platz für Liste über dem Ctrl ausreichend?
    WinMove($guiBox, '', $caret[0], $caret[1] +25) ; Versatz 25 (Ctrlhöhe+5) unter y vom Ctrl
    Else
    WinMove($guiBox, '', $caret[0], $caret[1] -95) ; Versatz 95 (Boxhöhe+10) über y vom Ctrl
    EndIf
    GUISetState(@SW_SHOWNOACTIVATE, $guiBox)
    $show = True
    EndIf
    ElseIf $hCtrl = $box And $nNotifyCode = 1 Then
    $indexB = _GUICtrlListBox_GetCurSel($box)
    ControlSetText($SenseGui, '', $SenseCtrl, _GUICtrlListBox_GetText($box, $indexB))
    GUISetState(@SW_HIDE, $guiBox)
    $show = False
    ElseIf $show And $nNotifyCode = 512 And $hCtrl = $lParam And Not $hCtrl = $box Then
    GUISetState(@SW_HIDE,$guiBox)
    $show = False
    EndIf
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _WM_ENTERSIZEMOVE($hWnd)
    If $hWnd = $SenseGui Then $POSSenseGui = WinGetPos($SenseGui)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _WM_MOVE($hWnd)
    If $hWnd = $SenseGui Then
    Local $pos = WinGetPos($guiBox)
    Local $postemp = WinGetPos($SenseGui)
    WinMove($guiBox,"",$pos[0]-($POSSenseGui[0]-$postemp[0]),$pos[1]-($POSSenseGui[1]-$postemp[1]))
    $POSSenseGui = WinGetPos($SenseGui)
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _CaretPos()
    Local $old = Opt("CaretCoordMode", 0) ;relative mode
    Local $c = WinGetCaretPos() ;relative caret coords
    Local $w = WinGetPos("") ;window's coords
    Local $f = ControlGetFocus("","") ;text region "handle"
    Local $e = ControlGetPos("", "", $f) ;text region coords
    Local $h = ControlGetHandle("", "", $f) ;Ctrl-Handle
    Local $t[5]
    If IsArray($c) and IsArray($w) and IsArray($e) Then
    If _WinAPI_IsClassName($SenseCtrl, 'Edit') Then ; Input wird als Edit-Class erkannt
    $t[0] = $c[0] + $w[0] + $e[0]
    ElseIf _WinAPI_IsClassName($SenseCtrl, 'ComboBox') Then
    $t[0] = $w[0] + $e[0]
    EndIf
    $t[1] = $c[1] + $w[1] + $e[1]
    $t[2] = $h
    $t[3] = $w[1]
    $t[4] = $e[1]
    Opt("CaretCoordMode", $old)
    Return $t ;absolute screen coords of caret cursor
    Else
    Opt("CaretCoordMode", $old)
    SetError(1)
    EndIf
    EndFunc
    #endregion - SenseFunc's

    [/autoit]