threads and callback

Everything else that doesn't fall into one of the other PB categories.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

threads and callback

Post by localmotion34 »

ok, so you create a window in the main program and setwindowcallback() for that window. now lets say you are creating a custom gadget in a NEW THREAD so that the custom gadget can have its own event loop. can you setwindowcallback() for the custom gadget WITHOUT affecting the original main program and callback.

ex:

procedure mygadget()
;create custom gadget here
setwindowcallback @ threadcallback()
repeat
;;separate event loop
until whenever
endprocedure

what i want to do is be able to create a custom gadget i am working on (secret for now), and be able to have its own event loop and callback outside of the main program. i want to make a PB user library out of this gadget, and have the programmer be able to create the gadget with its own callback and NOT affect his main window callback.

openwindow(#window1,,,,)
setwindowcallback(@maincallback)

if createthread(thread,mygadget())
endif

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Sorry, but the way you want to do it is wrong 8O
SetWindowCallback can only be used ONCE :!:
What you need to do is called SubClassing.

After creating the gadget you have to subclass it with:
old_proc = SetWindowLong_(MyControlhWnd, #GWL_WNDPROC, @MyControlWndProc())

And than you create a callback procedure:
MyControlWndProc(hWnd,Message,wParam,lParam)

and fill it with your code.
Don't forget to set the proper ProcedureReturn:

Code: Select all

Select Message 
  Case #WM_COMMAND 
    ; your code
  Default
    ProcedureReturn CallWindowProc_(old_proc, hWnd, Message, wParam, lParam)
EndProcedure
I don't have more time right now to show you the details, but search this forum under subclassing... :wink:
Post Reply