Individuare ID e nome delle finestre attive, nonché il PID dei loro programmi con le risorse del Componente gb.desktop.x11

Da Gambas-it.org - Wikipedia.

Usando alcune risorse della Classe statica "X11" del Componente "gb.desktop.x11" è possibile ottenere di ciascuna finestra aperta:
- l'identificativo (ID);
- il desktop (numero d'indice) nel quale è aperta;
- il PID del programma alla quale essa appartiene;
- il nome della finestra.

Di seguito un possibile codice:

Public Sub Form_Open()
 
 Dim i As Integer
 Dim ob As Object
 
 For Each i In X11.GetWindowProperty(X11.RootWindow, "_NET_CLIENT_LIST")
 
' Di ciascuna finestra aperta mostra in console:
'   - l'ID (in esadecimale);
'   - il desktop (numero d'indice) nel quale è aperta;
'   - il PID del programma alla quale appartiene;
'   - il nome;
   
   If TypeOf(X11.GetWindowProperty(i, "_NET_WM_DESKTOP")) <> gb.Null Then 
     Write "&h" & Hex(i, 8) & "  " &
           Format(X11.GetWindowProperty(i, "_NET_WM_DESKTOP")[0], "-#") & "  " &
           Format(X11.GetWindowProperty(i, "_NET_WM_PID")[0], "######") & "  "
   Endif
' Potrebbero esserci finestre, come messaggi di errore dal sistema, che non posseggono nome, quindi lo verifica:
   ob = X11.GetWindowProperty(i, "_NET_WM_NAME")
   If Object.IsValid(ob) Then Write ob[0]
         
   Print

 Next

End

oppure:

Public Sub Button1_Click()

 Dim wid As Integer
 Dim ob As Object

 For Each wid In Desktop.FindWindow("*", Null, Null)  ' ...oppure anche: (Null, Null, Null)
' Ottiene il numero identificativo della finestra, presente sulla Scrivania, di ogni programma e il PID del processo del programma:
   ob = X11.GetWindowProperty(wid, "_NET_WM_NAME")
   If Object.IsValid(ob) Then
     If IsNull(X11.GetWindowProperty(wid, "_NET_WM_NAME")[0]) Then Continue 
     Print Hex(wid), X11.GetWindowProperty(wid, "_NET_WM_PID")[0], ob[0]
   Endif
 Next

End


Riferimenti