Ich hätte da mal ne Frage ...
Ich möchte gerne Inhalte ins dropdown einer Combobox schreiben, das funktioniert soweit auch,
leider kann ich aber die Inhalte die schon geschrieben wurden nicht einfach löschen, und das müsste schon auch geschehen.
Hier mal die Codezeilen (achtung, benutzt eine googlefunktion, also Internetzugriff)
[autoit]#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <inet.au3>
#include <array.au3>
#include <GUIComboBox.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
Global $Combo1, $data, $olddata
[/autoit][autoit][/autoit][autoit]#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 515, 42, 288, 338)
$Combo1 = GUICtrlCreateCombo("Combo1", 8, 8, 497, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
[/autoit][autoit][/autoit][autoit]While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
If GUICtrlRead($Combo1) <> "" Then
$data = GUICtrlRead($Combo1)
If $olddata <> $data Then
If StringLen($data) < 3 Then
Else
$suggestions = _GoogleSuggestions($data)
_GUICtrlComboBox_BeginUpdate($Combo1)
For $i = 1 To UBound($suggestions) - 1
_GUICtrlComboBox_AddString($Combo1, $suggestions[$i])
Next
_GUICtrlComboBox_EndUpdate($Combo1)
EndIf
EndIf
$olddata = $data
EndIf
WEnd
Func _Edit_Changed()
_GUICtrlComboBox_AutoComplete($Combo1)
EndFunc ;==>_Edit_Changed
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
If Not IsHWnd($Combo1) Then $hWndCombo = GUICtrlGetHandle($Combo1)
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word
Switch $hWndFrom
Case $Combo1, $hWndCombo
Switch $iCode
Case $CBN_CLOSEUP ; Sent when the list box of a combo box has been closed
_DebugPrint("$CBN_CLOSEUP" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->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" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->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" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->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" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->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" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->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" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus
_DebugPrint("$CBN_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->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" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->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" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->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" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_SETFOCUS ; Sent when a combo box receives the keyboard focus
_DebugPrint("$CBN_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; no return value
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func _GoogleSuggestions($sSuggest); Retruns an Array of Suggestions
Local $sSource, $aResults;, $aQueries
$sSource = _INetGetSource("http://google.de/complete/search?output=toolbar&q=" & $sSuggest)
If @error Then Return SetError(1)
$aResults = StringRegExp($sSource, '<CompleteSuggestion><suggestion data="(.*?)"/>', 3)
;~ $sQueries = StringRegExp($source, '"/><num_queries int="(\d{0,})"/>', 3)
Return $aResults
EndFunc ;==>_GoogleSuggestions
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @LF & _
"+======================================================" & @LF & _
"-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
"+======================================================" & @LF)
EndFunc ;==>_DebugPrint
Ich hab versucht die Box mit _GUICtrlComboBox_ResetContent zu löschen, was leider dazu führt, dass auch jeder bisher eingetippte Buchstabe sich verabschiedet (wenig sinnvoll ;))
Ein nachträgliches setzen von _GUICtrlComboBox_SetEditText mit dem bisher eingegebenen text ($data) hilft leider auch überhauptnicht weiter.
über eine Schleife (zeile 34ff) die einzelnen Einträge zu löschen ist auch in die Hose gegangen.
Denn Mausbewegung in der Combobox lässt danach unvorhersehbar dinge verschwinden, was auch irgendwie nicht Sinn der Sache war
For $i=0 to _GUICtrlComboBox_GetCount($Combo1)
_GUICtrlComboBox_DeleteString($Combo1, $i)
Next
Nun brauch ich also doch Eure Hilfe:
Wie kann ich, ohne die bisherige Eingabe zu verlieren die Combobox löschen und danach dennoch etwas aus Ihr wählen?
(Also ganz wie sich google selber verhält)
'sid