Sub SetForegroundWindow(Title As String)
Dim WU As JavaObject
WU.InitializeStatic("com.sun.jna.platform.WindowUtils")
Dim user32 As JavaObject
user32 = user32.InitializeStatic("com.sun.jna.platform.win32.User32").GetField("INSTANCE")
Dim L As List = WU.RunMethod("getAllWindows",Array(False))
For Each JO As JavaObject In L
Dim t As String = JO.RunMethod("getTitle",Null)
If t.Contains(Title) Then
Dim hwnd As Object = JO.RunMethod("getHWND", Null)
user32.RunMethod("SetForegroundWindow", Array(hwnd))
user32.RunMethod("SetFocus", Array(hwnd))
user32.RunMethod("ShowWindow", Array(hwnd, 9))'SW_RESTORE
Return
End If
Next
Log("Window not found")
End Sub
#AdditionalJar: jna-5.0.0
#AdditionalJar: jna-platform-5.0.0
Perfec!B4X:Sub SetForegroundWindow(Title As String) Dim WU As JavaObject WU.InitializeStatic("com.sun.jna.platform.WindowUtils") Dim user32 As JavaObject user32 = user32.InitializeStatic("com.sun.jna.platform.win32.User32").GetField("INSTANCE") Dim L As List = WU.RunMethod("getAllWindows",Array(False)) For Each JO As JavaObject In L Dim t As String = JO.RunMethod("getTitle",Null) If t.Contains(Title) Then Dim hwnd As Object = JO.RunMethod("getHWND", Null) user32.RunMethod("SetForegroundWindow", Array(hwnd)) user32.RunMethod("SetFocus", Array(hwnd)) user32.RunMethod("ShowWindow", Array(hwnd, 9))'SW_RESTORE Return End If Next Log("Window not found") End Sub
B4X:#AdditionalJar: jna-5.0.0 #AdditionalJar: jna-platform-5.0.0
Jars: http://repo1.maven.org/maven2/net/java/dev/jna/jna/5.0.0/jna-5.0.0.jar
http://repo1.maven.org/maven2/net/java/dev/jna/jna-platform/5.0.0/jna-platform-5.0.0.jar
Code:
Sub SetForegroundWindow(Title As String)
Dim WU As JavaObject
WU.InitializeStatic("com.sun.jna.platform.WindowUtils")
Dim user32 As JavaObject
user32 = user32.InitializeStatic("com.sun.jna.platform.win32.User32").GetField("INSTANCE")
Dim L As List = WU.RunMethod("getAllWindows",Array(False))
For Each JO As JavaObject In L
Dim t As String = JO.RunMethod("getTitle",Null)
If t.Contains(Title) Then
Dim hwnd As Object = JO.RunMethod("getHWND", Null)
user32.RunMethod("SetForegroundWindow", Array(hwnd))
user32.RunMethod("SetFocus", Array(hwnd))
user32.RunMethod("ShowWindow", Array(hwnd, 9))'SW_RESTORE
Return
End If
Next
Log("Window not found")
End Sub
OK, Thanks.If you know the context which was the last one. Focus this one.
Windows does not have a history. At least not that i know of.
I fear the answer is no.