slow reaction when clicking

Just starting out? Need help? Post your questions and find answers here.
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

slow reaction when clicking

Post by t57042 »

Following code is based on something old i found in the forum.

Code: Select all

; English forum: http://www.purebasic.fr/english/viewtopic.php?t=6203&highlight=
; Author: Freak (updated for PB4.00 by blbltheworm)
; Date: 21. May 2003
; OS: Windows
; Demo: Yes
Global a,b
#ListIcon = 1 
LoadFont(0, "tahoma", 12)

Procedure Callback(Window.l, Message.l, wParam.l, lParam.l) 
  result = #PB_ProcessPureBasicEvents 
  Select Message 
  
    Case #WM_NOTIFY        ; these events are send as notification messages 
      *pnmh.NMHDR = lParam  ; lParam points to a structure with more info 
      
      If *pnmh\hwndFrom = GadgetID(#ListIcon) ; see if it is the right gadget 
      
        Select *pnmh\code  ; code contains actual message 
        
         ; Case #LVN_COLUMNCLICK ; user clicked on the Header of a column 
          ;  *pnmv.NMLISTVIEW = lParam ; another info structure 
            
           ; Column.l = *pnmv\iSubItem ; clicked column 
            
            ;MessageRequester("Column Header Click","Clicked on Column "+Str(Column),0) 
            
          Case #NM_CLICK  ; user clicked in the ListView 
            *lpnmitem.NMITEMACTIVATE = lParam 
            
            Row.l = *lpnmitem\iItem 
            Column.l = *lpnmitem\iSubItem 
            
           Result$ = GetGadgetItemText(#ListIcon, row, Column)
           SetGadgetText(2,result$)  
           ;Debug "Row: "+ Str(Row+1)+  " Column: "+ Str(Column+1) + "  " + result$
           a=row:b=column 
            ; there is also 
            ; #NM_DBLCLK  - doublecklick 
            ; #NM_RCLICK  - right button 
            ; #NM_RDBLCLK - right doubleclick 
            ; they work the same as #NM_CLICK          
        EndSelect 
      
      EndIf 
  
  EndSelect 
  ProcedureReturn result 
  
EndProcedure 

OpenWindow(0,0,0,400,400, "Listicon test...",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
StringGadget(2,150,350,120,25,"")
SetGadgetFont(2, FontID(0))
ButtonGadget(3,300,340,40,40,"OK")
ListIconGadget(#ListIcon, 10, 10, 380, 300, "Column1", 140,#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
SetGadgetFont(#ListIcon, FontID(0))
    ; Fullrowselect must be set, because otherwiese only the first 
    ; column will be clickable 
    
    AddGadgetColumn(#ListIcon, 1, "Column2", 140) 
    AddGadgetColumn(#ListIcon, 2, "Column3", 140) 
    
    AddGadgetItem(#ListIcon, 0, "Richard"+Chr(10)+"Peeters"+Chr(10)+"man") 
    AddGadgetItem(#ListIcon, 1, "Mie"+Chr(10)+"Kockaerts"+Chr(10)+"vrouw") 
    AddGadgetItem(#ListIcon, 2, "Laurens"+Chr(10)+"Lemahieu"+Chr(10)+"jongen") 
    AddGadgetItem(#ListIcon, 3, "Klaartje"+Chr(10)+"Lasso"+Chr(10)+"meisje") 

    SetWindowCallback(@Callback()) 
  
    Repeat 
      EventID.l=WaitWindowEvent()
      
      Select EventID
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 3
             x$= GetGadgetText(2)
             SetGadgetItemText(#ListIcon,a,x$,b)
       EndSelect      
   EndSelect
   Until WaitWindowEvent() = #PB_Event_CloseWindow 

  
When clicking a field it appears in the stringgadget to edit. When clicking OK the result is set back in the listicongadget.
Sometimes one must click several times to get a reaction. Why?
Richard
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: slow reaction when clicking

Post by kenmo »

You should never use WaitWindowEvent() or WindowEvent() twice in a loop... some events will be caught by the first call, and some will be caught by the second, so you have a 50/50 chance of your #PB_Event_CloseWindow being caught where you're checking for it.

Code: Select all

Until EventID = #PB_Event_CloseWindow
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: slow reaction when clicking

Post by t57042 »

thanks KENMO.
Richard
Post Reply