Window Method

From Xojo Documentation


Returns a reference to an open window.


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.


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 = WindowCount - 1 DownTo 0
Dim w As Window = Window(i)
If w <> Nil Then
End If

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

Dim frontmostDocumentWindow As Window
Dim lastOffset As Integer = WindowCount - 1
For i As Integer = 0 To lastOffset
Dim w As Window = Window(i)
If (w <> Nil) And (w.Frame = 0) And w.Visible Then
frontmostDocumentWindow = w
End If
Return frontmostDocumentWindow

See Also

WindowCount function; Window class.