Child Eventloop

Windows specific forum
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Child Eventloop

Post 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.
Apart from that Mrs Lincoln, how was the show?
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post 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.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post 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?
Apart from that Mrs Lincoln, how was the show?
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post 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?
Apart from that Mrs Lincoln, how was the show?
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post 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 

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post 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?
Apart from that Mrs Lincoln, how was the show?
Post Reply