PB 5.20 - Differences between callback and event loop
Posted: Wed Oct 23, 2013 4:36 pm
Until now I thought that the window callback is the option of choice when dealing with API events. What confuses though is that using the main event loop actually works better... For example if I want to receive the mouse move and click events on the string gadget I have to use the main event loop - this was pretty unexpected! Why is it like that? Is it a bug?
Example code:
Using PB 5.20 LTS (x86) on Windows 8.1 (x64).
Example code:
Code: Select all
Procedure WinCallback(WindowID, Message, WParam, LParam)
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_MOUSEMOVE
Debug "move (API, callback)"
Case #WM_LBUTTONDOWN
Debug "down (API, callback)"
Case #WM_LBUTTONUP
Debug "up (API, callback)"
EndSelect
ProcedureReturn Result
EndProcedure
OpenWindow(0, 0, 0, 200, 60, "WinAPI Events", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
StringGadget(1, 5, 5, 190, 20, "")
SetWindowCallback(@WinCallback(), 0)
Repeat
Select WaitWindowEvent()
Case #WM_MOUSEMOVE
Debug "move (API, event loop)"
Case #WM_LBUTTONDOWN
Debug "down (API, event loop)"
Case #WM_LBUTTONUP
Debug "up (API, event loop)"
Case #PB_Event_LeftClick ; By the way, a native #WM_MOUSEMOVE is missing in my opinion
Debug "up (PB, event loop)"
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver