SetWindowCallback()

Syntax

SetWindowCallback(@ProcedureName() [, #Window])
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. It must have 4 parameters. Here is a sample code to use a callback correctly:
  Procedure MyWindowCallback(WindowID, Message, WParam, LParam)
    Result = #PB_ProcessPureBasicEvents
    ;
    ; you code here
    ;
    ProcedureReturn Result
  EndProcedure
Here you see a working example checking some window parameters (using Windows API constants):
  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())    ; activate the callback
    
    Repeat 
      Select WaitWindowEvent() 
        Case #PB_Event_CloseWindow 
          End 
      EndSelect 
    ForEver 
    
  EndIf 
#Window (optional) A specific window to associate the callback to. If omitted the callback will be called for any window.

Return value

None.

Supported OS

Windows

<- SetActiveWindow() - Window Index - SetWindowColor() ->