The class DesktopWindow (gb. desktop) represents a top-level window. You can create objects of the class in this way:
Dim hDesktopWindow As DesktopWindow hDesktopWindow = New DesktopWindow(Window As Integer)
However, it is recommended that you do not create DesktopWindow objects directly, but rather access a top-level window using the Desktop. Windows property. Two examples should prove this:
Private Function Desktop_FindWindow(sPattern As String) As DesktopWindow[] Dim dtWindow As DesktopWindow Dim dtWList As New DesktopWindow[] Desktop.Windows.Refresh() ' Desktop.Windows presents a list of all top-level windows as a virtual object. For Each dtWindow In Desktop.Windows If dtWindow.Name Like sPattern Then dtWList.Add(dtWindow) Endif ' dtWindow.Name Like sPattern ? Next ' dtWindow Return dtWList End ' Function Desktop_FindWindow(..)
Public Sub btnExample_Click() Dim dtWindow As DesktopWindow Desktop.Windows.Refresh() For Each dtWindow In Desktop.Windows If dtWindow.SkipTaskbar = False Then Print "Window.Name = \"" & dtWindow.Name & "\" , X = " & dtWindow.X & " , Y = " & dtWindow.Y Endif ' dtWindow.SkipTaskbar = False Next ' dtWindow End ' btnExample_Click()
The last section of the source code, for example, provides the following output in the console (IDE):
Window.Name = "Gambas Documentation - Desktop.Windows[] (gb.desktop) - Mozilla Firefox" , X = 0 , Y = 24 Window.Name = "19.7.4.odt - LibreOffice Writer" , X = 0 , Y = 24 Window.Name = "19.7_Desktop" , X = 0 , Y = 24 Window.Name = "k19:start [GAMBAS-BUCH 3.5.1] - Mozilla Firefox" , X = 0 , Y = 24 Window.Name = "propertytest 0.0.15 - Gambas 3" , X = 0 , Y = 24 Window.Name = "PropertyTest" , X = 304 , Y = 213
Selected properties and methods of the class are listed and described in the following two tables:
Property | Type | Description |
---|---|---|
Desktop | Integer | Returns the number (0.. k) of the virtual desktop where the window is visible or sets the number of the desktop where the window is displayed. |
Icon | Image | Returns the window icon. |
Id | Integer | Returns the X11 window identifier. |
FullScreen | Boolean | Specifies whether the window is in full screen state or sets the full screen state. |
Height | Integer | Specifies the height of the window (pixels). |
Width | Integer | Specifies the width of the window (pixels). |
Maximized | Boolean | Returns True if the window is maximized or maximizes the window. |
Minimized | Boolean | Returns True if the window is minimized or minimizes the window. |
Name | String | Specifies the name of the window. This is the window title of the application that owns this window. |
Sticky | Boolean | Returns True if the window is displayed on all desktops or displays the window on all desktops. |
Visible | String | Returns the visible name of the window. This is the window title as displayed by the window manager. |
X | Integer | Returns the x-coordinate of the window. |
Y | Integer | Returns the y-coordinate of the window. |
Table 15.4.1.1: Overview of selected properties of the DesktopWindow class
Method | Description |
---|---|
Close() | Closes the window. |
GetIcon(Width As Integer, Height As Integer) As Image | Returns the window icon with the specified size. |
Move(X As Integer, Y As Integer[, Width As Integer, Height As Integer] | The window is moved to the position P(x,y) and optionally resized (width) and height. |
Refresh() | Restores a DesktopWindow object by querying the geometry of the window. This happens automatically with a DesktopWatcher.WindowGeometry event. |
Resize(Width As Integer, Height As Integer) | The window is only resized in size (height and width). |
Table 15.4.2.1: Selected methods of the DesktopWindow class
For more information on the DesktopWindow class (gb. desktop), see chapter 15, which demonstrates the practical interaction of the two classes in a project in addition to the description of the DesktopWatcher class.
Die Klasse DesktopWindow (gb.desktop) repräsentiert ein Top-Level-Fenster. Objekte der Klasse können Sie so anlegen:
Dim hDesktopWindow As DesktopWindow hDesktopWindow = New DesktopWindow(Window As Integer)
Es wird aber empfohlen, DesktopWindow-Objekte nicht direkt anzulegen, sondern Zugriff auf ein Top-Level-Fenster über die Eigenschaft Desktop.Windows zu bekommen. Zwei Beispiele sollen das belegen:
Private Function Desktop_FindWindow(sPattern As String) As DesktopWindow[] Dim dtWindow As DesktopWindow Dim dtWList As New DesktopWindow[] Desktop.Windows.Refresh() ' Desktop.Windows präsentiert als virtuelles Objekt eine Liste aller Top-Level-Fenster For Each dtWindow In Desktop.Windows If dtWindow.Name Like sPattern Then dtWList.Add(dtWindow) Endif ' dtWindow.Name Like sPattern ? Next ' dtWindow Return dtWList End ' Function Desktop_FindWindow(..)
Public Sub btnExample_Click() Dim dtWindow As DesktopWindow Desktop.Windows.Refresh() For Each dtWindow In Desktop.Windows If dtWindow.SkipTaskbar = False Then Print "Window.Name = \"" & dtWindow.Name & "\" , X = " & dtWindow.X & " , Y = " & dtWindow.Y Endif ' dtWindow.SkipTaskbar = False Next ' dtWindow End ' btnExample_Click()
Der letzte Quelltext-Ausschnitt liefert beispielsweise folgende Ausgabe in der Konsole (IDE):
Window.Name = "Gambas Documentation - Desktop.Windows[] (gb.desktop) - Mozilla Firefox" , X = 0 , Y = 24 Window.Name = "19.7.4.odt - LibreOffice Writer" , X = 0 , Y = 24 Window.Name = "19.7_Desktop" , X = 0 , Y = 24 Window.Name = "k19:start [GAMBAS-BUCH 3.5.1] - Mozilla Firefox" , X = 0 , Y = 24 Window.Name = "propertytest 0.0.15 - Gambas 3" , X = 0 , Y = 24 Window.Name = "PropertyTest" , X = 304 , Y = 213
Ausgewählte Eigenschaften und Methoden der Klasse werden in den folgenden zwei Tabellen aufgeführt und beschrieben:
Eigenschaft | Type | Beschreibung |
---|---|---|
Desktop | Integer | Gibt die Nummer (0..k) des virtuellen Desktops zurück, wo das Fenster sichtbar ist oder setzt die Nummer des Desktops, auf dem das Fenster angezeigt wird. |
Icon | Image | Gibt das Fenster-Icon zurück. |
Id | Integer | Gibt den X11-Fenster-Identifizierer zurück. |
FullScreen | Boolean | Gibt an, ob das Fenster im Vollbild-Status ist oder setzt den Vollbild-Status. |
Height | Integer | Gibt die Höhe des Fensters an (Pixel). |
Width | Integer | Gibt die Breite des Fensters an (Pixel). |
Maximized | Boolean | Gibt True zurück, wenn das Fenster maximiert ist oder maximiert das Fenster. |
Minimized | Boolean | Gibt True zurück, wenn das Fenster minimiert ist oder minimiert das Fenster. |
Name | String | Gibt den Namen des Fensters an. Das ist der Fenster-Titel der Anwendung, die dieses Fenster besitzt. |
Sticky | Boolean | Gibt True zurück, wenn das Fenster auf allen Desktops angezeigt wird oder zeigt das Fenster auf allen Desktops an. |
Visible | String | Gibt den sichtbaren Namen der Fensters zurück. Das ist der Fenster-Titel wie er vom Fenster-Manager angezeigt wird. |
X | Integer | Gibt die x-Koordinate des Fensters zurück. |
Y | Integer | Gibt die y-Koordinate des Fensters zurück. |
Tabelle 15.4.1.1: Übersicht ausgewählter Eigenschaften der Klasse DesktopWindow
Methode | Beschreibung |
---|---|
Close() | Das Fenster wird geschlossen. |
GetIcon (Width As Integer, Height As Integer ) As Image | Gibt das Fenster-Symbol mit der angegebenen Größe zurück. |
Move ( X As Integer, Y As Integer [ , Width As Integer, Height As Integer ] ) | Das Fenster wird an die Position P(x,y) verschoben und optional in der Größe (Weite) und Höhe geändert. |
Refresh() | Stellt ein DesktopWindow-Objekt durch Abfragen der Geometrie des Fenster wieder her. Das geschieht bei einem DesktopWatcher.WindowGeometry-Ereignis automatisch. |
Resize ( Width As Integer, Height As Integer ) | Das Fenster wird nur in der Größe (Höhe und Weite) geändert. |
Tabelle 15.4.2.1: Ausgewählten Methoden der Klasse DesktopWindow
Weitere Ausführungen zur Klasse DesktopWindow (gb.desktop) finden Sie im Kapitel 15, das neben der Beschreibung der Klasse DesktopWatcher vor allem das praktische Zusammenspiel der beiden Klassen in einem Projekt demonstriert.