SetWindowCallback()
Syntax
SetWindowCallback(@ProcedureName() [, #Window [, Mode]])Description
For experienced programmers only. It's only supported on Microsoft Windows.
Normal events should be handled with the regular WaitWindowEvent() or WindowEvent().
This function associates a callback to handle the events of the all open windows. All the events are caught by this callback and can be processed here. To set a callback for a specific window only, the optional parameter can be used to pass the PB window number.
To remove/disable a previous set callback just call SetWindowCallback(0 [, #Window]).
Warning: this way is lowlevel. Incorrect handling of the messages in the callback can interfere with PB's own message processing.
Parameters
@ProcedureName() The callback procedure to use. If a previous callback was set it will be replaced. The callback must have 4 parameters. If the event isn't processed, the result must be set to #PB_ProcessPureBasicEvents so the event will be properly handled by PureBasic. Here is a sample code to use a callback correctly: Procedure MyWindowCallback(WindowID, Message, WParam, LParam) Result = #PB_ProcessPureBasicEvents ; ; your code here ; ProcedureReturn Result EndProcedure#Window (optional) A specific window to associate the callback to. If omitted the callback will be called for any window. Mode (optional) The callback mode, can be one of the following value: #PB_Window_ProcessChildEvents: the child gadgets events (mostly #WM_NOTIFY) will be sent to the main window. Doesn't work for all gadgets (default). #PB_Window_NoChildEvents : the child gadgets events won't be sent to the main window (WinAPI default behavior).
Return value
None.
Example
Procedure WinCallback(hWnd, uMsg, WParam, LParam) ; Windows fills the parameter automatically, which we will use in the callback... If uMsg = #WM_SIZE Select WParam Case #SIZE_MINIMIZED Debug "Window was minimized" Case #SIZE_RESTORED Debug "Window was restored" Case #SIZE_MAXIMIZED Debug "Window was maximized" EndSelect EndIf ProcedureReturn #PB_ProcessPureBasicEvents EndProcedure If OpenWindow(0, 0, 0, 200, 100, "Messages", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget) SetWindowCallback(@WinCallback(), 0) ; set the callback Repeat Select WaitWindowEvent() Case #PB_Event_CloseWindow End EndSelect ForEver EndIf
Supported OS
Windows