collectordave wrote:
I think I posted earlier, can these non official events be prevented from reaching the message loop in my program? Or is there a way of finding whether it is an official PB event so it can be discarded in my message loop before an attempt to find on which window the event occurred?
You simply process the PureBasic events and leave the rest to fend for themselves.
Here's an extensive and noisy example to show what is handled by PureBasic's message loop. I made the example to use as a reference for myself and I hope it is useful in answering your question as well. It is possible I may have made overlooked something but it was created with reference to the documentation. It makes an effort in the source code to show how various events are generated and what information is available to handle them.
In general everything is handled with Select/Case statements. At the very end is a 'default' case. The events that end up there are ones created using PostEvent(), the 'no event' (i.e. #Null), and events that aren't handled by PureBasic. So after you filter out any PostEvent() messages the rest you can ignore or properly handle by using SetWindowCallback().
Incidentally, if the WindowCallback is used, it would handle the specific OS messages and then pass control to the PureBasic message loop to process the rest. IMHO this means that the PureBasic message loop is not the proper place to handle OS event messages (at least not in the current version of PureBasic) if you are going to handle them at all.
Code:
;Author: Demivec
;Date: 10/20/2015
;Written for: PureBasic v5.40 LTS
;General example of a classic event message loop.
;
;Using BindEvent(), BindGadgetEvent(), BindMenuEvent() are powerful alternatives to
;processing events with through the event loop. There is also the use of SetWindowCallback()
;for handling all events generated by the OS that may or may not be handled through
;PureBasic's own message handling functions.
;This code only includes a single window. You would typically place your windows, gadgets,
;and so forth here before the event loop.
OpenWindow(0, 0, 0, 600, 220, "MainWindow", #PB_Window_SystemMenu)
Define event, quit
Repeat
Repeat
event = WindowEvent() ;or WaitWindowEvent()
Select event
Case #PB_Event_Menu
; Select EventMenu()
; Case 0 ;Customize to handle specific menu numbers (or toolbar or keyboard shortcuts)
; Default
Debug "Menu: " + EventMenu() + ", window: " + EventWindow()
; EndSelect
Case #PB_Event_Gadget
; Select EventGadget()
; Case 0 ;Customize to handle specific gadget numbers.
; Default
;Events are neither reported nor handled by every gadget type,
;refer to documentation for specific gadget type for further info.
;The CanvasGadget(), WebGadget() and OpenGLGadget() each also support a special set of events.
Debug "Gadget: " + EventGadget() + ", type: " + EventType() + ", window: " + EventWindow()
; EndSelect
Case #PB_Event_SysTray
Select EventGadget()
Case 0 ;Customize to handle specific system tray icon numbers.
Default
Debug "SysTrayIcon: " + EventGadget() + ", type: " + EventType()
EndSelect
Case #PB_Event_Timer
; Select EventTimer()
; Case 0 ;Customize to handle specific system tray icon numbers.
; Default
Debug "Timer: " + EventTimer() + ", window: " + EventWindow()
; EndSelect
Case #PB_Event_WindowDrop
; Select EventWindow()
; Case 0 ;Customize to handle specific windows as drop targets.
; Default
Debug "Drop onto Window : " + EventWindow() + ", type: " + EventDropType() + ", action: " + EventDropAction()
;Further functions to handle the event may include:
; EventDropText(), EventDropImage(), EventDropFiles(), EventDropPrivate(),
; EventDropBuffer(), EventDropSize(), EventDropX(), EventDropY()
; EndSelect
Case #PB_Event_GadgetDrop
; Select EventGadget()
; Case 0 ;Customize to handle specific gadgets as drop targets.
; Default
Debug "Drop onto Gadget : " + EventGadget() + ", type: " + EventDropType() + ", action: " + EventDropAction() + ", window: " + EventWindow()
;Further functions to handle the event may include:
; EventDropText(), EventDropImage(), EventDropFiles(), EventDropPrivate(),
; EventDropBuffer(), EventDropSize(), EventDropX(), EventDropY()
; EndSelect
Case #PB_Event_CloseWindow
Debug "CloseWindow: " + EventWindow() ;Custom handling for specific windows is possible.
quit = 1
Case #PB_Event_Repaint
Debug "Repaint: " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_SizeWindow
Debug "SizeWindow: " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_MoveWindow
Debug "MoveWindow: " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_MinimizeWindow
Debug "MinimizeWindow : " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_MaximizeWindow
Debug "MaximizeWindow: " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_RestoreWindow ;Custom handling for specific windows is possible.
Debug "RestoreWindow: " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_ActivateWindow
Debug "ActivateWindow: " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_DeactivateWindow
Debug "DeactivateWindow: " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_RightClick
Debug "RightClick: " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_LeftClick
Debug "LeftClick: " + EventWindow() ;Custom handling for specific windows is possible.
Case #PB_Event_LeftDoubleClick
Debug "LeftDoubleClick: " + EventWindow() ;Custom handling for specific windows is possible.
Default
If event <> 0
;This includes events posted with PostEvent() and all 'OS events' that are not handled by the PureBasic message loop.
;If using custom PostEvent() compare the event to their numbers for proper handling, further details may then
; be obtained with: EventWindow(), EventGadget(), EventType(), EventData()
;IF not using custom PostEvent(), IMHO OS events should be handled with a window callback procedure.
;Debug "Unhandled Event: " + event
EndIf
EndSelect
Until event = 0 Or quit = 1
Delay(10) ;Delay() frees the CPU for the multitasking
Until quit = 1
There has been postings on the meaning of events generated where the window, or gadget event is '0' (a non-documented value). For gadget events it means the gadget has only one event, such as a clicking on a check-box. For windows any events for window -1 should be ignored (as they are not valid events).
@Edit: Changed code to no longer require debugger on to run. Running it without the debugger will keep it from displaying any information but it will operate correctly.