Combo box autocompletition

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Parole De JOJO
Messages : 446
Inscription : mar. 25/mai/2010 17:24
Localisation : Bnei Brak, Israel

Combo box autocompletition

Message par Parole De JOJO »

le code suivant est tire du codarchive, il est compatible seulement avec Purebasic 4.20
comment l'adapter a la nouvelle version?

merci d'avance

Code : Tout sélectionner

; English forum: http://www.purebasic.fr/english/viewtopic.php?t=7269&highlight=
; Author: ebs (updated for PB4.00 by blbltheworm)
; Date: 23. August 2003
; OS: Windows
; Demo: No

#NONE = -1 

;- autocomplete specified combobox 
Procedure AutocompleteComboBox(ComboBox.l) 
  Shared LenTextSave.l 
  Shared GadgetSave.l 

  ; get text entered by user 
  TextTyped.s = UCase(GetGadgetText(ComboBox)) 
  LenTextTyped.l = Len(TextTyped) 
  
  ; skip if same gadget and same length or shorter text (backspace?) 
  If ComboBox = GadgetSave And LenTextTyped <= LenTextSave 
    LenTextSave = LenTextTyped 
  ElseIf LenTextTyped 
    GadgetSave = #NONE 
    ; search combo contents for item that starts with text entered 
    MaxItem.l = CountGadgetItems(ComboBox) - 1 
    For Item.l = 0 To MaxItem 
      If TextTyped = UCase(Left(GetGadgetItemText(ComboBox, Item, 0), LenTextTyped)) 
        ; found matching item 
        ; set combo state 
        SetGadgetState(ComboBox, Item) 
        ; select added text only 
        hComboEdit.l = ChildWindowFromPoint_(GadgetID(ComboBox), 5, 5) 
        SendMessage_(hComboEdit, #EM_SETSEL, LenTextTyped, -1) 
        ; save gadget number and text length for next pass 
        LenTextSave = LenTextTyped 
        GadgetSave = ComboBox 
        ; exit For loop 
        Item = MaxItem 
      EndIf 
    Next 
  EndIf 
EndProcedure 

If OpenWindow(0, 0, 0, 300, 300, "Autocompletion", #PB_Window_SystemMenu|#PB_Window_TitleBar) 
  If CreateGadgetList(WindowID(0)) 
    ComboBoxGadget(0, 10, 10, 200, 100, #PB_ComboBox_Editable) 
    AddGadgetItem(0, -1, "Autocomplete") 
    AddGadgetItem(0, -1, "Bernard") 
    AddGadgetItem(0, -1, "Car") 
    AddGadgetItem(0, -1, "Explorer") 
    AddGadgetItem(0, -1, "Fantastic") 
    AddGadgetItem(0, -1, "General protection error") 
    AddGadgetItem(0, -1, "Purebasic") 
    AddGadgetItem(0, -1, "Purepower") 
    AddGadgetItem(0, -1, "Purevisual") 
    AddGadgetItem(0, -1, "Question") 
    AddGadgetItem(0, -1, "Zas") 
  EndIf 
EndIf 

Repeat 
  Event = WaitWindowEvent() 
  Select Event 
    Case #PB_Event_Gadget 
      If EventGadget() = 0 
        AutocompleteComboBox(0) 
      EndIf 
  EndSelect 
Until Event = #PB_Event_CloseWindow 

End
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: Combo box autocompletition

Message par Backup »

....
Dernière modification par Backup le mar. 19/août/2014 11:36, modifié 1 fois.
Parole De JOJO
Messages : 446
Inscription : mar. 25/mai/2010 17:24
Localisation : Bnei Brak, Israel

Re: Combo box autocompletition

Message par Parole De JOJO »

merci, je connaissais cette mise a jour, mais ca ne marche pas
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Combo box autocompletition

Message par Ar-S »

ça marche sur la 1ère lettre du 1er mot.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: Combo box autocompletition

Message par Backup »

Ar-S a écrit :ça marche sur la 1ère lettre du 1er mot.
oui , et je ne pense pas que ce code soit fait pour rendre un résultat diffèrent ! :)
Parole De JOJO a écrit :merci, je connaissais cette mise a jour, mais ca ne marche pas
c'est pas une mise a jour , j'ai juste ajouter "point.point" a l'Api donné par ton code !

Code : Tout sélectionner

hComboEdit.l = ChildWindowFromPoint_(GadgetID(ComboBox), 5, 5) 
remplacé par

Code : Tout sélectionner

hComboEdit.l = ChildWindowFromPoint_(GadgetID(ComboBox),point.point) 
c'est ce qui plantait ...

j'ai corrigé, c'est deja pas mal non ?
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Combo box autocompletition

Message par Le Soldat Inconnu »

Oui, enfin, il y avait pas mal de chose à revoir sur ce code pour le faire fonctionner.

C'était plutôt mal fichu, je trouve.
Voici la correction

Code : Tout sélectionner

; Author: LSI (Correction of code from ebs, 23. August 2003)
; OS: Windows

;- autocomplete specified combobox
Procedure AutocompleteComboBox_SearchEdit(hwnd.l, lParam.l)
	Tampon.s = Space(50)
	GetClassName_(hwnd, @Tampon, 50)
	
	If Tampon = "Edit" ; Non de l'objet rechercher
		PokeL(lParam, hwnd)
	EndIf
	
	ProcedureReturn #True
EndProcedure
Procedure AutocompleteComboBox(ComboBox.l)
	
	; Get combobox edit hwnd
	ComboxEdit = 0
	EnumChildWindows_(GadgetID(ComboBox), @AutocompleteComboBox_SearchEdit(), @ComboxEdit)
	
	; get text entered by user
	TextTyped.s = UCase (GetGadgetText(ComboBox))
	SendMessage_(ComboxEdit, #EM_GETSEL, @Selection_Start, @Selection_End)
	LenTextTyped = Selection_Start
	LenTextSave = GetGadgetData(ComboBox)
	
	Debug TextTyped
	Debug LenTextTyped
	
	; skip if same gadget and same length or shorter text (backspace?)
	If LenTextTyped <= LenTextSave
		SetGadgetData(ComboBox, LenTextTyped)
	ElseIf LenTextTyped
		; search combo contents for item that starts with text entered
		MaxItem.l = CountGadgetItems(ComboBox) - 1
		For Item.l = 0 To MaxItem
			ItemText.s = GetGadgetItemText(ComboBox, Item, 0)
			If TextTyped = UCase (Left(ItemText, LenTextTyped))
				; found matching item²
				; set combo state
				SetGadgetState(ComboBox, Item)
				; select added text only
				Selection_Start = LenTextTyped
				Selection_End = Len(ItemText)
				SendMessage_(ComboxEdit, #EM_SETSEL, Selection_Start, Selection_End)
				; save gadget number and text length for next pass
				SetGadgetData(ComboBox, LenTextTyped)
				; exit For loop
				Item = MaxItem
				Break
			EndIf
		Next
	EndIf
EndProcedure

If OpenWindow(0, 0, 0, 300, 300, "Autocompletion", #PB_Window_SystemMenu | #PB_Window_TitleBar)
	If CreateGadgetList(WindowID(0))
		ComboBoxGadget(0, 10, 10, 200, 24, #PB_ComboBox_Editable)
		AddGadgetItem(0, -1, "Autocomplete")
		AddGadgetItem(0, -1, "Bernard")
		AddGadgetItem(0, -1, "Car")
		AddGadgetItem(0, -1, "Explorer")
		AddGadgetItem(0, -1, "Fantastic")
		AddGadgetItem(0, -1, "General protection error")
		AddGadgetItem(0, -1, "Purebasic")
		AddGadgetItem(0, -1, "Purepower")
		AddGadgetItem(0, -1, "Purevisual")
		AddGadgetItem(0, -1, "Question")
		AddGadgetItem(0, -1, "Zas")
	EndIf
EndIf

Repeat
	event = WaitWindowEvent()
	Select event
		Case #PB_Event_Gadget
			If EventGadget() = 0
				AutocompleteComboBox(0)
			EndIf
	EndSelect
Until event = #PB_Event_CloseWindow

End
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Parole De JOJO
Messages : 446
Inscription : mar. 25/mai/2010 17:24
Localisation : Bnei Brak, Israel

Re: Combo box autocompletition

Message par Parole De JOJO »

merci
Répondre