Platforms to show: All Mac Windows Linux Cross-Platform
/MacFrameworks/Window Selection
Required plugins for this example: MBS Overlay Plugin, MBS MacFrameworks Plugin, MBS Util Plugin, MBS MacBase Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/Window Selection
This example is the version from Tue, 19th Feb 2024.
Project "Window Selection.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
SelectAWindow
End EventHandler
Sub GotAWindow(WindowNumber as integer, X as integer, Y as integer, Width as Integer, Height as Integer, TargetInfo as Dictionary)
app.FrontmostMBS = True
// title not available unless older macOS or you have permissions to know it
MsgBox "You selected: "+str(WindowNumber)+" at "+str(x)+"/"+str(y)+" "+str(Width)+" "+str(Height)+" with title: "+TargetInfo.Lookup(CGWindowMBS.kCGWindowName, "")
End Sub
Sub SelectAWindow()
t = new MyTimer
t.mode = 2
t.Period = 500
End Sub
Property t As MyTimer
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyTimer Inherits Timer
EventHandler Sub Action()
Dim x As Integer = System.Mousex
dim y as integer = screen(0).Height-System.Mousey
dim belowWindowNumber as integer = 0
if o<>Nil then
belowWindowNumber = o.WindowID
end if
dim windowNumber as integer = NSWindowMBS.windowNumberAtPoint(x,y, belowWindowNumber)
if LastWindowNumber = windowNumber then Return
LastWindowNumber = windowNumber
dim list() as Dictionary = CGWindowMBS.GetWindowListInfo(CGWindowMBS.kCGWindowListOptionIncludingWindow, windowNumber)
if UBound(list) <0 then Return
Dim w As Dictionary = list(0)
Dim bounds As Dictionary = w.Lookup(CGWindowMBS.kCGWindowBounds, Nil)
If bounds <> Nil Then
Dim wx As Integer = bounds.Lookup("X", 0)
Dim wy As Integer = bounds.Lookup("Y", 0)
Dim wh As Integer = bounds.Lookup("height", 0)
Dim ww As Integer = bounds.Lookup("width", 0)
Dim p As Picture = New Picture(ww,wh,32)
dim m as Picture = new Picture(ww,wh,32)
p.Graphics.forecolor = &cFFFFFF
p.graphics.FillRect 0, 0, p.Width, p.Height
m.Graphics.forecolor = &c777777
m.graphics.FillRect 0, 0, m.Width, m.Height
p.Graphics.forecolor = &cFF0000
p.Graphics.PenWidth = 3
p.Graphics.PenHeight = 3
p.graphics.drawrect 0, 0, p.Width, p.Height
o=new MyOverlayMBS(wx,wy,ww,wh)
o.Pict=p
o.Mask=m
o.UpdateShow
o.TargetWindowNumber = windowNumber
o.TargetInfo = list(0)
o.IgnoreMouseClicks = false
End If
End EventHandler
Property LastWindowNumber As Integer
Property o As MyOverlayMBS
End Class
Class MyOverlayMBS Inherits OverlayMBS
EventHandler Function MouseDown(x as integer, y as integer, modifiers as integer) As boolean
#Pragma unused x
#Pragma unused y
#Pragma unused modifiers
Return True
End EventHandler
EventHandler Function MouseUp(x as integer, y as integer, modifiers as integer) As boolean
#Pragma unused x
#Pragma unused y
#Pragma unused modifiers
app.t.Mode = 0
app.t = nil
me.hide
app.GotAWindow TargetWindowNumber, me.left, me.top, me.Width, me.Height, TargetInfo
Return true
End EventHandler
Property TargetInfo As Dictionary
Property TargetWindowNumber As Integer
Property timer As MyTimer
End Class
Module Module1
End Module
Sign
End Sign
End Project
The items on this page are in the following plugins: MBS MacFrameworks Plugin.