'need a special library... the jna... easy to get it from the internet !!!
#AdditionalJar: jna-5.2.0
#AdditionalJar: jna-platform-5.2.0
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
'you will need the timer:
Private tm As Timer
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
'you can have this in b4xpages to check every 0.5 sec:
tm.Initialize("Timer1",500)
tm.Enabled=True
End Sub
'and this sub to check what is in front:
Sub Timer1_tick
tm.Enabled=False
Dim user32 As JavaObject
user32 = user32.InitializeStatic("com.sun.jna.platform.win32.User32").GetField("INSTANCE")
Dim hwnd1 As JavaObject = user32.RunMethod("GetForegroundWindow",Null)
Dim Rect As JavaObject
Rect.InitializeNewInstance("com.sun.jna.platform.win32.WinDef.RECT",Null)
user32.runmethod("GetWindowRect",Array(hwnd1,Rect))
Dim title(512) As Char
user32.RunMethod("GetWindowText", Array(hwnd1,title,512))
Dim native As JavaObject
Dim activewindowtitle As String = native.InitializeStatic("com.sun.jna.Native").RunMethod("toString", Array(title))
activewindowtitle = activewindowtitle.Trim
'check for it:
Log(activewindowtitle)
'you can even get the height or width of form... or the position... you can play with magic..
Log(Rect.GetField("left") & " " & (Rect.GetField("right")-Rect.GetField("left")))
tm.Enabled=True
End Sub