Page 1 sur 1

plusieurs setwindowcallback dans une fenetre ?

Publié : mar. 25/avr./2006 15:27
par hichem
bonjour,

peut-on avoir plusieurs appels de setwindowcallback dans une fenetre ?

Publié : mar. 25/avr./2006 17:09
par lionel_om
A partir d'un CallBack, tu peux en rappeler un autre :wink:
Mais un SetWinCB() ne permet d'en avoir qu'un seul en mémoire : le précédent sera effacé

Lionel

Publié : mar. 25/avr./2006 17:12
par hichem
ok, merci. :D

Publié : mer. 26/avr./2006 0:42
par Flype
en fait il peut y en avoir plusieurs, d'une certaine façon.

par défaut beaucoup d'objets windows ont déjà une callback d'activée.
mais quand on fait un SetWindowCallback() çà efface/remplace l'ancienne.

mais il est possible de procéder autrement en passant par l'api windows.

Il faut récupérer le pointeur de la fonction callback déjà existante et créée par windows.
Ensuite on attache notre propre fonction callback ( comme on le fait avec SetWindowCallback() ).
Enfin, lorsque notre callback à fait son travail, juste avant un ProcedureReturn, on appelle la fonction callback par défaut de windows.
On peut ainsi chainer plusieurs callbacks. C'est possible.

Code : Tout sélectionner

Macro SetWindowCallback2(hWnd, UserCallBack)
  SetWindowLong_(hWnd, #GWL_WNDPROC, UserCallBack) 
EndMacro

Global defTreeCB.l
Global defWindowCB1.l
Global defWindowCB2.l
Global defWindowCB3.l

Procedure.l myTreeCallBack(hWnd.l, uMsg.l, wParam.l, lParam.l) 
   
   Select uMsg
      Case #WM_NOTIFY    : Debug "tree: notify"
      Case #WM_MOUSEMOVE : Debug "tree: mousemove"
      Case #WM_LBUTTONUP : Debug "tree: lbuttonup"
   EndSelect 
   
   ProcedureReturn CallWindowProc_(defTreeCB, hWnd, uMsg, wParam, lParam) 
   
EndProcedure 
Procedure.l myWindowCallBack1(hWnd.l, uMsg.l, wParam.l, lParam.l) 
   
   Select uMsg
      Case #WM_CLOSE :      Debug "window1: close"
      Case #WM_COMMAND :    Debug "window1: command"
      Case #WM_MOUSEMOVE  : Debug "window1: mousemove"
   EndSelect 
   
   ProcedureReturn CallWindowProc_(defWindowCB1, hWnd, uMsg, wParam, lParam) 
   
EndProcedure 
Procedure.l myWindowCallBack2(hWnd.l, uMsg.l, wParam.l, lParam.l) 
   
   Select uMsg
      Case #WM_CLOSE :      Debug "window2: close"
      Case #WM_COMMAND :    Debug "window2: command"
      Case #WM_MOUSEMOVE  : Debug "window2: mousemove"
   EndSelect 
   
   ProcedureReturn CallWindowProc_(defWindowCB2, hWnd, uMsg, wParam, lParam) 
   
EndProcedure 
Procedure.l myWindowCallBack3(hWnd.l, uMsg.l, wParam.l, lParam.l) 
   
   Select uMsg
      Case #WM_CLOSE :      Debug "window3: close"
      Case #WM_COMMAND :    Debug "window3: command"
      Case #WM_MOUSEMOVE  : Debug "window3: mousemove"
   EndSelect 
   
   ProcedureReturn CallWindowProc_(defWindowCB3, hWnd, uMsg, wParam, lParam) 
   
EndProcedure 

If OpenWindow(0, 0, 0, 320, 240, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
  
  If CreateGadgetList(WindowID(0)) 
    
    TreeGadget(0, 5, 5, 310, 100) 
    AddGadgetItem(0, 0, "test")
    
    defTreeCB    = SetWindowCallback2(GadgetID(0), @myTreeCallBack())
    defWindowCB1 = SetWindowCallback2(WindowID(0), @myWindowCallBack1())
    defWindowCB2 = SetWindowCallback2(WindowID(0), @myWindowCallBack2())
    defWindowCB3 = SetWindowCallback2(WindowID(0), @myWindowCallBack3())
    
  EndIf
  
  Repeat 
    
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  
EndIf

End
Sinon il y a aussi SetWindowsHookEx_()/CallNextHookEx_() mais c'est plus délicat et uniquement exécutable depuis une dll.

Publié : mer. 26/avr./2006 0:47
par hichem
merci flype, j'avais déjâ essayé d'utiliser les macros, mais je me suis embrouillé. :?
en tout cas avec ton code c'est plus clair, t'es un chef :D

Publié : mer. 26/avr./2006 1:12
par Flype
sinon tu as aussi dans le même esprit cette fonction qui appelle la callback windows par défaut.

DefWindowProc_(hWnd, uMsg, wParam, lParam)

çà permet essentiellement de ne pas avoir à stocker la callback précédente dans une globale.

Publié : mer. 26/avr./2006 1:20
par hichem
oui, je la connais mais je ne peux pas l'utiliser dans mon cas...
sinon ton code me servira dans le mien. :wink:

Publié : sam. 18/nov./2006 8:58
par Kwai chang caine
Bonjour à tous

Et peut on arreter une callback ????

Peut on ensuite la redémarrer ????

Merci
Bonne journée