#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#AdditionalJar: jna-5.2.0
#AdditionalJar: jna-platform-5.2.0
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Title = "xy"
MainForm.Show
GetWindow
End Sub
Sub GetWindow()
Dim wu As JavaObject
wu.InitializeStatic("com.sun.jna.platform.WindowUtils")
Dim Ls As List = wu.RunMethod("getAllWindows",Array(True)) ' or False if you want to include windows that are not visible
Dim tit As String
For Each JO As JavaObject In Ls
tit = JO.RunMethod("getTitle",Null)
If tit = "xy" Then
Dim awtrect As JavaObject = JO.RunMethod("getLocAndSize", Null)
Dim x As Double = awtrect.GetField("x")
Dim y As Double = awtrect.GetField("y")
Dim w As Double = awtrect.GetField("width")
Dim h As Double = awtrect.GetField("height")
WriteImg(x, y, w, h)
End If
Next
End Sub
Sub WriteImg(x As Int, y As Int, w As Int, h As Int)
Dim bitmap As B4XBitmap = Capturar(x, y, w, h)
Dim out As OutputStream
out = File.OpenOutput(File.DirApp, "window.png", False)
bitmap.WriteToStream(out, 100, "PNG")
out.Close
End Sub
Sub Capturar(x As Int, y As Int, largura As Int, altura As Int) As B4XBitmap
Dim c3po As AWTRobot
c3po.ScreenCurrentRectangleSetAsArbitrary(x, y, largura, altura)
Return BytesToImage(c3po.ScreenCaptureAsByteArray)
End Sub
Public Sub BytesToImage(bytes() As Byte) As B4XBitmap
Dim In As InputStream
In.InitializeFromBytesArray(bytes, 0, bytes.Length)
Dim bmp As Image
bmp.Initialize2(In)
Return bmp
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub