DesktopApplication.Window

From Xojo Documentation

Revision as of 18:12, 23 July 2021 by Gperlman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Method

DesktopApplication.Window()

New in 2021r3

Supported for all project types and targets.

Returns a reference to an open window.

Usage

result = Window(WindowNumber)

Part Type Description
result DesktopWindow 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 Opening event, the window list includes that window, but during a window's Closing 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.

fa-exclamation-circle-32.png
This function returns only DesktopWindows. Windows of the original Window class will not be returned.

Sample Code

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

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 (DesktopWindow.Type=DesktopWindow.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

DesktopApplication.WindowCount method; DesktopWindow class.