Pb CallBack -> Accès memoire invalide
Publié : mer. 27/juin/2012 22:27
				
				Bonsoir,
J'ai un soucis d'accès mémoire invalide avec des fonction callback . Je fais un callback principal sur la fenêtre pour intercepter le changement du texte du StringGadget puis je voudrais récupérer la touche "taper" (Tab,Entrée,haut,bas) . D'après je que j'ai compris (c'est à dire pas grand chose )Il faut que je refasse un callback sur le StringGadget et la çà bug !!!!
)Il faut que je refasse un callback sur le StringGadget et la çà bug !!!!   
 
Pour la petite histoire je voulais un StringGadget qui ce complète tous seul . Pourquoi passer par les Callback , Pour que tous soit autonome un peu comme un nouveau Gadget Bref pourquoi faire simple quand on peut faire compliqué 
 
Voilà mon code spécial méga Bug ....
			J'ai un soucis d'accès mémoire invalide avec des fonction callback . Je fais un callback principal sur la fenêtre pour intercepter le changement du texte du StringGadget puis je voudrais récupérer la touche "taper" (Tab,Entrée,haut,bas) . D'après je que j'ai compris (c'est à dire pas grand chose
 )Il faut que je refasse un callback sur le StringGadget et la çà bug !!!!
)Il faut que je refasse un callback sur le StringGadget et la çà bug !!!!   
 Pour la petite histoire je voulais un StringGadget qui ce complète tous seul . Pourquoi passer par les Callback , Pour que tous soit autonome un peu comme un nouveau Gadget Bref pourquoi faire simple quand on peut faire compliqué
 
 Voilà mon code spécial méga Bug ....
Code : Tout sélectionner
;- Enumerations
;{
Enumeration
  #WinMain
  #String
EndEnumeration
;}
;- Structure
;{
Structure Lst
  Text.s
  Affiche.i
EndStructure
Structure ACStringInfo
  ID_Edit.i
  ID_List.i
  ListHeight.i 
EndStructure
  
;}
;- Variables
;{
Global NewList Liste.Lst()
Global ACS.ACStringInfo
Global Flag_EnCours = 0
Global oldEditProc.l
;}
;- Procedure
;{
Procedure LoWord(value)
  ProcedureReturn value & $FFFF
EndProcedure
Procedure HiWord(value)
  ProcedureReturn value >> 16 & $FFFF
EndProcedure 
Procedure AddToList(String.s)
  If ACS\ID_List
    Result=AddElement(Liste())
    If Result
      Liste()\Text = String
      Liste()\Affiche = 1
      SortStructuredList(Liste(), #PB_Sort_Ascending, OffsetOf(Lst\Text), #PB_Sort_String)
    EndIf
  EndIf
EndProcedure
Procedure UpdateListView()
  ClearGadgetItems(ACS\ID_List)
  ResetList(Liste())
  
  While NextElement(Liste())
    If Liste()\Affiche = 1
      AddGadgetItem(ACS\ID_List,-1,Liste()\Text)
    EndIf
  Wend
  
EndProcedure
Procedure SearchInList()
  Flag_EnCours = 1
  ;Texte tapé et sa longueur
  TextTyped.s = GetGadgetText(ACS\ID_Edit)
  LenTextTyped = Len(TextTyped)
  
  ;Maj Liste chainée
  ResetList(Liste())
  While NextElement(Liste())
    If UCase(Left(TextTyped,LenTextTyped)) = UCase(Left(Liste()\Text,LenTextTyped))
      Liste()\Affiche = 1
    Else
      Liste()\Affiche = 0
    EndIf
  Wend
  
  ;Maj du ListView
  ClearGadgetItems(ACS\ID_List)
  
  
  ResetList(Liste())
  
  While NextElement(Liste())
    If Liste()\Affiche = 1
      AddGadgetItem(ACS\ID_List,-1,Liste()\Text)
    EndIf
  Wend
  
  LenTextSave = GetGadgetData(ACS\ID_Edit)
  If LenTextTyped <= LenTextSave
    SetGadgetData(#String, LenTextTyped)
  Else
    ;Selection dans le ListView
    ItemCount = CountGadgetItems(ACS\ID_List)
    
    For Item = 0 To ItemCount - 1
      ItemText.s = GetGadgetItemText(ACS\ID_List,Item)
      If  UCase(TextTyped) = UCase(Left(ItemText,LenTextTyped)) 
        SetGadgetState(ACS\ID_List,Item)
        Selection_Start = LenTextTyped
        Selection_End = Len(ItemText)
        
        
        SetGadgetText(#String,ItemText)
        SendMessage_(GadgetID(ACS\ID_Edit), #EM_SETSEL, Selection_Start, Selection_End)
   
        SetGadgetData(ACS\ID_Edit, LenTextTyped)
        Break
      EndIf
    Next
  EndIf
  Flag_EnCours = 0
EndProcedure
Procedure StringProc(hWnd,uMsg,wParam,lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_CHAR
      Debug wParam
  EndSelect
  
  ProcedureReturn result
EndProcedure
Procedure AC_StringGadgetProc(hWnd,uMsg,wParam,lParam)
 result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_COMMAND
      If (wParam >> 16 = #EN_CHANGE) And (lParam =GadgetID(ACS\ID_Edit)) 
        Debug "#EN_CHANGE"
        If Flag_EnCours = 0
          SearchInList()
        EndIf 
      EndIf   
  EndSelect
  
  ProcedureReturn result
EndProcedure
Procedure AC_StringGadget(Gadget,x,y,w,h,lh,text.s="")
  ACS\ID_Edit=Gadget
  If StringGadget(Gadget,x,y,w,h,text)
    
    ACS\ID_List=ListViewGadget(#PB_Any,x,y+GadgetHeight(Gadget),w,lh)
    If ACS\ID_List
      SetWindowCallback(@AC_StringGadgetProc())
      ;si je décommente la ligne suivante , CA BUG !!!!
      oldEditProc=SetWindowLong_(GadgetID(ACS\ID_Edit),GWL_WNDPROC,@StringProc)
    EndIf
  EndIf
EndProcedure
Procedure Open_WinMain()
  If OpenWindow(#WinMain,0,0,300,150,"StringGadgetEx",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
    AC_StringGadget(#String,50,10,200,20,100)
    
  EndIf
EndProcedure
;}
;- Main
;{
Open_WinMain()
    AddToList("AS250M150V3")
    AddToList("AS250L250V2")
    AddToList("AS250/100V2")
    AddToList("AS250M130-16V4")
    AddToList("AS250M160")
    AddToList("AB100V2")
    AddToList("AC100")
    AddToList("AS280L240-28V6")
    AddToList("AS280L240-28V5")
    AddToList("AS280L240-28V8")
    AddToList("AB100V3")
    AddToList("AS180L170")
    UpdateListView()
SetActiveGadget(ACS\ID_Edit)
SetGadgetState(ACS\ID_List,0)
;}
;- Event Loop
;{
Repeat
  Event = WaitWindowEvent()
  
  Select Event
     Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #WinMain
        CloseWindow(#WinMain)
        Break
      EndIf
  EndSelect
ForEver
;}
