Application.Window

From Xojo Documentation

Method

Application.Window()

New in 2019r2

Supported for all project types and targets.

Returns a reference to an open window.

Usage

result = Window(WindowNumber)

Part Type Description
result Window A reference to the window whose number was passed.
WindowNumber Integer The number of the window you want a reference to. Window 0 is the frontmost window.

Notes

The Window function returns a reference to the window number passed. The window list contains all the windows that have been created. Window zero is the frontmost window. Floating windows are always in front of document windows. For example, to get the frontmost document window when you also have Floating windows, you must also check each window's Frame property. In evaluating the order of windows in the list from front to back, keep in mind that a window may not have its Visible property set to True. If this may be the case, check the Visible property of a window while identifying the frontmost visible window. If you don't, the code may identify the frontmost window as a window that is not Visible.

This function can be used in conjunction with the WindowCount function to loop through the open windows. Note that during a window's Open event, the window list includes that window, but during a window's Close event, the window list does not include that window.

If you pass in a window number that does not exist ( a value < 0 or >= WindowCount) then this function returns Nil.

Sample Code

This code places the titles of all open windows into a ListBox:

For i As Integer = App.WindowCount - 1 DownTo 0
Var w As Window = App.Window(i)
If w <> Nil Then
ListBox1.AddRow(w.Title)
End If
Next

This code gets the frontmost Document window. It considers only Document windows (Window.Type=Window.Types.Document) and takes into account the possibility that a window might not be visible:

Var frontmostDocumentWindow As Window
Var lastOffset As Integer = App.WindowCount - 1
For i As Integer = 0 To lastOffset
Var w As Window = System.Window(i)
If (w <> Nil) And (w.Type = Window.Types.Document) And w.Visible Then
frontmostDocumentWindow = w
Exit
End If
Next
Return frontmostDocumentWindow

See Also

Application.WindowCount method; Window class.