WidgetGetParentWindow

Syntax

Window = WidgetGetParentWindow(Widget)

Description

Retrieves the handle of the ProGUI window that ultimately contains the specified widget.

Parameters

Widget
The handle of the ProGUI widget whose parent window is to be retrieved.

Return Value

Returns the handle to the parent ProGUI window object if successful, or #Null if the widget handle is invalid or not associated with a window (which shouldn't normally happen for a valid widget).

Remarks

This function traverses the layout hierarchy upwards from the widget until it finds the root window container. It's useful when a widget needs to interact with or get information from the window it belongs to.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Event handler that uses the parent window
Procedure WidgetClickHandler(Widget, EventType, *EventData, *UserData)
  If EventType = #PG_Event_MouseLeftButtonDown
    ParentWindow = WidgetGetParentWindow(Widget)
    If ParentWindow
      OldTitle$ = WindowGetTitle(ParentWindow)
      WindowSetTitle(ParentWindow, OldTitle$ + " Clicked!")
      Debug "Changed parent window title."
    EndIf
  EndIf
EndProcedure

MyWindow = CreateWindow(0, 0, 300, 200, "Parent Window")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetPadding(RootLayout, 10)

If MyWindow
  MyWidget = CreateWidget(0, 0, 100, 30)
  WidgetSetClass(MyWidget, "button")
  WidgetSetMargin(MyWidget, 5)
  AddEventHandler(MyWidget, #PG_Event_MouseLeftButtonDown, @WidgetClickHandler())

  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

StopProGUI()

See Also

CreateWidget, CreateWindow, WindowGetLayout

Supported OS

Windows, Linux