Syntax
PreviousCaptureWindow = WindowSetMouseCapture(Window)
Description
Captures the mouse input for the specified window. Once captured, all subsequent mouse events, regardless of the cursor's position on the screen, are sent to this window until capture is released using WindowReleaseMouseCapture() or WidgetReleaseMouseCapture().
Parameters
Window
The handle of the ProGUI window that should capture the mouse.
Return Value
Returns the handle of the ProGUI window that previously held the mouse capture, if any. Returns
#Null if no window previously held the capture or if the input `Window` handle is invalid.
Remarks
Mouse capture is typically used during drag-and-drop operations or when resizing elements to ensure that mouse movement and button release events are received even if the cursor moves outside the initiating window or widget. Remember to release the capture when the operation is complete. Only one window or widget can capture the mouse at a time system-wide.
Example
IncludeFile "ProGUI_PB.pbi"
Global IsDragging
Procedure MouseHandler(Window, EventType, *EventData.PG_EventMouse)
Select EventType
Case #PG_Event_MouseLeftButtonDown
Debug "Mouse Down - Capturing Mouse"
WindowSetMouseCapture(Window)
IsDragging = #True
Case #PG_Event_MouseMove
If IsDragging
Debug "Dragging... X: " + StrD(*EventData\x) + ", Y: " + StrD(*EventData\y)
; Add drag logic here
EndIf
Case #PG_Event_MouseLeftButtonUp
If IsDragging
Debug "Mouse Up - Releasing Capture"
WindowReleaseMouseCapture()
IsDragging = #False
EndIf
EndSelect
EndProcedure
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Mouse Capture Example")
If MyWindow
AddEventHandler(MyWindow, #PG_Event_MouseLeftButtonDown, @MouseHandler())
AddEventHandler(MyWindow, #PG_Event_MouseLeftButtonUp, @MouseHandler())
AddEventHandler(MyWindow, #PG_Event_MouseMove, @MouseHandler())
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WindowReleaseMouseCapture, WidgetSetMouseCapture, WidgetReleaseMouseCapture
Supported OS
Windows, Linux