Page 1 of 1

Child Eventloop

Posted: Wed Aug 16, 2006 5:45 pm
by Konne
Hi does anybody know if I can add an own eventloop to a child window.
I mean like a Containergadget with it's own Eventllop.
Could someone please tell me if something like that is possible or not.

Posted: Wed Aug 16, 2006 8:45 pm
by localmotion34
use a subclass procedure catching the #wm_command or some other message. i have written tons of code on how to subclass, just find my examples.

compare lparam and wparam to your gadgetid's, compare x and y locations of a mouse, detect and process left and right button clicks.
WM_COMMAND

wNotifyCode = HIWORD(wParam); // notification code
wID = LOWORD(wParam); // item, control, or accelerator identifier
hwndCtl = (HWND) lParam; // handle of control


The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.

Parameters

wNotifyCode

Value of the high-order word of wParam. Specifies the notification code if the message is from a control. If the message is from an accelerator, this parameter is 1. If the message is from a menu, this parameter is 0.

wID

Value of the low-order word of wParam. Specifies the identifier of the menu item, control, or accelerator.

hwndCtl

Value of lParam. Identifies the control sending the message if the message is from a control. Otherwise, this parameter is NULL.

Posted: Wed Aug 16, 2006 9:36 pm
by Fluid Byte
Yeah, sub-classing is the way. Here's an example:

Code: Select all

Global lpPrevWndFunc.l

Procedure WndChildProc(hwnd.l,uMsg.l,wParam.l,lParam.l)
	Select uMsg
		Case #WM_LBUTTONDOWN
		Debug "Snatched window event!"
	EndSelect
	
	ProcedureReturn CallWindowProc_(lpPrevWndFunc,hwnd,uMsg,wParam,lParam)
EndProcedure

OpenWindow(0,0,0,320,240,"untitled",#WS_OVERLAPPEDWINDOW | 1)

CreateGadgetList(WindowID(0))

*hwndCont = ContainerGadget(0,5,5,310,230,2)

lpPrevWndFunc = SetWindowLong_(*hwndCont,#GWL_WNDPROC,@WndChildProc())

While WaitWindowEvent() ! 16 : Wend

Posted: Wed Aug 16, 2006 11:10 pm
by Konne
Is subclassinbg also Possible if I have a thread? Means I create the Window in the Mainllop add a Subclasses from a Thread. Is it still working then?

Posted: Wed Aug 16, 2006 11:44 pm
by Flype
as fred said before (do not remember which post),
events must be processed in the same thread of the one in which we have created the window. it's a windows feature.
but if someone can confirm...

Posted: Wed Aug 16, 2006 11:53 pm
by Konne
And would it work if I would create a containergadget in the same thread but created by a dll with this kind of Eventhandling?

Posted: Thu Aug 17, 2006 12:08 am
by freak
It will not work because PB events are always posted up to the main window.
Your eventloop for the container will not receive any events.

Posted: Thu Aug 17, 2006 4:05 pm
by localmotion34
freak wrote:It will not work because PB events are always posted up to the main window.
Your eventloop for the container will not receive any events.
Yes it does work, just with subclassing. It's called DOUBLE SUBCLASSING.

and heres the example:

Code: Select all


Global oldproc.l

Procedure notpossibleproc(hwnd,msg,wParam,lParam)
  Select msg
    Case #WM_COMMAND
      Debug "The control I got the message from is" + Space(1) +Str(lParam)
      Debug "the gadgetid of button 1 is" + Space(1) + Str(GadgetID(1))
      Debug "I just Punk'd the eventloop" 
      ProcedureReturn 0 ;don't let the eventloop get this message
      ;alternatively, you can let this message pass to the eventloop
  EndSelect 
  ProcedureReturn DefWindowProc_(hwnd,msg,wParam,lParam)
EndProcedure 
    
    
Procedure letitpassproc(hwnd,msg,wParam,lParam)
  Select msg
    ;trap anyother messages you want here, EXCEPT the #wm_command
    
  EndSelect 
  ProcedureReturn CallWindowProc_(oldproc,hwnd,msg,wParam,lParam)
EndProcedure 
    
    
    
    


If OpenWindow(0, 869, 108, 237, 471, "Robbing and Stealing", #PB_Window_SystemMenu | #PB_Window_TitleBar  )
    
    If CreateGadgetList(WindowID(0))
      ContainerGadget(200,20,20,150,90,#PB_Container_Raised)
      oldproc=GetWindowLong_(GadgetID(200), #GWL_WNDPROC)
      ButtonGadget(1, 10, 15, 80, 24, "Button 1")  
      oldproc=SetWindowLong_(GadgetID(200),#GWL_WNDPROC,@notpossibleproc())
      CloseGadgetList()
      CheckBoxGadget(2,10,150,180,20,"Allow Container Events to Pass")
    EndIf 
  EndIf


  Repeat
     
    
  Event = WaitWindowEvent()
  Select Event
    Case  #PB_Event_Menu
      Select EventMenu()
        
      EndSelect
    Case  #PB_Event_Gadget
      Select EventGadget()
        Case 1
          Debug "PB event loop got the message!!!"
          Debug "Localmotion34 Rocks!!!"
        Case 2
          State=GetGadgetState(2)
          Select State
            Case 0
              SetWindowLong_(GadgetID(200),#GWL_WNDPROC,@notpossibleproc()) 
            Case 1
              SetWindowLong_(GadgetID(200),#GWL_WNDPROC,@letitpassproc())
          EndSelect
      EndSelect
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow
  
End 


Posted: Thu Aug 17, 2006 11:07 pm
by Konne
localmotion34 wrote: Yes it does work, just with subclassing. It's called DOUBLE SUBCLASSING.
So if I want to create some Gadgets from a dll on the Window what do I have to do so that Eventhandling works?