WaitWindowEvent()
Syntax
Event = WaitWindowEvent([Timeout])Description
Wait until an event occurs. It's the same function as WindowEvent() but locks the program execution, which is very important in a multitasking environment.
Parameters
Timeout (optional) The timeout (in milliseconds) which causes the function to return if no events are occurring. If no timeout is specified, it will wait infinitely until an event occurs.
Return value
Return the event which occurred, see WindowEvent() for more information.
Remarks
An application should always use this function instead of WindowEvent() if possible, as it doesn't takes an CPU time while waiting for an event.
The window event loop should not be processed in a thread, as there is some limitation on OS X and Linux. A debugger error will be raised.
WaitWindowEvent() can only be called once per event loop, because else events will be "lost" (every event can only be processed once and isn't available anymore for a second time after first processing).
Example
If OpenWindow(0, 0, 0, 230, 90, "Event handling example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) ButtonGadget (1, 10, 10, 200, 20, "Click me") CheckBoxGadget(2, 10, 40, 200, 20, "Check me") If CreateMenu(0, WindowID(0)) MenuTitle("Menu") MenuItem(1, "Item 1") MenuItem(2, "Item 2") MenuItem(3, "Item 3") EndIf Repeat Event = WaitWindowEvent() Select Event Case #PB_Event_Gadget Select EventGadget() Case 1 : Debug "Button 1 clicked!" Case 2 : Debug "Button 2 clicked!" EndSelect Case #PB_Event_Menu Select EventMenu() Case 1 : Debug "Menu item 1 clicked!" Case 2 : Debug "Menu item 2 clicked!" Case 3 : Debug "Menu item 3 clicked!" EndSelect EndSelect Until Event = #PB_Event_CloseWindow EndIf
Supported OS
All