WindowReleaseMouseCapture

Syntax

Success = WindowReleaseMouseCapture()

Description

Releases mouse capture that was previously set by either WindowSetMouseCapture() or WidgetSetMouseCapture(). After this call, mouse events are no longer exclusively directed to the previously capturing window or widget, and normal mouse routing resumes.

Parameters

This command takes no parameters.

Return Value

Returns #True if mouse capture was active and successfully released. Returns #False if no mouse capture was currently active.

Remarks

It's essential to call this function when a mouse operation that required capture (like dragging) is completed (e.g., on a mouse button up event) to restore normal mouse behavior for the application and the system. On Windows, this internally calls the `ReleaseCapture()` API function.

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

WindowSetMouseCapture, WidgetSetMouseCapture, WidgetReleaseMouseCapture

Supported OS

Windows, Linux