#WM_LBUTTONDOWN event is not 'filterd correctly' ?

Just starting out? Need help? Post your questions and find answers here.
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

#WM_LBUTTONDOWN event is not 'filterd correctly' ?

Post by Joris »

Hi,

I have a setup with multiple windows (like the code part shows).
Inside Window_0_Events(EventID) I need to use #WM_LBUTTONDOWN.
That works fine, but the first #WM_LBUTTONDOWN on an other window, is also recieved by Window_0.
Why or how does that happen and how can I prevent that 'bad split of events' ?

Thanks

Code: Select all

Repeat 
    EventID = WaitWindowEvent() 
    If EventID 
      Select EventWindow() 
        Case Window_0
          Window_0_Events(EventID) 
        Case Window_1
          Window_1_Events(EventID)
        Case Window_2
          Window_2_Events(EventID)
        Case Window_3
          Window_3_Events(EventID)
     EndSelect 
    EndIf 
  ForEver 
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
STARGÅTE
Addict
Addict
Posts: 2087
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: #WM_LBUTTONDOWN event is not 'filterd correctly' ?

Post by STARGÅTE »

The #WM_LBUTTONDOWN event is no PB event, probably therefore the result of EventWindow() is invalid!
The PB event #PB_Event_ActivateWindow (13104) comes after #WM_LBUTTONDOWN, therefore EventWindow() was not set in the first left button down event.

You can try SetWindowCallback() to bind the windows event directly:

Code: Select all

OpenWindow(1, 20, 120, 500, 500, "")
OpenWindow(2, 550, 120, 500, 500, "")

Procedure WinCallback(WindowID, Message, wParam, lParam)
	If Message = #WM_LBUTTONDOWN
		If WindowID(1) = WindowID
			Debug "Window 1"
		EndIf
		If WindowID(2) = WindowID
			Debug "Window 2"
		EndIf
	EndIf
	ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

SetWindowCallback(@WinCallback())

Repeat
	If WaitWindowEvent() = #PB_Event_CloseWindow
		End
	EndIf
ForEver
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: #WM_LBUTTONDOWN event is not 'filterd correctly' ?

Post by RASHAD »

The next snippet not perfect like SetWindowCallback()
It will respond after Left up
But in case you don't want to use SetWindowCallback()

Code: Select all

Procedure win1()
 Debug "1"
EndProcedure

Procedure win2()
Debug "2"
EndProcedure

flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,400,300,"Test1",Flags)
OpenWindow(1,0,0,400,300,"Test2",Flags)


BindEvent(#PB_Event_LeftClick,@win1(),0)
BindEvent(#PB_Event_LeftClick,@win2(),1)
Repeat           
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect
Until Quit = 1
Egypt my love
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: #WM_LBUTTONDOWN event is not 'filterd correctly' ?

Post by Joris »

Thanks guys.

Both your sollutions woks, but created other problems, yet it gave me the simple idea
of using what I'm doing after the #WM_LBUTTONDOWN : x=WindowMouseX(Window_0).
If x>0 it is the correct #WM_LBUTTONDOWN, so thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply